Skip to content

Commit

Permalink
Added my solutions for some old challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
martindevans committed Jun 13, 2020
1 parent 0b61a2d commit dca3122
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 25 deletions.
128 changes: 128 additions & 0 deletions YololEmulator/FlipFlops.lol
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
x=:a:o=""y=:b a=""b=""u=0d=0c=0g=0a+=x---x a+=x---x goto2+(:t=="T")
b+=y---y b+=y---y b+=y---y b+=y---y b+=y---y b+=y---y b+=y---y goto2
a+=x---x a+=x---x a+=x---x a+=x---x a+=x---x a+=x---x a+=x---x goto3
goto 6+((:t>"D")+(:t>"K")+(:t>"SR"))*4

p=c c=a---a d=b---b>0 r=p<c u=r*d+(1-r)*u:o+=u :done=a<0goto6-:done*9
goto:done++


c=a---a>0 d=b---b>0 u=(c+d==2)*(1-u)+(c+d==1)*c+(c+d==0)*u:o+=u goto10
goto:done++


c=a---a>0u=(b---b>0<1)*(c+u-c*u):o+=u:done=a<0goto14-:done*99
goto:done++


c=a---a u=c>g!=u:o+=u d=a---a u=d>c!=u:o+=u e=a---a u=e>d!=u:o+=u
f=a---a u=f>e!=u:o+=u g=a---a u=g>f!=u:o+=u goto18
goto:done++




/--------//--------//--------//--------//--------//--------//--------/
a=:a:o=""b=:b c=0u=0e=0z="x0"y="x1"j=4+((:t>"D")+(:t>"K")+(:t>"SR"))*2
e=c c=a<1<1r=e<c a="x"+a a-=z a-=y d=b<1<1b="x"+b b-=z b-=y gotoj+c

:o+=u :done=a<0 goto2-:done D(00)(01)
u=r*d+(1-r)*u :o+=u :done=a<0 goto2-:done D(10)(11)
u=(1-d)*u :o+=u :done=a<0 goto2-:done JK(00)(01)
u=(1-d)+d*(1-u) :o+=u :done=a<0 goto2-:done JK(10)(11)
u=(1-d)*u :o+=u :done=a<0 goto2-:done SR(00)(01)
u=1-d :o+=u :done=a<0 goto2-:done SR(10)(11)
:o+=u :done=a<0 goto2-:done T(00)(01)
u=r*(1-u)+(1-r)*u :o+=u :done=a<0 goto2-:done T(10)(11)




# D(00)(01) T(00)(01)
:o+=u

# JK(00)(01) SR(00)(01)
u=(1-d)*u :o+=u

# D(10)(11)
u=r*d+(1-r)*u :o+=u

# JK(10)(11)
u=(1-d)+d*(1-u) :o+=u

# SR(10)(11)
u=1-d :o+=u

# T(10)(11)
u=r*(1-u)+(1-r)*u :o+=u

/--------//--------//--------//--------//--------//--------//--------/
a=:a:o=""b=:b c=0u=0e=0z="x0"y="x1"j=4+((:t>"D")+(:t>"K")+(:t>"SR"))*2
e=c c=a<1<1r=e<c a="x"+a a-=z a-=y d=b<1<1b="x"+b b-=z b-=y gotoj+c

:o+=u :done=a<0 goto2-:done
u=r*d+(1-r)*u :o+=u :done=a<0 goto2-:done
u=(1-d)*u :o+=u :done=a<0 goto2-:done
u=(1-d)+d*(1-u) :o+=u :done=a<0 goto2-:done
u=(1-d)*u :o+=u :done=a<0 goto2-:done
u=1-d :o+=u :done=a<0 goto2-:done
:o+=u :done=a<0 goto2-:done
u=r*(1-u)+(1-r)*u :o+=u :done=a<0 goto2-:done

/--------//--------//--------//--------//--------//--------//--------/
a=:a:o=""b=:b c=0u=0e=0z="x0"y="x1"j=4+((:t>"D")+(:t>"K")+(:t>"SR"))*4
e=c c=a<1<1 a="x"+a a-=z a-=y d=b<1<1 b="x"+b b-=z b-=y gotoj+c+d*2

:o+=u :done=a<0 goto2-:done
u+=(e<c)*(d-u) :o+=u :done=a<0 goto2-:done
:o+=u :done=a<0 goto2-:done
u+=(e<c)*(d-u) :o+=u :done=a<0 goto2-:done
:o+=u :done=a<0 goto2-:done
u=1 :o+=u :done=a<0 goto2-:done
u=0 :o+=u :done=a<0 goto2-:done
u=1-u :o+=u :done=a<0 goto2-:done
:o+=u :done=a<0 goto2-:done
u=1 :o+=u :done=a<0 goto2-:done
u=0 :o+=u :done=a<0 goto2-:done
u=0 :o+=u :done=a<0 goto2-:done
u+=(e<c)*(1-u*2) :o+=u :done=a<0 goto2-:done
u+=(e<c)*(1-u*2) :o+=u :done=a<0 goto2-:done
u+=(e<c)*(1-u*2) :o+=u :done=a<0 goto2-:done
u+=(e<c)*(1-u*2) :o+=u :done=a<0 goto2-:done
/--------//--------//--------//--------//--------//--------//--------/

a=input
b=input
u=current_state
e=prev_a
z="x0"
y="x1"
c=single value from a
d=single value from b
r=indicates rising edge

# D (Rising Edge)
A B O
~R 0 SAME
~R 1 SAME
R 0 0
R 1 1

# JK
A B O
0 0 SAME
1 0 1
0 1 0
1 1 TOGGLE

# SR
A B O
0 0 SAME
1 0 1
0 1 0
1 1 0

# T (Rising Edge)
A O
~R SAME
R TOGGLE
8 changes: 7 additions & 1 deletion YololEmulator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ private static void Run(Options options)
Console.Title = $"Elapsed Game Time: {TimeSpan.FromMilliseconds(200 * lines).TotalSeconds.ToString(CultureInfo.CurrentCulture)}s";
Console.WriteLine("State:");
foreach (var (key, value) in st)
Console.WriteLine($" | {key} = {value}");
{
if (value.Value.Type == Yolol.Execution.Type.String)
Console.WriteLine($" | {key} = \"{value}\"");
else
Console.WriteLine($" | {key} = {value}");
}

Console.WriteLine();

if (options.Auto)
Expand Down
12 changes: 9 additions & 3 deletions YololEmulator/YololEmulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
</ItemGroup>

<ItemGroup>
<None Update="min10.lol">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="atan2 take2.lol">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="FlipFlops.lol">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test.lol">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -76,9 +85,6 @@
<None Update="NyefariSort.lol">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="trip.lol">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="union.lol">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
61 changes: 61 additions & 0 deletions YololEmulator/atan2 take2.lol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
u=31.416v=1800a=:a b=:b t=a/absa*(b<0)*180goto3-(absa>absb)
:c=((atan(a/b+((a*10)/b-10*a/b)/5)+t)*u)/v goto:done++
:c=(((a*b>0)*180-90-atan(b/a+((b*10)/a-10*b/a)/5)+t)*u)/v goto:done++

# ^ 108922 (0.048)

/--------//--------//--------//--------//--------//--------//--------/

# 108148
:c=atan(:a/:b)
:c+=(:a/abs:a)*(:b<0)*180
:c*=31.415
:c/=1800
goto:done++

/--------//--------//--------//--------//--------//--------//--------/

# 108667
a=:a b=:b d=(a*10)/b e=d/10 f=d-e*10 s=(f>0.005)*0.001
:c=((atan(e+s)+((:a>0)*360-180)*(:b<0))*31.415)/1800goto:done++

/--------//--------//--------//--------//--------//--------//--------/

# 108695
:c=((atan(:a/:b)+180*:a/abs:a*(:b<0))*31.415)/1800goto:done++

/--------//--------//--------//--------//--------//--------//--------/

# 108448
c=atan(:a/:b)+((:a>0)*360-180)*(:b<0)
c*=3.141 :c=c/180 goto:done++

/--------//--------//--------//--------//--------//--------//--------/

z/=:b>0 :c=atan(:a/:b) goto5
z/=:a>0 :c=atan(:a/:b)+180 goto5
:c=atan(:a/:b)-180 goto5

:c*=3.141 :c/=180 goto:done++


/--------//--------//--------//--------//--------//--------//--------/

:c=atan(:a/:b)*3.141:c/=180goto:done++

/--------//--------//--------//--------//--------//--------//--------/

p=3.141 q=p/2 x=:b y=:a
z/=x>0 :c=(p*atan(y/x))/180 :done=1goto1
z/=y>0 :c=(p*(q-atan(x/y)))/180 :done=1goto1
z/=y<0 :c=(p*(-q-atan(x/y)))/180 :done=1goto1
goto5

/--------//--------//--------//--------//--------//--------//--------/

p=3.141
x/=:b>0 :c=(atan(:a/:b)*p)/180 :done=1goto2
x/=(:b<0)*(:a>=0) :c=((atan(:a/:b)+p)*p)/180 :done=1goto2
x/=(:b<0)*(:a<0) :c=((atan(:a/:b)-p)*p)/180 :done=1goto2
x/=(:b==0)*(:a>0) :c=(p/2*p)/180 :done=1goto2
x/=(:b==0)*(:a<0) :c=-(p/2*p)/180 :done=1goto2
60 changes: 60 additions & 0 deletions YololEmulator/min10.lol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
o=:a+(:a>:b)*(:b-:a)o+=(o>:c)*(:c-o)o+=(o>:d)*(:d-o)o=:e/(:e<o)
o+=(o>:f)*(:f-o)o+=(o>:g)*(:g-o)o+=(o>:h)*(:h-o)o=:i/(:i<o)
:o=o+(o>:j)*(:j-o)goto:done++



/--------//--------//--------//--------//--------//--------//--------/

:a-=(:b<:a)*(:a-:b)
:c-=(:d<:c)*(:c-:d)
:e-=(:f<:e)*(:e-:f)
:g-=(:h<:g)*(:g-:h)
:i-=(:j<:i)*(:i-:j)

:a-=(:c<:a)*(:a-:c)
:e-=(:g<:e)*(:e-:g)
:e-=(:i<:e)*(:e-:i)

:o=:a+(:a>:e)*(:e-:a)

goto:done++

/--------//--------//--------//--------//--------//--------//--------/

:o=:a+(:a>:b)*(:b-:a)
:o+=(:o>:c)*(:c-:o)
:o+=(:o>:d)*(:d-:o)
:o+=(:o>:e)*(:e-:o)
:o+=(:o>:f)*(:f-:o)
:o+=(:o>:g)*(:g-:o)
:o+=(:o>:h)*(:h-:o)
:o+=(:o>:i)*(:i-:o)
:o+=(:o>:j)*(:j-:o)
goto:done++

:o+=(:o>:j)*(:j-:o)
c=:o>:j c*=:j-:o :o+=c

/--------//--------//--------//--------//--------//--------//--------/

:o=:a if:a<:o then:o=:a end if:b<:o then:o=:b end
if:c<:o then:o=:c end if:d<:o then:o=:d end if:e<:o then:o=:e end
if:f<:o then:o=:f end if:g<:o then:o=:g end if:h<:o then:o=:h end
if:i<:o then:o=:i end if:j<:o then:o=:j endgoto:done++

/--------//--------//--------//--------//--------//--------//--------/

:o=4001
if :a<:o then :o=:a end
if :b<:o then :o=:b end
if :c<:o then :o=:c end
if :d<:o then :o=:d end
if :e<:o then :o=:e end
if :f<:o then :o=:f end
if :g<:o then :o=:g end
if :h<:o then :o=:h end
if :i<:o then :o=:i end
if :j<:o then :o=:j end
:done=1
goto 1
21 changes: 0 additions & 21 deletions YololEmulator/trip.lol

This file was deleted.

0 comments on commit dca3122

Please sign in to comment.