Skip to content

Instantly share code, notes, and snippets.

@kaecy
Created December 19, 2013 20:15
Show Gist options
  • Select an option

  • Save kaecy/8045503 to your computer and use it in GitHub Desktop.

Select an option

Save kaecy/8045503 to your computer and use it in GitHub Desktop.
the sum of all primes or evens in the noise
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