Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,24 @@
PROGRAM LOOK
PROCEDURE LOOK_AND_SAY(N$->N$)
LOCAL I%,J%,C$,O$
I%=1
REPEAT
C$=MID$(N$,I%,1)
J%=I%+1
WHILE MID$(N$,J%,1)=C$ DO
J%+=1
END WHILE
O$+=MID$(STR$(J%-I%),2)+C$
I%=J%
UNTIL I%>LEN(N$)
N$=O$
END PROCEDURE
BEGIN
NUMBER$="1"
FOR I%=1 TO 10 DO
LOOK_AND_SAY(NUMBER$->NUMBER$)
PRINT(NUMBER$)
END FOR
END PROGRAM

View file

@ -0,0 +1,12 @@
(lib 'math) ;; for (number->list) = explode function
(lib 'list) ;; (group)
(define (next L)
(for/fold (acc null) ((g (group L)))
(append acc (list (length g) (first g)))))
(define (task n starter)
(for/fold (L (number->list starter)) ((i n))
(writeln (list->string L))
(next L)))

View file

@ -0,0 +1,11 @@
(task 10 1)
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211

View file

@ -0,0 +1,28 @@
define rle(str::string)::string => {
local(orig = #str->values->asCopy,newi=array, newc=array, compiled=string)
while(#orig->size) => {
if(not #newi->size) => {
#newi->insert(1)
#newc->insert(#orig->first)
#orig->remove(1)
else
if(#orig->first == #newc->last) => {
#newi->get(#newi->size) += 1
else
#newi->insert(1)
#newc->insert(#orig->first)
}
#orig->remove(1)
}
}
loop(#newi->size) => {
#compiled->append(#newi->get(loop_count)+#newc->get(loop_count))
}
return #compiled
}
define las(n::integer,run::integer) => {
local(str = #n->asString)
loop(#run) => { #str = rle(#str) }
return #str
}
loop(15) => {^ las(1,loop_count) + '\r' ^}

View file

@ -0,0 +1,21 @@
function lookAndSay S
put 0 into C
put char 1 of S into lastChar
repeat with i = 2 to length(S)
add 1 to C
if char i of S is lastChar then next repeat
put C & lastChar after R
put 0 into C
put char i of S into lastChar
end repeat
return R & C + 1 & lastChar
end lookAndSay
on demoLookAndSay
put 1 into x
repeat 10
put x & cr after message
put lookAndSay(x) into x
end repeat
put x after message
end demoLookAndSay

View file

@ -0,0 +1 @@
: lookAndSay(n) [ 1 ] n #[ dup .cr group map([#size, #first]) ] times ;

View file

@ -0,0 +1,19 @@
number = "1"
for nr = 1 to 10
number = lookSay(number)
see number + nl
next
func lookSay n
i = 0 j = 0 c="" o=""
i = 1
while i <= len(n)
c = substr(n,i,1)
j = i + 1
while substr(n,j,1) = c
j += 1
end
o += string(j-i) + c
i = j
end
return o

View file

@ -0,0 +1,9 @@
func lookandsay(str) {
str.gsub(/((.)\2*)/, {|a,b| a.len.to_s + b });
}
var num = "1";
{
say num;
num = lookandsay(num);
} * 10;

View file

@ -0,0 +1,15 @@
def look_and_say:
def head(c; n): if .[n:n+1] == c then head(c; n+1) else n end;
tostring
| if length == 0 then ""
else head(.[0:1]; 1) as $len
| .[0:$len] as $head
| ($len | tostring) + $head[0:1] + (.[$len:] | look_and_say)
end ;
# look and say n times
def look_and_say(n):
if n == 0 then empty
else look_and_say as $lns
| $lns, ($lns|look_and_say(n-1))
end ;