Jump to content

Boustrophedon transform: Difference between revisions

Added Easylang
(Added Easylang)
Line 244:
Sequence of factorial numbers -> A230960
1 2 5 17 73 381 2347 16701 134993 1222873 12279251 135425553 1627809401 21183890469 296773827547
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
cache[][] = [ ]
a[] = [ ]
#
func T k n .
if n = 1
return a[k]
.
if cache[k][n] = 0
cache[k][n] = T k (n - 1) + T (k - 1) (k - n + 1)
.
return cache[k][n]
.
#
proc boustrophedon . .
k = len a[]
cache[][] = [ ]
len cache[][] k
for i to k
len cache[i][] k
.
b[] &= a[1]
for n = 2 to k
b[] &= T n n
.
print b[]
.
len a[] 15
print "1 followed by 0's:"
a[1] = 1
boustrophedon
#
print "\nAll 1's:"
proc mkall1 n . a[] .
a[] = [ ]
while len a[] <> n
a[] &= 1
.
.
mkall1 15 a[]
boustrophedon
#
print "\nAlternating 1, -1"
proc mkalt n . a[] .
a[] = [ ]
h = 1
while len a[] <> n
a[] &= h
h *= -1
.
.
mkalt 15 a[]
boustrophedon
#
print "\nPrimes:"
func isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
proc mkprimes n . a[] .
a[] = [ ]
i = 2
while len a[] <> n
if isprim i = 1
a[] &= i
.
i += 1
.
.
mkprimes 15 a[]
boustrophedon
#
print "\nFibonacci numbers:"
proc mkfibon n . a[] .
a[] = [ 1 ]
val = 1
while len a[] <> n
h = prev + val
prev = val
val = h
a[] &= val
.
.
mkfibon 15 a[]
boustrophedon
print "\nFactorials:"
proc mkfact n . a[] .
a[] = [ ]
f = 1
while len a[] <> n
a[] &= f
f *= len a[]
.
.
mkfact 15 a[]
boustrophedon
 
</syntaxhighlight>
{{out}}
<pre>
1 followed by 0's:
[ 1 1 1 2 5 16 61 272 1385 7936 50521 353792 2702765 22368256 199360981 ]
 
All 1's:
[ 1 2 4 9 24 77 294 1309 6664 38177 243034 1701909 13001604 107601977 959021574 ]
 
Alternating 1, -1
[ 1 0 0 1 0 5 10 61 280 1665 10470 73621 561660 4650425 41441530 ]
 
Primes:
[ 2 5 13 35 103 345 1325 5911 30067 172237 1096319 7677155 58648421 485377457 4326008691 ]
 
Fibonacci numbers:
[ 1 2 5 14 42 144 563 2526 12877 73778 469616 3288428 25121097 207902202 1852961189 ]
 
Factorials:
[ 1 2 5 17 73 381 2347 16701 134993 1222873 12279251 135425553 1627809401 21183890469 296773827547 ]
</pre>
 
Line 288 ⟶ 414:
13250869953362054385 ... 82450325540640498987 (2371 digits)
</pre>
 
=={{header|J}}==
Implementation:<syntaxhighlight lang=J>b=: {{
2,063

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.