programgames/guess/guess.xtl

source · imports g: games/guess/NumberGuess.xtl

t : Int

value · line 6
t ← ᵍn̲ew ᵍtop

ᵘp̲lay : Num a => Int -> Int -> a

function · line 13

The halving player on this secret: guess the middle of what is still possible, narrow, repeat. Each guess is printed with its answer, and the result is how many guesses it took.

ᵘp̲lay ← { t b →
  k ← f̲irst r̲avel ᵍg̲uess b
  r ← t ᵍm̲ove k
  shown ← p̲rint! @ f̲ormat< "{k}  {g:r_eply r}"
  r = 0 ? 1◆ 1 + t ᵘp̲lay b ᵍn̲arrow r
}
f̲ormat< expands to
((f̲ormat (k)) c̲at "  " c̲at (f̲ormat (ᵍr̲eply r)))

start : Int

value · line 19
start ← 2 1 r̲eshape 1 c̲at ᵍtop

s : Int

value · line 29
s ← r̲ange ᵍtop

ᵘr̲ound : Int -> Int

function · line 30
ᵘr̲ound ← { st →
  b ← 2 t̲ake st
  r ← s ᵍm̲ove ᵍg̲uess b
  (b ᵍn̲arrow r) c̲at (3 s̲elect st) + r ≠ 0
}
Used in: st

st0 : Int

value · line 35
st0 ← (3 c̲at ᵍtop) r̲eshape (ᵍtop r̲eshape 1) c̲at (ᵍtop r̲eshape ᵍtop) c̲at ᵍtop r̲eshape 0
Used in: st

st : Int

value · line 36
st ← 7 'ᵘr̲ound p̲ower st0

n : Int

value · line 38
n ← 1 + 3 s̲elect st                  ⍝ the guesses each secret needed

ok : Unit

value · line 46
ok ← "7 >= 'm_ax r_/ n" a̲ssert< "every secret found in at most 7 guesses (2^7 > 100)"
a̲ssert< expands to
({ @ → (7 ≥ 'm̲ax r̲/ n) ? @◆ ⎕E̲RR "assertion failed: 7 >= 'm_ax r_/ n (every secret found in at most 7 guesses (2^7 > 100)) [games/guess/guess.xtl:46]"◆ @ } @)

ok : Unit

value · line 47
ok ← "g:top = '+ r_/ s = g:g_uess 2 t_ake st" a̲ssert< "all games won after 7 rounds"
a̲ssert< expands to
({ @ → (ᵍtop = '+ r̲/ s = ᵍg̲uess 2 t̲ake st) ? @◆ ⎕E̲RR "assertion failed: g:top = '+ r_/ s = g:g_uess 2 t_ake st (all games won after 7 rounds) [games/guess/guess.xtl:47]"◆ @ } @)