Programs to report scores during tennis games. The specifications used were those involved here. (No code was written to facilitate data entry. Hardcoded values of first three names would be replaced by some such code.)
Example given in specification:
tellGameScoreSeries 'AABBBAABAABBBB' love all Alice fifteen, Bob love Alice thirty, Bob love Alice thirty, Bob fifteen thirty all Alice thirty, Bob forty forty all advantage Alice deuce advantage Alice game Alice
Code:
firstPlayerName=: 'Alice'"_
secondPlayerName=: 'Bob'"_
ScoreMarks=: 'AB'
tellGameScoreSeries=: 3 :'tellSituation/&> ({.~ validLength) pair ScoreMarks, y'
pair =: [: tally&.> situate
tally =: 1 1 -~ [:+/"1 =
situate=: [: }. <\
tellSituation =: tellIncomplete ` tellFinal @. isFinal
tellIncomplete=: tellLow ` tellHigh @. isHigh
tellLow =: tellBoth ` tellTie @. isTied
tellHigh =: tellAdvantage ` tellDeuce @. isTied
isFinal=: isHigh *. 1 < [: | -
isHigh=: 3 < >.
isTied=: =
tellFinal=: 'game ', leadingPlayerName
tellAdvantage=: 'advantage ', leadingPlayerName
tellDeuce=: 'deuce'"_
tellBoth=: firstPlayerName, ' ', tellNumber@[ , ', ', secondPlayerName, ' ', tellNumber@]
tellTie=: tellNumber,' all'"_
tellNumber=: [: > ] { (;:' love fifteen thirty forty ')"_
leadingPlayerName=: firstPlayerName ` secondPlayerName @. <
validLength=: ( {.@: ((1+I.),#) )@: (isFinal/&>)