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,5 @@
(define (fib n)
(let _fib ((a 1) (b 1) (n n))
(if
(<= n 1) a
(_fib b (+ a b) (1- n)))))

View file

@ -0,0 +1,42 @@
' FB 1.05.0 Win64
#Lang "fblite"
Option Gosub '' enables Gosub to be used
' Using gosub to simulate a nested function
Function fib(n As UInteger) As UInteger
Gosub nestedFib
Exit Function
nestedFib:
fib = IIf(n < 2, n, fib(n - 1) + fib(n - 2))
Return
End Function
' This function simulates (rather messily) gosub by using 2 gotos and would therefore work
' even in the default dialect
Function fib2(n As UInteger) As UInteger
Goto nestedFib
exitFib:
Exit Function
nestedFib:
fib2 = IIf(n < 2, n, fib2(n - 1) + fib2(n - 2))
Goto exitFib
End Function
For i As Integer = 1 To 12
Print fib(i); " ";
Next
Print
For j As Integer = 1 To 12
Print fib2(j); " ";
Next
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,12 @@
on fib (n)
if n<0 then return _player.alert("negative arguments not allowed")
-- create instance of unnamed class in memory only (does not pollute namespace)
m = new(#script)
r = RETURN
m.scriptText = "on fib (me,n)"&r&"if n<2 then return n"&r&"return me.fib(n-1)+me.fib(n-2)"&r&"end"
aux = m.script.new()
m.erase()
return aux.fib(n)
end

View file

@ -0,0 +1,2 @@
put fib(10)
-- 55

View file

@ -0,0 +1,12 @@
# Using scoped function fibI inside fib
proc fib(x): int =
proc fibI(n): int =
if n < 2: n else: fibI(n-2) + fibI(n-1)
if x < 0:
raise newException(ValueError, "Invalid argument")
return fibI(x)
for i in 0..4:
echo fib(i)
# fibI(10) # undeclared identifier 'fibI'

View file

@ -0,0 +1,7 @@
{ |i|
func (n) {
if (n < 0) { return };
n < 2 ? n
: (__FUNC__(n-2) + __FUNC__(n-1));
}(i).to_s.say;
} * 10;

View file

@ -0,0 +1,7 @@
{ |i|
{ |n|
if (n < 0) { return };
n < 2 ? n
: (__BLOCK__(n-2) + __BLOCK__(n-1));
}(i).to_s.say;
} * 10;

View file

@ -0,0 +1,5 @@
function(n, f) {
return f(n, f);
}(10, function(n, f) {
return n < 2 ? 1 : f(n - 1, f) + f(n - 2, f);
})

View file

@ -0,0 +1,2 @@
spn:1> function(n, f) { return f(n, f); }(10, function(n, f) { return n < 2 ? 1 : f(n - 1, f) + f(n - 2, f); })
= 89

View file

@ -0,0 +1,9 @@
let fib: Int -> Int = {
func f(n: Int) -> Int {
assert(n >= 0, "fib: no negative numbers")
return n < 2 ? 1 : f(n-1) + f(n-2)
}
return f
}()
print(fib(8))

View file

@ -0,0 +1,10 @@
let fib: Int -> Int = {
var f: (Int -> Int)!
f = { n in
assert(n >= 0, "fib: no negative numbers")
return n < 2 ? 1 : f(n-1) + f(n-2)
}
return f
}()
println(fib(8))

View file

@ -0,0 +1,15 @@
struct RecursiveFunc<F> {
let o : RecursiveFunc<F> -> F
}
func y<A, B>(f: (A -> B) -> A -> B) -> A -> B {
let r = RecursiveFunc<A -> B> { w in f { w.o(w)($0) } }
return r.o(r)
}
func fib(n: Int) -> Int {
assert(n >= 0, "fib: no negative numbers")
return y {f in {n in n < 2 ? 1 : f(n-1) + f(n-2)}} (n)
}
println(fib(8))

View file

@ -0,0 +1,7 @@
def (fib n)
if (n >= 0)
(transform n :thru (afn (n)
(if (n < 2)
n
(+ (self n-1)
(self n-2)))))

View file

@ -0,0 +1,12 @@
class Fibonacci {
static compute(n) {
var fib
fib = Fn.new {|n|
if (n < 2) return n
return fib.call(n - 1) + fib.call(n - 2)
}
if (n < 0) return null
return fib.call(n)
}
}

View file

@ -0,0 +1 @@
0 | recurse(. + 1)

View file

@ -0,0 +1,8 @@
def fib(n):
def aux: if . == 0 then 0
elif . == 1 then 1
else (. - 1 | aux) + (. - 2 | aux)
end;
if n < 0 then error("negative arguments not allowed")
else n | aux
end ;