Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,12 @@
Number extend [
my_factorial [
(self < 2)
ifTrue: [ ^1 ]
ifFalse: [
^ (2 to: self) fold: [ :a :b | a * b ]
]
]
].
7 factorial printNl.
7 my_factorial printNl.

View file

@ -0,0 +1,7 @@
Number extend [
factorial [
self < 0 ifTrue: [ self error: 'factorial is defined for natural numbers' ].
self isZero ifTrue: [ ^1 ].
^self * ((self - 1) factorial)
]
].

View file

@ -0,0 +1,10 @@
|fac|
fac := [:n |
n < 0 ifTrue: [ self error: 'fac is defined for natural numbers' ].
n <= 1
ifTrue: [ 1 ]
ifFalse: [ n * (fac value:(n - 1)) ]
].
fac value:1000.

View file

@ -0,0 +1,4 @@
| fac |
fac := [ :n | (1 to: n) inject: 1 into: [ :prod :next | prod * next ] ].
fac value: 10.
"3628800"

View file

@ -0,0 +1,3 @@
fac := [:n | (1 to: n) product].
fac value:40
-> 815915283247897734345611269596115894272000000000