Skip to content

Instantly share code, notes, and snippets.

@zaius
Created October 8, 2010 22:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaius/617672 to your computer and use it in GitHub Desktop.
Save zaius/617672 to your computer and use it in GitHub Desktop.
s = 'FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth'
longest = ''
(0...s.length).each do |i|
(0..i).each do |j|
part = s[j..i]
longest = part if part == part.reverse && part.length > longest.length
end
end
longest
=> "ranynar"
def is_prime? number
(2..number/2).each do |i|
return false if number % i == 0
end
true
end
def fib index
return 0 if index == 0
return 1 if index == 1
fib(index - 1) + fib(index - 2)
end
highest_prime = 1
index = 0
while highest_prime < 227000
index += 1
result = fib index
highest_prime = result if is_prime?(result)
end
calc = highest_prime + 1
factors = []
while !is_prime? calc
(2..calc/2).each do |i|
if calc % i == 0
factors << i if !factors.include? i
calc = calc / i
end
end
end
factors.sum
=> 352
numbers = 3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99
set_count = 0
numbers.each_with_index do |number, i|
numbers.combination(i).each do |combination|
set_count += 1 and puts combination.inspect if combination[0..-2].sum == combination[-1]
end
end
set_count
=> 179
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment