Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def almost_increasing_sequence(sequence)
- array_of_arrays = sequence.chunk_while {|i, j| i < j}.to_a
- if array_of_arrays.length == 1
- puts true
- elsif array_of_arrays.length > 2
- puts false
- else
- if (array_of_arrays[0].last <=> array_of_arrays[1].first) == 1
- if (array_of_arrays[0][-2] <=> array_of_arrays[1][0]) == -1
- puts true
- elsif (array_of_arrays[0].last <=> array_of_arrays[1][1]) == -1
- puts true
- elsif (array_of_arrays[0][-2]) == nil
- puts true
- else
- puts false
- end
- else
- puts true
- end
- end
- end
- almost_increasing_sequence([1, 2, 3, 4, 99, 5, 6]) #true
- almost_increasing_sequence([1, 3, 2]) #true
- almost_increasing_sequence([10, 1, 2, 3, 4, 5]) #true
- almost_increasing_sequence([0, -2, 5, 6]) #true
- almost_increasing_sequence([1, 2, 3, 4, 3, 6]) #true
- almost_increasing_sequence([1, 1]) #true
- almost_increasing_sequence([100, 200, 300, 400, 99, 500, 600]) #true
- almost_increasing_sequence([1, 2, 1, 2]) #false
- almost_increasing_sequence([1, 2, 3, 4, 5, 3, 5, 6]) #false
- almost_increasing_sequence([40, 50, 60, 10, 20, 30]) #false
- almost_increasing_sequence([1, 3, 2, 1]) #false
- almost_increasing_sequence([1, 4, 10, 4, 2] ) #false
- almost_increasing_sequence( [1, 1, 1, 2, 3]) #false
- almost_increasing_sequence([10, 1, 2, 3, 4, 5, 6]) #true
- almost_increasing_sequence([5, 7, 8, 90, 91, 92, 93]) #true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement