21 lines
631 B
Fennel
21 lines
631 B
Fennel
(do ;;; Solve the McNuggets problem find the largest n <= 100 for which there
|
|
;;; are no non-negative integers x, y, z such that 6x + 9y + 20z = n
|
|
|
|
(local maxNuggets 100)
|
|
(var sum {})
|
|
(for [i 0 maxNuggets] (tset sum i false))
|
|
(for [x 0 maxNuggets 6]
|
|
(for [y x maxNuggets 9]
|
|
(for [z y maxNuggets 20]
|
|
(tset sum z true)
|
|
)
|
|
)
|
|
)
|
|
; show the highest number that cannot be formed
|
|
(var largest maxNuggets)
|
|
(while (. sum largest)
|
|
(set largest (- largest 1))
|
|
)
|
|
(print (.. "The largest non McNugget number is " largest))
|
|
|
|
)
|