Login
7 branches 0 tags
Ben (Win10) Moved testsuite to /testsuite and improved its handling in the wasm build 71fb293 3 years ago 559 Commits
nujel / tests / slow / day17.nuj
#!/usr/bin/env nujel

[def counter 0]

[defn in-area? [x y]
       [and [>= x 144]
	    [<= x 178]
	    [>= y -100]
	    [<= y -76]]]

[defn over? [x y]
       [or [> x 178]
	   [< y -100]]]

[defn zdir [a]
       [cond [[zero? a] 0]
             [[> a 0] -1]
	     [#t 1]]]

[defn shoot [x y vx vy max-y]
       ;[println [cat x " " y " " vx " " vy]]
       [cond [[in-area? x y] [++ counter] max-y]
	     [[over? x y] 0]
	     [#t [shoot [+ x vx] [+ y vy] [+ vx [zdir vx]] [+ vy -1] [max y max-y]]]]]

[defn find-max []
       [def ret 0]
       [for [vx 0 300]
       [for [vy -300 300]
	    [def res [shoot 0 0 vx vy 0]]
	    [set! ret [max ret res]]
       ]] ret]

[def res-p1 [find-max]]
[when [!= res-p1 4950]
      [throw [list :wrong-result "Wrong result" res-p1]]]
[def res-p2 counter]
[when [!= res-p2 1477]
      [throw [list :wrong-result "Wrong result" res-p2]]]