Created
December 19, 2013 20:15
-
-
Save kaecy/8045503 to your computer and use it in GitHub Desktop.
the sum of all primes or evens in the noise
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
| ans = 0; | |
| tokens = "2GSD#13x8xU343%^DGF1@22@".scan /\d+/ | |
| def prime? op | |
| divs = 0; | |
| (1..op).each do |op2| | |
| case op % op2 | |
| when 0 | |
| divs += 1; | |
| end | |
| end | |
| if divs == 2 | |
| true; | |
| end | |
| end | |
| tokens.each do |t| | |
| t = t.to_i; | |
| if t != 0 # zeros not allowed | |
| # it's a 1s and everyone above party! | |
| if prime?(t) || t % 2 == 0 # prime or even | |
| ans += t; | |
| end | |
| end | |
| end | |
| puts ans; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment