Skip to content

Instantly share code, notes, and snippets.

@shurizzle
Created May 6, 2011 01:54
Show Gist options
  • Save shurizzle/958326 to your computer and use it in GitHub Desktop.
Save shurizzle/958326 to your computer and use it in GitHub Desktop.
Greplin solution
require 'prime'
require 'net/http'
puts "1: " + Net::HTTP.get(URI.parse('http://challenge.greplin.com/static/gettysburg.txt')).tap {|str|
break (0...str.size).flat_map {|i|
(i..str.size).inject([]) {|r, j|
str[i..j].tap {|chunk|
break chunk == chunk.reverse ? r << chunk : r
}
}
}.max_by(&:length)
}
puts "2: " + Prime.prime_division(Enumerator.new {|x|
a, b = 1, 1
loop {
a, b = b, a + b
x << b
}
}.each {|x|
break x if x > 227_000 and x.prime?
} + 1).map(&:first).inject(:+).to_s
puts "3: " + Net::HTTP.get(URI.parse('http://challenge.greplin.com/static/numbers.csv')).strip.split(/,\s*/).map(&:to_i).tap {|set|
break (2..set.size).inject(0) {|c, n|
set.combination(n).inject(c) {|i, x|
x[0..-2].inject(:+) == x[-1] ? i + 1 : i
}
}
}.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment