Jump to content

Zeckendorf arithmetic: Difference between revisions

m
Line 1,278:
=={{header|Julia}}==
Influenced by the format of the Tcl and Perl 6 versions, but added other functionality.
<lang julia>import Base.*, Base.+, Base.-, Base./, Base.stringshow, Base.!=, Base.==, Base.<=, Base.<, Base.>, Base.>=, Base.divrem
<lang julia>
import Base.*, Base.+, Base.-, Base./, Base.string, Base.!=, Base.==, Base.<=, Base.<, Base.>, Base.>=, Base.divrem
 
const z0 = "0"
Line 1,292 ⟶ 1,291:
tolen(x::Z, n::Int) = (s = x.s; while length(s) < n s = z0 * s end; s)
 
<(x::Z, y::Z) = (l = pairlen(x, y); booflipordered =? tolen(x, l) <>= tolen(y, l); return: fliporderedtolen(x, ?l) !boo< :tolen(y, bool))
>(x::Z, y::Z) = (l = pairlen(x, y); booflipordered =? tolen(x, l) ><= tolen(y, l); return: fliporderedtolen(x, ?l) !boo> :tolen(y, bool))
==(x::Z, y::Z) = (l = pairlen(x, y); tolen(x, l) == tolen(y, l))
<=(x::Z, y::Z) = (l = pairlen(x, y); booflipordered =? tolen(x, l) <=> tolen(y, l); return: fliporderedtolen(x, ?l) !boo<= :tolen(y, bool))
>=(x::Z, y::Z) = (l = pairlen(x, y); booflipordered =? tolen(x, l) >=< tolen(y, l); return: fliporderedtolen(x, ?l) !boo>= :tolen(y, bool))
!=(x::Z, y::Z) = (l = pairlen(x, y); tolen(x, l) != tolen(y, l))
 
Line 1,415 ⟶ 1,414:
end
 
stringshow(io::IO, z::Z) = show(io, parse(BigInt, tocanonical(z).s))
 
function zeckendorftest()
4,105

edits

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