Skip to content

Commit

Permalink
Adding "Following Integer" solution
Browse files Browse the repository at this point in the history
  • Loading branch information
rxaviers committed Feb 4, 2012
1 parent fe7e5d9 commit 3171ad5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
28 changes: 28 additions & 0 deletions open_challenges/hard/following_integer.rb
@@ -0,0 +1,28 @@
#! /usr/bin/env ruby
# CodeEval - Hard) Following Integer
# http://www.codeeval.com/open_challenges/44/
# author: Rafael Xavier <rxaviers at gmail.com>

class Test
def initialize(line)
@n = line.strip.to_i
end

def run
puts @n.following_integer
end
end

class Integer
def following_integer
seq = (to_s.chars.to_a + ["0"]).permutation.to_a.sort.uniq.map{|i|
i.join('').to_i
}
seq[ seq.index(self)+1 ]
end
end

File.open(ARGV[0]).each_line do |line|
t = Test.new(line)
t.run
end
34 changes: 34 additions & 0 deletions open_challenges/hard/following_integer.testcases
@@ -0,0 +1,34 @@
115
8000
177115
206155
717272
314920
812939
6233
604888
2020
594909
447631
80
374525
883189
7007
68
88
202
2
301
41
103044
405946
785741
440
656394
643338
638561
495048
759621
786884
208
689266

0 comments on commit 3171ad5

Please sign in to comment.