Permalink
Browse files

a

  • Loading branch information...
1 parent 8aa5cf4 commit b2ba02ae8c8079e125f2b229a54e3a218ca0b627 @hamfz committed Jul 31, 2011
Showing with 41 additions and 0 deletions.
  1. +2 −0 README
  2. +38 −0 level1.rb
  3. +1 −0 level1.txt
View
2 README
@@ -0,0 +1,2 @@
+completed for level1 greplin challenge, posted for jake to make smaller
+
View
@@ -0,0 +1,38 @@
+#find substring palindrome
+def read_file(filename)
+ file = File.new(filename, "r")
+ text = file.gets
+ file.close
+ text
+end
+
+def find_palindrome(text)
+ if text.empty?
+ puts "No palindromes in chunk of text"
+ end
+ text = text.chars.to_a
+
+ (2..text.length).each do |window_size|
+ (0..text.length).each do |begin_window|
+ word = text[begin_window,window_size].join
+ if word == word.reverse
+ palindrome = word
+ end
+ end
+ end
+
+ puts "The longest Palindrome found is #{palindrome.size()}
+ characters long: #{palindrome}"
+end
+
+#argument handling
+if ARGV.size() == 2
+ if ARGV[0] == "-file" || "-f"
+ find_palindrome(read_file(ARGV[1]))
+ elsif ARGV[0] == "-string" || "-s"
+ find_palindrome(ARGV[1])
+ end
+else
+ puts 'use "-s" or "-string" for string of text'
+ puts 'use "-f" or "-file" for filename containing text'
+end
View
@@ -0,0 +1 @@
+FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth

0 comments on commit b2ba02a

Please sign in to comment.