June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
15
Task/Anonymous-recursion/AutoIt/anonymous-recursion.autoit
Normal file
15
Task/Anonymous-recursion/AutoIt/anonymous-recursion.autoit
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
ConsoleWrite(Fibonacci(10) & @CRLF) ; ## USAGE EXAMPLE
|
||||
ConsoleWrite(Fibonacci(20) & @CRLF) ; ## USAGE EXAMPLE
|
||||
ConsoleWrite(Fibonacci(30)) ; ## USAGE EXAMPLE
|
||||
|
||||
Func Fibonacci($number)
|
||||
|
||||
If $number < 0 Then Return "Invalid argument" ; No negative numbers
|
||||
|
||||
If $number < 2 Then ; If $number equals 0 or 1
|
||||
Return $number ; then return that $number
|
||||
Else ; Else $number equals 2 or more
|
||||
Return Fibonacci($number - 1) + Fibonacci($number - 2) ; FIBONACCI!
|
||||
EndIf
|
||||
|
||||
EndFunc
|
||||
|
|
@ -7,17 +7,16 @@ extension mathOp
|
|||
if (self < 0)
|
||||
[ InvalidArgumentException new:"Must be non negative"; raise ].
|
||||
|
||||
^ control do:self with
|
||||
(:n)
|
||||
^ target evalSelf(:n)
|
||||
[
|
||||
if (n > 1)
|
||||
[ ^ $closure eval(n - 2) + $closure eval(n - 1) ];
|
||||
[ ^ @self(n - 2) + @self(n - 1) ];
|
||||
[ ^ n ]
|
||||
].
|
||||
]
|
||||
}
|
||||
|
||||
program =
|
||||
public program =
|
||||
[
|
||||
-1 to:10 do(:i)
|
||||
[
|
||||
|
|
|
|||
23
Task/Anonymous-recursion/Haskell/anonymous-recursion-4.hs
Normal file
23
Task/Anonymous-recursion/Haskell/anonymous-recursion-4.hs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
fib :: Integer -> Maybe Integer
|
||||
fib n
|
||||
| n < 0 = Nothing
|
||||
| otherwise =
|
||||
Just $
|
||||
(\f ->
|
||||
let x = f x
|
||||
in x)
|
||||
(\f n ->
|
||||
if n > 1
|
||||
then f (n - 1) + f (n - 2)
|
||||
else 1)
|
||||
n
|
||||
|
||||
-- TEST ----------------------------------------------------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
print $
|
||||
fib <$> [-4 .. 10] >>=
|
||||
\m ->
|
||||
case m of
|
||||
Just x -> [x]
|
||||
_ -> []
|
||||
1
Task/Anonymous-recursion/Klong/anonymous-recursion.klong
Normal file
1
Task/Anonymous-recursion/Klong/anonymous-recursion.klong
Normal file
|
|
@ -0,0 +1 @@
|
|||
fib::{:[x<0;"error: negative":|x<2;x;.f(x-1)+.f(x-2)]}
|
||||
40
Task/Anonymous-recursion/Ring/anonymous-recursion.ring
Normal file
40
Task/Anonymous-recursion/Ring/anonymous-recursion.ring
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Project : Anonymous recursion
|
||||
# Date : 2018/01/03
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
t=0
|
||||
for x = -2 to 12
|
||||
n = x
|
||||
recursion()
|
||||
if x > -1
|
||||
see t + nl
|
||||
ok
|
||||
next
|
||||
|
||||
func recursion()
|
||||
nold1=1
|
||||
nold2=0
|
||||
if n < 0
|
||||
see "positive argument required!" + nl
|
||||
return
|
||||
ok
|
||||
if n=0
|
||||
t=nold2
|
||||
return t
|
||||
ok
|
||||
if n=1
|
||||
t=nold1
|
||||
return t
|
||||
ok
|
||||
while n
|
||||
t=nold2+nold1
|
||||
if n>2
|
||||
n=n-1
|
||||
nold2=nold1
|
||||
nold1=t
|
||||
loop
|
||||
ok
|
||||
return t
|
||||
end
|
||||
return t
|
||||
14
Task/Anonymous-recursion/VBA/anonymous-recursion.vba
Normal file
14
Task/Anonymous-recursion/VBA/anonymous-recursion.vba
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
Sub Main()
|
||||
Debug.Print F(-10)
|
||||
Debug.Print F(10)
|
||||
End Sub
|
||||
|
||||
Private Function F(N As Long) As Variant
|
||||
If N < 0 Then
|
||||
F = "Error. Negative argument"
|
||||
ElseIf N <= 1 Then
|
||||
F = N
|
||||
Else
|
||||
F = F(N - 1) + F(N - 2)
|
||||
End If
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue