Saturday, August 10, 2013

First use of Swap Rule - "Whenever"

In the hackathon, I used the Whenever programming language trivially when I had an analytic solution just to perform a multiplication. But I decided to now go back and use it for real. The Whenever Programming Language (http://www.dangermouse.net/esoteric/whenever.html) executes lines of code in your program in whatever order it pleases - and it notably has no variables for state, the only state is the "wish-list" of lines of code to be executed randomly. My solution notably took 13 minutes for me to run, which is above the Project Euler limit...but I think I will let this slide, seeing as the runtime of a Whenver program is very nondeterministic: if I got lucky, I am pretty sure my program could run in a few milliseconds.

1 defer (9 || N(6) < 4000000) -2#N(2),-3#N(3),-4#N(4),-5#N(5),-6#N(6),-7#N(7),-8#N(8);
2 defer (7 || N(6) > 4000000 || N(8)>2 || N(3)>N(2)) 3#N(2),2,8;
3 defer (7 || N(6) > 4000000 || N(8)>2 || N(2)>N(3)) 2#N(3),3,8;
4 defer (9 || N(8)<3 || N(3)>N(2)) 6#N(3),-8#3,4,9;
5 defer (9 || N(8)<3 || N(2)>N(3)) 6#N(2),-8#3,5,9;
6 defer (1 > 0) 6;
7 2,8;
8 defer (1 > 0) 8;
9 print(N(6) - 1);

No comments:

Post a Comment