Skip to content

Instantly share code, notes, and snippets.

@jli-hashrocket
Created October 27, 2013 18:56
Show Gist options
  • Select an option

  • Save jli-hashrocket/7186464 to your computer and use it in GitHub Desktop.

Select an option

Save jli-hashrocket/7186464 to your computer and use it in GitHub Desktop.
Number Shuffle problem in Ruby Monk Problem Statement Given a 3 or 4 digit number with distinct digits, return a sorted array of all the unique numbers than can be formed with those digits.
def factorial(number)
if number <= 1
1
else
number * factorial(number - 1)
end
end
def number_shuffle(number)
new_array = []
number = number.to_s
num_array = number.split("")
factorial_num = factorial(num_array.length)
while new_array.length < factorial_num
shuffle_array = num_array.shuffle
num_array = num_array.join("")
new_array.push num_array
puts new_array.uniq
end
end
number_shuffle(123)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment