Created
April 20, 2016 07:57
-
-
Save ssvb/29b23a52912d5b4480bc56558d29fe7f to your computer and use it in GitHub Desktop.
Coin Jam from https://www.go-hero.net/jam/16/name/RX14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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