Browse files

gattaca

  • Loading branch information...
1 parent 65171fd commit d733a5e6655979e0c7d70c8fe66f9c737ef53ece @tianyicui committed Apr 19, 2011
Showing with 47 additions and 0 deletions.
  1. +35 −0 gattaca/gattaca
  2. +12 −0 gattaca/gattaca.in
View
35 gattaca/gattaca
@@ -0,0 +1,35 @@
+#!/usr/bin/env ruby
+
+f = open(ARGV[0])
+n = f.readline.to_i
+((n+79)/80).times do
+ f.readline
+end
+
+m = f.readline.to_i
+seq = []
+m.times do
+ s = f.readline.split.map{|o| o.to_i}
+ s[0] += 1
+ s[1] += 1
+ seq << s
+end
+seq = seq.sort_by {|o| o[1]}
+seq << [n + 1, n + 1, 0]
+
+S = [0] * (n + 2)
+
+solved = 0
+
+seq.each do |s|
+ start = s[0]
+ stop = s[1]
+ score = s[2]
+ (solved...stop).each do |i|
+ S[i+1] = [S[i+1], S[i]].max
+ end
+ S[stop] = [S[stop], S[start-1] + score].max
+ solved = stop
+end
+
+puts S[n+1]
View
12 gattaca/gattaca.in
@@ -0,0 +1,12 @@
+100
+GAACTATCGCCCGTGCGCATCGCCCGTCCGACCGGCCGTAAGTCTATCTCCCGAGCGGGCGCCCGATCTCAAGTGCACCT
+CACGGCCTCACGACCGTGAG
+8
+43 70 27
+3 18 24
+65 99 45
+20 39 26
+45 74 26
+10 28 20
+78 97 23
+0 9 22

0 comments on commit d733a5e

Please sign in to comment.