RosettaCodeData/Task/ABC-problem/SNOBOL4/abc-problem.sno

69 lines
1.2 KiB
Plaintext

* Program: abc.sbl,
* To run: sbl -r abc.sbl
* Comment: Tested using the Spitbol for Linux version of SNOBOL4
* Read in blocks to construct the blocks string
in1
line = replace(input,&lcase,&ucase) :f(in1end)
line ? breakx(' ') . pre ' ' rem . post :f(in1end)
blocks = blocks "," pre post
:(in1)
in1end
* Function to determine if a word can be constructed with the given blocks
define('abc(blocks,word)s,i,let')
abcpat = (breakx(',') ',') . pre (*let len(1) | len(1) *let) rem . post
:(abc_end)
abc
eq(size(word),0) :s(abc3)
s = replace(word,&lcase,&ucase)
i = 0
abc2
i = lt(i,size(s)) i + 1 :f(abc4)
let = substr(s,i,1)
blocks ? abcpat = pre post :f(abc3)
:(abc2)
abc3
abc = 'False' :(abc5)
abc4
abc = 'True' :(abc5)
abc5
output = lpad('can_make_word("' word '"): ',26) abc
abc = ""
:(return)
abc_end
* Check words
* output = abc(blocks,"")
* output = abc(blocks," ")
output = abc(blocks,'A')
output = abc(blocks,'bark')
output = abc(blocks,'BOOK')
output = abc(blocks,'TrEAT')
output = abc(blocks,'COMMON')
output = abc(blocks,'SQUAD')
output = abc(blocks,'CONFUSE')
* The blocks are entered below, after the following END label
END
b o
X K
D Q
C P
N A
G T
R E
T G
Q D
F S
J W
H U
V I
A N
O B
E R
F S
L Y
P C
Z M