sourcegames/guess/play.xtl

1⍝!/usr/bin/env xetal 2⍝# Guess the number at the terminal, as the COR24 BASIC game plays: 3⍝# type a number from 1 to 100; you are told to go 4⍝# higher or lower until you have it. Anything that is not a number is 5⍝# asked for again. The rules are those of NumberGuess.xtl. 6ᵍ⁼u̲se< "NumberGuess" 7ᵖ⁼u̲se< "Play" 8said ← p̲rint! "--- GUESS THE NUMBER ---" 9said ← p̲rint! "I AM THINKING OF A NUMBER BETWEEN 1 AND 100." 10t ← ᵍn̲ew ᵍtop 11 12⍝# A guess: the first number typed, or it asks again. 13ᵘa̲sk ← { n → 14 g ← ᵖn̲umber "YOUR GUESS ?" 15 g ≥ 0 ? g◆ ᵘa̲sk n 16} 17⍝# Answer each guess until one is right; how many it took. 18ᵘt̲urn ← { n → 19 r ← t ᵍm̲ove ᵘa̲sk n 20 shown ← p̲rint! ᵍr̲eply r 21 r = 0 ? n◆ ᵘt̲urn n + 1 22} 23n ← ᵘt̲urn 1 24@ f̲ormat< "YOU TOOK {n} GUESSES."
f̲ormat< expands to
"YOU TOOK " c̲at (f̲ormat (n)) c̲at " GUESSES."