Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -1,4 +1,4 @@
|
|||
proc fractran prog$ val limit . r[] .
|
||||
func[] fractran prog$ val limit .
|
||||
for s$ in strsplit prog$ " " : n[][] &= number strsplit s$ "/"
|
||||
for n to limit
|
||||
r[] &= val
|
||||
|
|
@ -8,19 +8,19 @@ proc fractran prog$ val limit . r[] .
|
|||
if i > len n[][] : break 1
|
||||
val = val / n[i][2] * n[i][1]
|
||||
.
|
||||
return r[]
|
||||
.
|
||||
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[]
|
||||
print fractran p$ 2 15
|
||||
#
|
||||
proc sort . d[] .
|
||||
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[]
|
||||
r[] = fractran p$ 2 1000
|
||||
sort r[]
|
||||
i = 1
|
||||
prim = 2
|
||||
|
|
|
|||
|
|
@ -1,29 +1,70 @@
|
|||
using Base.Iterators: filter, map, take
|
||||
using Dates: now, seconds
|
||||
using .Iterators, BenchmarkTools
|
||||
using Primes: Factorization, factor
|
||||
|
||||
struct FRACTRAN
|
||||
P::Vector{Rational{BigInt}}
|
||||
i::BigInt
|
||||
# type alias for abbreviation
|
||||
Factors = Factorization{Int}
|
||||
|
||||
# iterable stuct with parametric type polymorphism
|
||||
struct Fractran{T}
|
||||
program::Vector{@NamedTuple{num::T, den::T}}
|
||||
input::Int
|
||||
|
||||
# inner constructor
|
||||
function Fractran{T}(program::Vector{Rational{Int}}, input::Int) where T
|
||||
c = Dict(BigInt => identity, Factors => factor)[T]
|
||||
new{T}([(num = c(f.num), den = c(f.den)) for f ∈ program], input)
|
||||
end
|
||||
end
|
||||
|
||||
# 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
|
||||
# methods for Fractran with n::BigInt
|
||||
Base.iterate(ft::Fractran{BigInt}, n = big(ft.input)) =
|
||||
for f ∈ ft.program
|
||||
if iszero(n % f.den)
|
||||
n = n ÷ f.den * f.num
|
||||
return n, n
|
||||
end
|
||||
end
|
||||
|
||||
"lazy generation of Fractran output sequence"
|
||||
out(ft::FRACTRAN) = map(trailing_zeros, filter(ispow2, ft))
|
||||
iters(ft::Fractran{BigInt}) = ft
|
||||
|
||||
"convenient Fractran scripting"
|
||||
macro P_str(s) eval(Meta.parse(replace("[$s]", "/" => "//"))) end
|
||||
output(ft::Fractran{BigInt}) = (trailing_zeros(n) for n ∈ ft if ispow2(n))
|
||||
|
||||
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)
|
||||
# methods for Fractran with n::Factorization{Int}
|
||||
Base.iterate(ft::Fractran{Factors}, n = factor(ft.input)) =
|
||||
for f ∈ ft.program
|
||||
if all(n[p] ≥ e for (p, e) ∈ f.den)
|
||||
for (p, e) ∈ f.den n[p] -= e end
|
||||
for (p, e) ∈ f.num n[p] += e end
|
||||
return n, n
|
||||
end
|
||||
end
|
||||
|
||||
println("2, ", join(take(primes, 20), ", "), "...")
|
||||
t = now()
|
||||
join(stdout, take(out(primes), 25), ", ")
|
||||
println("...\n25 primes in $(seconds(now() - t)) seconds")
|
||||
iters(ft::Fractran{Factors}) = (prod(n) for n ∈ ft)
|
||||
|
||||
output(ft::Fractran{Factors}) = (n[2] for n ∈ ft if
|
||||
all((iszero(e) || (p == 2)) for (p, e) ∈ n))
|
||||
|
||||
# convenient Fractran scripting
|
||||
macro ft_str(s::String)
|
||||
eval(Meta.parse(replace("[$s]", "/" => "//")))
|
||||
end
|
||||
|
||||
# instantiation of Fractran example generating prime numbers
|
||||
primes(T) = Fractran{T}(ft"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)
|
||||
|
||||
# Output including Benchmark
|
||||
ilim = 20; plim = 45
|
||||
|
||||
function printout(T)
|
||||
println("\n$ilim iterations and output of $plim prime numbers using ", T)
|
||||
println(join(take(iters(primes(T)), ilim), ", "), "…")
|
||||
join(stdout, take(output(primes(T)), plim), ", ")
|
||||
print("…\nBenchmark: $plim primes in")
|
||||
end
|
||||
|
||||
printout(BigInt)
|
||||
@btime collect(take(output(primes(BigInt)), plim))
|
||||
|
||||
printout(Factors)
|
||||
@btime collect(take(output(primes(Factors)), plim));
|
||||
|
|
|
|||
77
Task/Fractran/Odin/fractran.odin
Normal file
77
Task/Fractran/Odin/fractran.odin
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:strconv"
|
||||
import "core:strings"
|
||||
import "core:text/match"
|
||||
import "core:math"
|
||||
|
||||
|
||||
main :: proc() {
|
||||
// fmt.println(os.args)
|
||||
|
||||
n:int
|
||||
number:int
|
||||
number_conv:bool
|
||||
fracts:[dynamic]int
|
||||
defer delete(fracts)
|
||||
|
||||
n,number_conv = strconv.parse_int(os.args[1])
|
||||
assert(number_conv, "Number must be given in first place!")
|
||||
assert(len(os.args)>1,"no command line arguments given")
|
||||
|
||||
data:="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"
|
||||
|
||||
ss := strings.split(string(data), " ")
|
||||
defer delete(ss)
|
||||
|
||||
|
||||
a: [dynamic]string
|
||||
dummy:[]string
|
||||
defer delete(a)
|
||||
defer delete(dummy)
|
||||
|
||||
for i in ss{
|
||||
dummy =strings.split(i,"/")
|
||||
for j in dummy{
|
||||
// fmt.println(j)
|
||||
|
||||
append_elem(&a,j)
|
||||
}
|
||||
}
|
||||
|
||||
for k in a{
|
||||
// fmt.println(k)
|
||||
number,number_conv = strconv.parse_int(k)
|
||||
assert(number_conv, "Number must be given in program")
|
||||
append_elem(&fracts,number)
|
||||
}
|
||||
|
||||
|
||||
// fmt.println(len(fracts))
|
||||
cond:int
|
||||
buf: [256]byte
|
||||
bb:int
|
||||
end:=0
|
||||
fmt.println(n)
|
||||
frac: for j:=0;j<len(fracts);{
|
||||
cond = (n*fracts[j])%fracts[j+1]
|
||||
|
||||
if (cond==0){
|
||||
|
||||
n= (n*fracts[j])/fracts[j+1]
|
||||
fmt.println(n)
|
||||
j=0
|
||||
end+=1
|
||||
if end==19{
|
||||
break frac
|
||||
}
|
||||
}
|
||||
else{
|
||||
j=j+2
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
include Settings
|
||||
|
||||
say version; say 'Fractan'; say
|
||||
say 'FRACTRAN - 3 Mar 2025'
|
||||
say version
|
||||
say
|
||||
parse arg n','t
|
||||
if n = '' then
|
||||
n = 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue