brewersfan1976

nth_number.rb

Mar 26th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.67 KB | None | 0 0
  1. def nthNumber(s, n)
  2.     x = 0
  3.     number = 0
  4.     string = ""
  5.    
  6.     while (x < s.length)
  7.           if s[x] >= '1' and s[x] <= '9' then
  8.              number = number + 1
  9.              
  10.              while (true and x < s.length)
  11.                    if s[x] >= '0' and s[x] <= '9' then
  12.                       string = string + s[x]
  13.                    else
  14.                       break
  15.                    end
  16.                      
  17.                    x = x + 1
  18.              end
  19.           end
  20.              
  21.           if number == n then
  22.              return string
  23.           else
  24.              string = ""
  25.           end
  26.              
  27.           x = x + 1
  28.     end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment