Advertisement
brewersfan1976

palindrome_rearranging.rb

Mar 9th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.61 KB | None | 0 0
  1. def palindromeRearranging(inputString)
  2.     array = Array.new
  3.     x = 0
  4.    
  5.     while (x < 256)
  6.           array[x] = 0
  7.           x = x + 1
  8.     end
  9.    
  10.     x = 0
  11.    
  12.     while (x < inputString.length)
  13.           number = inputString[x].ord
  14.           array[number] = array[number] + 1
  15.           x = x + 1
  16.     end
  17.    
  18.     odd = 0
  19.     x = 0
  20.    
  21.     while (x < 256)
  22.           if array[x] % 2 != 0 then
  23.              odd = odd + 1
  24.           end
  25.              
  26.           x = x + 1
  27.     end
  28.    
  29.     if odd == 0 or odd == 1 then
  30.        return true
  31.     else
  32.        return false
  33.     end
  34.    
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement