programlibs/Bits/demos/nim.xtl

Nim: heaps of counters; take any number from one heap; whoever takes the last counter wins. The winning move makes the xor of the heaps (the nim-sum) zero, worked out for every heap at once. Run with "just demo Bits nim".

source · imports b: libs/Bits/src/Bits.xtl libs/Bits/src/Bits.xtlm

heaps : Int

value · line 8
heaps ← 3 4 5

nimsum : Int

value · line 9
nimsum ← (f̲irst heaps) ᵇx̲or (f̲irst 1 d̲rop heaps) ᵇx̲or f̲irst 2 d̲rop heaps

target : Int

value · line 13
target ← heaps ᵇx̲or nimsum

after : Int

value · line 19
after ← heaps − 2 × (r̲ange 3) = 1