55 lines
1.9 KiB
Text
55 lines
1.9 KiB
Text
remove is op x xs {filter (not (x =)) xs}
|
|
|
|
append_map is transformer func op seq { \
|
|
reduce (op x xs { (func x) link xs}) (seq append []) }
|
|
|
|
permutations is op seq { \
|
|
if empty seq then [[]] else \
|
|
(append_map \
|
|
(op head {each (op tail {head hitch tail}) \
|
|
(permutations (remove head seq))}) \
|
|
seq) \
|
|
endif}
|
|
|
|
f is find
|
|
tokenize is op str{string_split ' ' str}
|
|
mk is tr pred op str {filter pred permutations tokenize str}
|
|
eq is op x xs y ys{f x xs = f y ys}
|
|
adj is op x xs y ys{1 = abs(f x xs - f y ys)}
|
|
|
|
run is { \
|
|
men := mk (op xs {0 = f 'norwegian' xs}) \
|
|
'danish english german norwegian swedish'; \
|
|
colors := mk (op xs {1 = ((f 'white' xs) - (f 'green' xs))}) \
|
|
'blue green red white yellow'; \
|
|
drinks := mk (op xs {2 = f 'milk' xs}) 'beer coffee milk tea water'; \
|
|
pets := mk (op xs {l}) 'birds cats dog horse zebra'; \
|
|
smokes := mk (op xs {l}) 'blend blue-master dunhill pall-mall prince'; \
|
|
for m with men do \
|
|
for c with colors do \
|
|
if (eq 'english' m 'red' c) and \
|
|
(adj 'norwegian' m 'blue' c) then \
|
|
for d with drinks do \
|
|
if (eq 'danish' m 'tea' d) and \
|
|
(eq 'coffee' d 'green' c) then \
|
|
for s with smokes do \
|
|
if (eq 'yellow' c 'dunhill' s) and \
|
|
(eq 'blue-master' s 'beer' d) and \
|
|
(eq 'german' m 'prince' s) then \
|
|
for p with pets do \
|
|
if (eq 'birds' p 'pall-mall' s) and \
|
|
(eq 'swedish' m 'dog' p) and \
|
|
(adj 'blend' s 'cats' p) and \
|
|
(adj 'horse' p 'dunhill' s) then \
|
|
write (0 blend (p m c d s)) \
|
|
endif \
|
|
endfor \
|
|
endif \
|
|
endfor \
|
|
endif \
|
|
endfor \
|
|
endif \
|
|
endfor \
|
|
endfor }
|
|
|
|
abs(time - (run; time))
|