Skip to content

Instantly share code, notes, and snippets.

@siddMahen
Created September 5, 2014 14:49
Show Gist options
  • Save siddMahen/cdb6100a8a431514b2cf to your computer and use it in GitHub Desktop.
Save siddMahen/cdb6100a8a431514b2cf to your computer and use it in GitHub Desktop.
importall Base
immutable ModInt{N} <: Integer
val::Int
ModInt(x) = new(mod(x,N))
end
-{N}(x::ModInt{N}) = ModInt{N}(-x.val)
+{N}(x::ModInt{N}, y::ModInt{N}) = ModInt{N}(x.val + y.val)
-{N}(x::ModInt{N}, y::ModInt{N}) = ModInt{N}(x.val - y.val)
*{N}(x::ModInt{N}, y::ModInt{N}) = ModInt{N}(x.val * y.val)
^{N}(a::ModInt{N}, k::Int) = k == 1 ? a * (a^(k - 1)) : a
hash{N}(n::ModInt{N}, h::Uint) = hash(n.val, h)
for fn in (:count_ones, :count_zeros,
:leading_zeros, :leading_ones,
:trailing_zeros, :trailing_ones)
@eval begin
($fn){N}(x::ModInt{N}) = ($fn)(x.val)
end
end
isodd{N}(a::ModInt{N}) = isodd(a.val + N)
iseven{N}(a::ModInt{N}) = iseven(a.val + N)
convert{N}(::Type{ModInt{N}}, x::Int) = ModInt{N}(x)
promote_rule{N}(::Type{ModInt{N}}, ::Type{Int}) = ModInt{N}
show{N}(io::IO, x::ModInt{N}) = print(io, "$(x.val) mod ($N)")
f(a,b,c,d) = (3*(a^6) + b^5 == c^2) && (3*(a^4) + 2*(b^3) == d^2)
S4 = Set()
S5 = Set()
g(a,b,c,d) = iseven(b^5 - 2*(b^3))
h(a,b) = (3*a^4 + 2*b^3)*(3*a^6 + b^5) == 0 || (3*a^4 + 2*b^3)*(3*a^6 + b^5) == 1
for x = 0:3, y = 0:3
a = ModInt{4}(x)
b = ModInt{4}(y)
if h(a,b)
println(a,",",b)
end
end
for x = 0:2, y = 0:2, z = 0:2, w = 0:2
a = ModInt{3}(x)
b = ModInt{3}(y)
c = ModInt{3}(z)
d = ModInt{3}(w)
if f(a,b,c,d) && g(a,b,c,d)
# push!(S4,(a,b,c,d))
#println(a,b,c,d)
end
end
for x = 0:4, y = 0:4, z = 0:4, w = 0:4
a = ModInt{5}(x)
b = ModInt{5}(y)
c = ModInt{5}(z)
d = ModInt{5}(w)
if f(a,b,c,d)
# push!(S5,(a,b,c,d))
end
end
sameparity(a::ModInt,b::ModInt) = iseven(a) == iseven(b)
#for (a,b,c,d) in S4
# F = filter(x -> sameparity(a,x[1]), S5)
# filter!(x -> sameparity(b,x[2]), F)
# filter!(x -> sameparity(c,x[3]), F)
# filter!(x -> sameparity(d,x[4]), F)
#
# println("When a = $a, b = $b, c = $c and d = $d")
# println("potential solutions mod 5 are:")
# for g in F
# println(g)
# end
# println("")
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment