Skip to content

Instantly share code, notes, and snippets.

@opparco
Created April 24, 2021 03:02
Show Gist options
  • Save opparco/442bf4894efd54aa0d2423ccb4d34518 to your computer and use it in GitHub Desktop.
Save opparco/442bf4894efd54aa0d2423ccb4d34518 to your computer and use it in GitHub Desktop.
for code in "1000".."9999"
a, b, c, d = code.bytes.map {|byte| byte - 0x30}
n = code.to_i
x = a + b + c + d
# min(x) = 1
# max(x) = 36
next if x == 1
expx = 1
while expx < n
expx = expx * x
if expx == n
puts "hit n:#{n} x:#{x}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment