Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. def almost_increasing_sequence(sequence)
  2. array_of_arrays = sequence.chunk_while {|i, j| i < j}.to_a
  3. if array_of_arrays.length == 1
  4. puts true
  5. elsif array_of_arrays.length > 2
  6. puts false
  7. else
  8. if (array_of_arrays[0].last <=> array_of_arrays[1].first) == 1
  9. if (array_of_arrays[0][-2] <=> array_of_arrays[1][0]) == -1
  10. puts true
  11. elsif (array_of_arrays[0].last <=> array_of_arrays[1][1]) == -1
  12. puts true
  13. elsif (array_of_arrays[0][-2]) == nil
  14. puts true
  15. else
  16. puts false
  17. end
  18. else
  19. puts true
  20. end
  21. end
  22. end
  23.  
  24. almost_increasing_sequence([1, 2, 3, 4, 99, 5, 6]) #true
  25. almost_increasing_sequence([1, 3, 2]) #true
  26. almost_increasing_sequence([10, 1, 2, 3, 4, 5]) #true
  27. almost_increasing_sequence([0, -2, 5, 6]) #true
  28. almost_increasing_sequence([1, 2, 3, 4, 3, 6]) #true
  29. almost_increasing_sequence([1, 1]) #true
  30. almost_increasing_sequence([100, 200, 300, 400, 99, 500, 600]) #true
  31. almost_increasing_sequence([1, 2, 1, 2]) #false
  32. almost_increasing_sequence([1, 2, 3, 4, 5, 3, 5, 6]) #false
  33. almost_increasing_sequence([40, 50, 60, 10, 20, 30]) #false
  34. almost_increasing_sequence([1, 3, 2, 1]) #false
  35. almost_increasing_sequence([1, 4, 10, 4, 2] ) #false
  36. almost_increasing_sequence( [1, 1, 1, 2, 3]) #false
  37. almost_increasing_sequence([10, 1, 2, 3, 4, 5, 6]) #true
  38. almost_increasing_sequence([5, 7, 8, 90, 91, 92, 93]) #true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement