September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,21 @@
' Mutually recursive
FUNCTION F(int n) TYPE int
RETURN IIF(n = 0, 1, n - M(F(n -1)))
END FUNCTION
FUNCTION M(int n) TYPE int
RETURN IIF(n = 0, 0, n - F(M(n - 1)))
END FUNCTION
' Get iteration limit, default 20
SPLIT ARGUMENT$ BY " " TO arg$ SIZE args
limit = IIF(args > 1, VAL(arg$[1]), 20)
FOR i = 0 TO limit
PRINT F(i) FORMAT "%2d "
NEXT
PRINT
FOR i = 0 TO limit
PRINT M(i) FORMAT "%2d "
NEXT
PRINT

View file

@ -0,0 +1,6 @@
f := method(n, if( n == 0, 1, n - m(f(n-1))))
m := method(n, if( n == 0, 0, n - f(m(n-1))))
Range
0 to(19) map(n,f(n)) println
0 to(19) map(n,m(n)) println

View file

@ -0,0 +1,6 @@
def M:
def F: if . == 0 then 1 else . - ((. - 1) | F | M) end;
if . == 0 then 0 else . - ((. - 1) | M | F) end;
def F:
if . == 0 then 1 else . - ((. - 1) | F | M) end;

View file

@ -0,0 +1,27 @@
// version 1.0.6
fun f(n: Int): Int =
when {
n == 0 -> 1
else -> n - m(f(n - 1))
}
fun m(n: Int): Int =
when {
n == 0 -> 0
else -> n - f(m(n - 1))
}
fun main(args: Array<String>) {
val n = 24
print("n :")
for (i in 0..n) print("%3d".format(i))
println()
println("-".repeat(78))
print("F :")
for (i in 0..24) print("%3d".format(f(i)))
println()
print("M :")
for (i in 0..24) print("%3d".format(m(i)))
println()
}

View file

@ -0,0 +1,14 @@
f(n)=
? n=0, <= 1
<= n-m(f(n-1))
.
m(n)=
? n=0, <= 0
<= n-f(m(n-1))
.
> i, 0..20
fs += " "+f(i)
ms += " "+m(i)
<
#.output("F:",fs)
#.output("M:",ms)

View file

@ -1,9 +1,9 @@
func F(){};
func M(){};
F = func(n) { n > 0 ? (n - M(F(n-1))) : 1 };
M = func(n) { n > 0 ? (n - F(M(n-1))) : 0 };
func F(){}
func M(){}
 
F = func(n) { n > 0 ? (n - M(F(n-1))) : 1 }
M = func(n) { n > 0 ? (n - F(M(n-1))) : 0 }
 
[F, M].each { |seq|
(0..19).map {|i| seq.call(i)}.join(' ').say;
{|i| seq.call(i)}.map(^20).join(' ').say
}

View file

@ -0,0 +1,82 @@
global main
extern printf
section .text
func_f
mov eax, [esp+4]
cmp eax, 0
jz f_ret
dec eax
push eax
call func_f
mov [esp+0], eax
call func_m
add esp, 4
mov ebx, [esp+4]
sub ebx, eax
mov eax, ebx
ret
f_ret
mov eax, 1
ret
func_m
mov eax, [esp+4]
cmp eax, 0
jz m_ret
dec eax
push eax
call func_m
mov [esp+0], eax
call func_f
add esp, 4
mov ebx, [esp+4]
sub ebx, eax
mov eax, ebx
ret
m_ret
xor eax, eax
ret
main
mov edx, func_f
call output_res
mov edx, func_m
call output_res
ret
output_res
xor ecx, ecx
loop0
push ecx
call edx
push edx
push eax
push form
call printf
add esp, 8
pop edx
pop ecx
inc ecx
cmp ecx, 20
jnz loop0
push newline
call printf
add esp, 4
ret
section .rodata
form
db '%d ',0
newline
db 10,0
end

View file

@ -0,0 +1,4 @@
fcn f(n){ if(n==0)return(1); n-m(f(n-1,m),f) }
fcn m(n){ if(n==0)return(0); n-f(m(n-1,f),m) }
[0..19].apply(f).println(); // or foreach n in ([0..19]){ print(f(n)," ") }
[0..19].apply(m).println(); // or foreach n in ([0..19]){ print(m(n)," ") }

View file

@ -1,4 +0,0 @@
def F: 0; # declare required signature
def M: if . == 0 then 0 else . - ((. - 1) | M | F) end;
def F: if . == 0 then 1 else . - ((. - 1) | F | M) end;