-
Notifications
You must be signed in to change notification settings - Fork 52
Code golf
Brent Yorgey edited this page Aug 22, 2023
·
1 revision
When a scenario is loaded with a specific script up front, and you don't type anything at the REPL, Swarm will compute the code size of your solution (measured both by counting characters and by counting AST nodes), and keep track of the shortest. Post your shortest solutions here!
- To load a specific scenario without going through the menu, use the
--scenario
(-i
) flag. - To run a specific program immediately when loading a scenario (such as a file containing custom definitions), use the
--run
flag with a file containing Swarm code. - Alternatively, to launch a scenario from the menu, use the
o
key to configure launch parameters and select the script to run. - To use a specific seed value (for set seed runs), use the
--seed
(-s
) flag.
- 188 AST nodes by
byorgey
def opposite : dir -> dir = \d.
if (d == left) {right} {left}
end
def x : int -> cmd unit -> cmd unit = \n. \c.
if (n == 0) {} {c; x (n-1) c}
end
def m5 = x 5 move end
def goTrade = m5; drill down; return () end
def fig8half : dir -> cmd unit = \d.
x 3 (turn d; goTrade); goTrade;
end
def fig8 : dir -> cmd unit = \d.
turn back;
fig8half (opposite d);
fig8half d;
turn back
end
def m2 = move; move end
def solution =
m5; x 5 (grab; m2);
x 2 (turn left; m2);
m5; turn right;
x 10 (fig8 right);
x 8 (fig8 left)
end;
solution