Skip to content

Instantly share code, notes, and snippets.

@mvw
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save mvw/0e8d5d7e579a1a89e6d4 to your computer and use it in GitHub Desktop.

Select an option

Save mvw/0e8d5d7e579a1a89e6d4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def check
min = -32
ma = 4 # 2^5 = 32 > 22
mb = 2 # 3^3 = 27 > 22
mc = 2 # 4^3 = 64 > 22
md = 1 # 5^2 = 25 > 22
me = 1 # 6^2 = 36 > 22
puts "checking"
puts "a in [#{min},..,#{ma}]"
puts "b in [#{min},..,#{mb}]"
puts "c in [#{min},..,#{mc}]"
puts "d in [#{min},..,#{md}]"
puts "e in [#{min},..,#{me}]"
nc = (ma-min+1)*(mb-min+1)*(mc-min+1)*(md-min+1)*(me-min+1)
puts "cases: #{nc}"
nt = 0
ns = 0
for a in min..ma do
pa = 2**a
xa = pa
for b in min..mb do
pb = 3**b
xb = xa + pb
for c in min..mc do
pc = 4**c
xc = xb + pc
for d in min..md do
pd = 5**d
xd = xc + pd
for e in min..me do
pe = 6**e
xe = xd + pe
x = xe
nt += 1
if x == 22
ns += 1
puts "#{ns}. (#{a},#{b},#{c},#{d},#{e}): #{pa}+#{pb}+#{pc}+#{pd}+#{pe}=#{x}"
end
end
end
end
end
end
puts "number of tests: #{nt}"
puts "number of solutions: #{ns}"
return ns
end
check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment