Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,8 @@
-- product of [a,a+1..b]
productFromTo a b =
if a>b then 1
else if a == b then a
else productFromTo a c * productFromTo (c+1) b
where c = (a+b) `div` 2
factorial = productFromTo 1

View file

@ -1,3 +1 @@
factorial :: Integral -> Integral
factorial 0 = 1
factorial n = n * factorial (n-1)
factorials = 1 : zipWith (*) factorials [1..]

View file

@ -1,5 +1,2 @@
fac n
| n >= 0 = go 1 n
| otherwise = error "Negative factorial!"
where go acc 0 = acc
go acc n = go (acc * n) (n - 1)
factorials = go 1 1 where
go n fac = f : go (n+1) (n*fac)

View file

@ -1,10 +1,3 @@
{-# LANGUAGE PostfixOperators #-}
(!) :: Integer -> Integer
(!) 0 = 1
(!) n = n * (pred n !)
main :: IO ()
main = do
print (5 !)
print ((4 !) !)
factorial :: Integral -> Integral
factorial 0 = 1
factorial n = n * factorial (n-1)

View file

@ -1,8 +1,5 @@
-- product of [a,a+1..b]
productFromTo a b =
if a>b then 1
else if a == b then a
else productFromTo a c * productFromTo (c+1) b
where c = (a+b) `div` 2
factorial = productFromTo 1
fac n
| n >= 0 = go 1 n
| otherwise = error "Negative factorial!"
where go acc 0 = acc
go acc n = go (acc * n) (n - 1)

View file

@ -0,0 +1,10 @@
{-# LANGUAGE PostfixOperators #-}
(!) :: Integer -> Integer
(!) 0 = 1
(!) n = n * (pred n !)
main :: IO ()
main = do
print (5 !)
print ((4 !) !)

View file

@ -1,2 +1,2 @@
val factorial = fn n: fold(fn{*}, 2 .. n)
val factorial = fn n: fold(2 .. n, by=fn{*})
writeln factorial(7)

View file

@ -0,0 +1,27 @@
Cls , 0 ' 0 for non split display, eg 3 means we preserve the 3 top lines from scrolling/cla
Report {
Factorial Task
Definitions
• The factorial of 0 (zero) is defined as being 1 (unity).
• The Factorial Function of a positive integer, n, is defined as the product of the sequence:
n, n-1, n-2, ... 1
}
Cls, row ' now we preserve some lines (as row number return here)
Module CheckIt {
m=bigInteger("1")
with m, "tostring" as m.toString
k=width-tab
For i=1 to 1000
if pos>tab then print
Print @(0), format$("{0::-4} :", i) ;
method m,"multiply", biginteger(i+"") as m
Report m.toString, k
' Report stop at 2/3 of display lines, and wait mouse button or spacebar
' we can flush the keyboard buffer and press space, so we get non stop display
' Report didn't stop if we use the printer's layer.
while inkey$<>"": wait 1:end while
keyboard " "
Next i
}
Checkit

View file

@ -1,2 +1,8 @@
: <factorial> dup 1 = if; dup 1- <factorial> * ;
: factorial dup 0 = [ 1+ ] [ <factorial> ] if ;
:<factorial>
dup #1 -eq? 0; drop
dup n:dec <factorial> * ;
:factorial
dup n:zero?
[ n:inc ]
[ <factorial> ] choose ;

View file

@ -1,4 +1,4 @@
!yamlscript/v0
!YS-v0
defn main(n=10):
say: "$n! -> $factorial(n)"