Skip to content

Instantly share code, notes, and snippets.

@ssvb
Created April 20, 2016 07:57
Show Gist options
  • Select an option

  • Save ssvb/29b23a52912d5b4480bc56558d29fe7f to your computer and use it in GitHub Desktop.

Select an option

Save ssvb/29b23a52912d5b4480bc56558d29fe7f to your computer and use it in GitHub Desktop.
$ cat coin_jam.cr
n = 16
j = 50
max_bound = (2**n - 1).to_u64
min_bound = (max_bound - 2**(n-1) + 2).to_u64
puts "Case #1:"
cur = min_bound
while cur <= max_bound && j > 0
str = cur.to_s(2)
divisors = (2..10).map { |base| check_prime(str.to_u64(base)) }
if divisors.any? &.nil?
cur += 2
next
end
puts str + ' ' + divisors.join(' ')
j -= 1
cur += 2
end
def check_prime(val)
divisor = 2
while divisor < 100
return divisor if val % divisor == 0
divisor += 1
end
nil
end
$ ruby coin_jam.cr
coin_jam.cr:14: syntax error, unexpected '.'
if divisors.any? &.nil?
^
coin_jam.cr:23: syntax error, unexpected keyword_end, expecting end-of-input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment