Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
38
Task/Y-combinator/VBA/y-combinator.vba
Normal file
38
Task/Y-combinator/VBA/y-combinator.vba
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
Private Function call_fn(f As String, n As Long) As Long
|
||||
call_fn = Application.Run(f, f, n)
|
||||
End Function
|
||||
|
||||
Private Function Y(f As String) As String
|
||||
Y = f
|
||||
End Function
|
||||
|
||||
Private Function fac(self As String, n As Long) As Long
|
||||
If n > 1 Then
|
||||
fac = n * call_fn(self, n - 1)
|
||||
Else
|
||||
fac = 1
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function fib(self As String, n As Long) As Long
|
||||
If n > 1 Then
|
||||
fib = call_fn(self, n - 1) + call_fn(self, n - 2)
|
||||
Else
|
||||
fib = n
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Sub test(name As String)
|
||||
Dim f As String: f = Y(name)
|
||||
Dim i As Long
|
||||
Debug.Print name
|
||||
For i = 1 To 10
|
||||
Debug.Print call_fn(f, i);
|
||||
Next i
|
||||
Debug.Print
|
||||
End Sub
|
||||
|
||||
Public Sub main()
|
||||
test "fac"
|
||||
test "fib"
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue