September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1,47 @@
report z_mutual_recursion.
class hoffstadter_sequences definition.
public section.
class-methods:
f
importing
n type int4
returning
value(result) type int4,
m
importing
n type int4
returning
value(result) type int4.
endclass.
class hoffstadter_sequences implementation.
method f.
result = cond int4(
when n eq 0
then 1
else n - m( f( n - 1 ) ) ).
endmethod.
method m.
result = cond int4(
when n eq 0
then 0
else n - f( m( n - 1 ) ) ).
endmethod.
endclass.
start-of-selection.
write: |{ reduce string(
init results = |f(0 - 19): { hoffstadter_sequences=>f( 0 ) }|
for i = 1 while i < 20
next results = |{ results }, { hoffstadter_sequences=>f( i ) }| ) }|, /.
write: |{ reduce string(
init results = |m(0 - 19): { hoffstadter_sequences=>m( 0 ) }|
for i = 1 while i < 20
next results = |{ results }, { hoffstadter_sequences=>m( i ) }| ) }|, /.

View file

@ -0,0 +1,16 @@
@% = 3 : REM Column width
PRINT "F sequence:"
FOR i% = 0 TO 20
PRINT FNf(i%) ;
NEXT
PRINT
PRINT "M sequence:"
FOR i% = 0 TO 20
PRINT FNm(i%) ;
NEXT
PRINT
END
DEF FNf(n%) IF n% = 0 THEN = 1 ELSE = n% - FNm(FNf(n% - 1))
DEF FNm(n%) IF n% = 0 THEN = 0 ELSE = n% - FNf(FNm(n% - 1))

View file

@ -0,0 +1,23 @@
100 PROGRAM "Hofstad.bas"
110 PRINT "F sequence:"
120 FOR I=0 TO 20
130 PRINT F(I);
140 NEXT
150 PRINT :PRINT "M sequence:"
160 FOR I=0 TO 20
170 PRINT M(I);
180 NEXT
190 DEF F(N)
200 IF N=0 THEN
210 LET F=1
220 ELSE
230 LET F=N-M(F(N-1))
240 END IF
250 END DEF
260 DEF M(N)
270 IF N=0 THEN
280 LET M=0
290 ELSE
300 LET M=N-F(M(N-1))
310 END IF
320 END DEF

View file

@ -1,20 +1,20 @@
import extensions.
import system'collections.
import extensions;
import system'collections;
F = (:n)((n == 0) ifTrue:[^1] ifFalse:[ ^n - (M(F(n-1))) ] ).
M = (:n)((n == 0) ifTrue:[^0] ifFalse:[ ^n - (F(M(n-1))) ] ).
F = (n => (n == 0) ? 1 : (n - M(F(n-1))) );
M = (n => (n == 0) ? 0 : (n - F(M(n-1))) );
program =
[
var ra := ArrayList new.
var rb := ArrayList new.
public program()
{
var ra := new ArrayList();
var rb := new ArrayList();
0 to:19 do(:i)
[
ra append(F eval:i).
rb append(M eval:i).
].
for(int i := 0, i <= 19, i += 1)
{
ra.append(F(i));
rb.append(M(i))
};
console printLine(ra).
console printLine(rb).
].
console.printLine(ra.asEnumerable());
console.printLine(rb.asEnumerable())
}

View file

@ -0,0 +1,8 @@
(letrec ((F (lambda (n)
(if (= n 0) 1
(- n (M (F (- n 1)))))))
(M (lambda (n)
(if (= n 0) 0
(- n (F (M (- n 1))))))))
(print (F 19)))
; produces 12

View file

@ -0,0 +1,17 @@
forward function M(integer n)
function F(integer n)
return iff(n?n-M(F(n-1)):1)
end function
function M(integer n)
return iff(n?n-F(M(n-1)):0)
end function
for i=0 to 20 do
printf(1," %d",F(i))
end for
printf(1,"\n")
for i=0 to 20 do
printf(1," %d",M(i))
end for

View file

@ -0,0 +1,26 @@
Private Function F(ByVal n As Integer) As Integer
If n = 0 Then
F = 1
Else
F = n - M(F(n - 1))
End If
End Function
Private Function M(ByVal n As Integer) As Integer
If n = 0 Then
M = 0
Else
M = n - F(M(n - 1))
End If
End Function
Public Sub MR()
Dim i As Integer
For i = 0 To 20
Debug.Print F(i);
Next i
Debug.Print
For i = 0 To 20
Debug.Print M(i);
Next i
End Sub