Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Look-and-say-sequence/Oz/look-and-say-sequence.oz
Normal file
30
Task/Look-and-say-sequence/Oz/look-and-say-sequence.oz
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
declare
|
||||
%% e.g. "21" -> "1211"
|
||||
fun {LookAndSayString S}
|
||||
for DigitGroup in {Group S} append:Add do
|
||||
{Add {Int.toString {Length DigitGroup}}}
|
||||
{Add [DigitGroup.1]}
|
||||
end
|
||||
end
|
||||
|
||||
%% lazy sequence of integers starting with N
|
||||
fun {LookAndSay N}
|
||||
fun lazy {Loop S}
|
||||
{String.toInt S}|{Loop {LookAndSayString S}}
|
||||
end
|
||||
in
|
||||
{Loop {Int.toString N}}
|
||||
end
|
||||
|
||||
%% like Haskell's "group"
|
||||
fun {Group Xs}
|
||||
case Xs of nil then nil
|
||||
[] X|Xr then
|
||||
Ys Zs
|
||||
{List.takeDropWhile Xr fun {$ W} W==X end ?Ys ?Zs}
|
||||
in
|
||||
(X|Ys) | {Group Zs}
|
||||
end
|
||||
end
|
||||
in
|
||||
{ForAll {List.take {LookAndSay 1} 10} Show}
|
||||
Loading…
Add table
Add a link
Reference in a new issue