Skip to content

Instantly share code, notes, and snippets.

@radralph
Created April 28, 2017 09:57
Show Gist options
  • Save radralph/cca667a7daa7ff06576221d0f97df733 to your computer and use it in GitHub Desktop.
Save radralph/cca667a7daa7ff06576221d0f97df733 to your computer and use it in GitHub Desktop.
*test_spec.rb
require 'test.rb'
describe "Result" do
it "should be a 5 digit number"
expect(solution.split(//).size).eql? 5
end
it "should be in included in the number given"
expect(givenNumber).include? solution
end
it "should be the largest 5 digit number within the series"
expect(numberCheck).eql? true
end
end
-----
*test.rb
def givenNumber
rand(100000..100000)
end
def solution
digits = givenNumber
digits = digits.to_s.split(//)
mSize, allResult = digits.size, []
digits.each_with_index do |x, index|
temp = []
index.to_i.upto(mSize) do |y|
temp << digits[y].to_i
if temp.size.eql? 5
allResult << temp.join("")
temp = []
break
end
end
end
allResult.max
end
def numberCheck
digits = givenNumber
digits = digits.to_s.split(//)
mSize, allResult = digits.size, []
digits.each_with_index do |x, index|
temp = []
index.to_i.upto(mSize) do |y|
temp << digits[y].to_i
if temp.size.eql? 5
allResult << temp.join("")
temp = []
break
end
end
end
#largestNumber = allResult.sort.last
largestNumber = allResult.max
allResult.each do |x|
x > largestNumber ? (return false) : (return true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment