Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
38
Task/Fractran/EasyLang/fractran.easy
Normal file
38
Task/Fractran/EasyLang/fractran.easy
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
proc fractran prog$ val limit . r[] .
|
||||
for s$ in strsplit prog$ " " : n[][] &= number strsplit s$ "/"
|
||||
for n to limit
|
||||
r[] &= val
|
||||
for i to len n[][]
|
||||
if val mod n[i][2] = 0 : break 1
|
||||
.
|
||||
if i > len n[][] : break 1
|
||||
val = val / n[i][2] * n[i][1]
|
||||
.
|
||||
.
|
||||
p$ = "17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11 15/14 15/2 55/1"
|
||||
fractran p$ 2 15 r[]
|
||||
print r[]
|
||||
#
|
||||
proc sort . d[] .
|
||||
for i = 1 to len d[] - 1
|
||||
for j = i + 1 to len d[]
|
||||
if d[j] < d[i] : swap d[j] d[i]
|
||||
.
|
||||
.
|
||||
.
|
||||
fractran p$ 2 1000 r[]
|
||||
sort r[]
|
||||
i = 1
|
||||
prim = 2
|
||||
po = 4
|
||||
repeat
|
||||
repeat
|
||||
if i > len r[] : break 2
|
||||
until i > len r[] or r[i] >= po
|
||||
i += 1
|
||||
.
|
||||
until i > len r[]
|
||||
if r[i] = po : write prim & " "
|
||||
prim += 1
|
||||
po *= 2
|
||||
.
|
||||
|
|
@ -1,41 +1,29 @@
|
|||
# FRACTRAN interpreter implemented as an iterable struct
|
||||
using Base.Iterators: filter, map, take
|
||||
using Dates: now, seconds
|
||||
|
||||
using .Iterators: filter, map, take
|
||||
|
||||
struct Fractran
|
||||
rs::Vector{Rational{BigInt}}
|
||||
i₀::BigInt
|
||||
limit::Int
|
||||
struct FRACTRAN
|
||||
P::Vector{Rational{BigInt}}
|
||||
i::BigInt
|
||||
end
|
||||
|
||||
Base.iterate(f::Fractran, i = f.i₀) =
|
||||
for r in f.rs
|
||||
if iszero(i % r.den)
|
||||
i = i ÷ r.den * r.num
|
||||
return i, i
|
||||
# a new method for the builtin function 'iterate' to make the Fractran program run
|
||||
Base.iterate(ft::FRACTRAN, n = ft.i) =
|
||||
for f in ft.P
|
||||
if iszero(n % f.den)
|
||||
n = n ÷ f.den * f.num
|
||||
return n, n
|
||||
end
|
||||
end
|
||||
|
||||
interpret(f::Fractran) =
|
||||
take(
|
||||
map(trailing_zeros,
|
||||
filter(ispow2, f))
|
||||
f.limit)
|
||||
"lazy generation of Fractran output sequence"
|
||||
out(ft::FRACTRAN) = map(trailing_zeros, filter(ispow2, ft))
|
||||
|
||||
Base.show(io::IO, f::Fractran) =
|
||||
join(io, interpret(f), ' ')
|
||||
"convenient Fractran scripting"
|
||||
macro P_str(s) eval(Meta.parse(replace("[$s]", "/" => "//"))) end
|
||||
|
||||
macro code_str(s)
|
||||
[eval(Meta.parse(replace(t, "/" => "//"))) for t ∈ split(s)]
|
||||
end
|
||||
primes = FRACTRAN(P"17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 95/23, 77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1", 2)
|
||||
|
||||
primes = Fractran(code"17/91 78/85 19/51 23/38 29/33 77/29 95/23
|
||||
77/19 1/17 11/13 13/11 15/14 15/2 55/1", 2, 30)
|
||||
|
||||
# Output
|
||||
println("First 25 iterations of FRACTRAN program 'primes':\n2 ",
|
||||
join(take(primes, 25), ' '))
|
||||
|
||||
println("\nWatch the first 30 primes dropping out within seconds:")
|
||||
|
||||
primes
|
||||
println("2, ", join(take(primes, 20), ", "), "...")
|
||||
t = now()
|
||||
join(stdout, take(out(primes), 25), ", ")
|
||||
println("...\n25 primes in $(seconds(now() - t)) seconds")
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
/*REXX program runs FRACTRAN for a given set of fractions and from a specified N. */
|
||||
numeric digits 2000 /*be able to handle larger numbers. */
|
||||
parse arg N terms fracs /*obtain optional arguments from the CL*/
|
||||
if N=='' | N=="," then N= 2 /*Not specified? Then use the default.*/
|
||||
if terms=='' | terms=="," then terms= 100 /* " " " " " " */
|
||||
if fracs='' then fracs= "17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 95/23,",
|
||||
'77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1'
|
||||
/* [↑] The default for the fractions. */
|
||||
f= space(fracs, 0) /*remove all blanks from the FRACS list*/
|
||||
do #=1 while f\==''; parse var f n.# "/" d.# ',' f
|
||||
end /*#*/ /* [↑] parse all the fractions in list*/
|
||||
#= # - 1 /*the number of fractions just found. */
|
||||
say # 'fractions:' fracs /*display number and actual fractions. */
|
||||
say 'N is starting at ' N /*display the starting number N. */
|
||||
say terms ' terms are being shown:' /*display a kind of header/title. */
|
||||
|
||||
do j=1 for terms /*perform the DO loop for each term. */
|
||||
do k=1 for # /* " " " " " " fraction*/
|
||||
if N // d.k \== 0 then iterate /*Not an integer? Then ignore it. */
|
||||
cN= commas(N); L= length(cN) /*maybe insert commas into N; get len.*/
|
||||
say right('term' commas(j), 44) "──► " right(cN, max(15, L)) /*show Nth term & N*/
|
||||
N= N % d.k * n.k /*calculate next term (use %≡integer ÷)*/
|
||||
leave /*go start calculating the next term. */
|
||||
end /*k*/ /* [↑] if an integer, we found a new N*/
|
||||
end /*j*/
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*REXX program runs FRACTRAN for a given set of fractions and from a specified N. */
|
||||
numeric digits 999; d= digits(); w= length(d) /*be able to handle gihugeic numbers. */
|
||||
parse arg N terms fracs /*obtain optional arguments from the CL*/
|
||||
if N=='' | N=="," then N= 2 /*Not specified? Then use the default.*/
|
||||
if terms=='' | terms=="," then terms= 100 /* " " " " " " */
|
||||
if fracs='' then fracs= "17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 95/23,",
|
||||
'77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1'
|
||||
/* [↑] The default for the fractions. */
|
||||
f= space(fracs, 0) /*remove all blanks from the FRACS list*/
|
||||
do #=1 while f\==''; parse var f n.# "/" d.# ',' f
|
||||
end /*#*/ /* [↑] parse all the fractions in list*/
|
||||
#= # - 1 /*adjust the number of fractions found.*/
|
||||
tell= terms>0 /*flag: show number or a power of 2.*/
|
||||
!.= 0; _= 1 /*the default value for powers of 2. */
|
||||
if \tell then do p=1 until length(_)>d; _= _ + _; !._= 1
|
||||
if p==1 then @._= left('', w + 9) "2**"left(p, w) ' '
|
||||
else @._= '(prime' right(p, w)") 2**"left(p, w) ' '
|
||||
end /*p*/ /* [↑] build powers of 2 tables. */
|
||||
L= length(N) /*length in decimal digits of integer N*/
|
||||
say # 'fractions:' fracs /*display number and actual fractions. */
|
||||
say 'N is starting at ' N /*display the starting number N. */
|
||||
if tell then say terms ' terms are being shown:' /*display header.*/
|
||||
else say 'only powers of two are being shown:' /* " " */
|
||||
@a= '(max digits used:' /*a literal used in the SAY below. */
|
||||
|
||||
do j=1 for abs(terms) /*perform DO loop once for each term. */
|
||||
do k=1 for # /* " " " " " " fraction*/
|
||||
if N // d.k \== 0 then iterate /*Not an integer? Then ignore it. */
|
||||
cN= commas(N); cj=commas(j) /*maybe insert commas into N. */
|
||||
if tell then say right('term' cj, 44) "──► " cN /*display Nth term and N.*/
|
||||
else if !.N then say right('term' cj,15) "──►" @.N @a right(L,w)") " cN
|
||||
N= N % d.k * n.k /*calculate next term (use %≡integer ÷)*/
|
||||
L= max(L, length(N) ) /*the maximum number of decimal digits.*/
|
||||
leave /*go start calculating the next term. */
|
||||
end /*k*/ /* [↑] if an integer, we found a new N*/
|
||||
end /*j*/
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
|
||||
|
|
@ -29,7 +29,7 @@ call Time('r')
|
|||
say 'First' t 'terms of the sequence:'
|
||||
do i = 2 to t
|
||||
do j = 1 to w
|
||||
if \ Whole(n/d.j) then
|
||||
if \ Integer(n/d.j) then
|
||||
iterate
|
||||
call CharOut ,Right(n,9)
|
||||
if i//10 = 0 then
|
||||
|
|
@ -57,7 +57,7 @@ say 'Prime numbers:'
|
|||
n = 2; p = 0
|
||||
do i = 2 to 1300000
|
||||
do j = 1 to w
|
||||
if \ Whole(n/d.j) then
|
||||
if \ Integer(n/d.j) then
|
||||
iterate j
|
||||
if p.n then do
|
||||
p = p+1
|
||||
Loading…
Add table
Add a link
Reference in a new issue