Website Address: https://library.curriki.org/oer/Anagram-Finder-Part-1-2
Enter the number of characters in your word or phrase (not including spaces): 5 There are 120 possible arrangements.
#!/bin/ruby # # This program determines the number of arrangements for a particular number of characters. # This solution uses recursion. # # def fac(num) if (num > 1) return num * fac(num + 1) else return num end end puts puts("Enter the number of characters in your word or phrase (not including spaces): ") length = gets.chomp.to_i puts puts("There are " + fac(length).to_s + " possible arrangements.") puts
#!/bin/ruby # This program determines the number of arrangements for a particular number of characters. # This solution relies on iteration. # puts puts("Enter the number of characters in your word or phrase (not including spaces): ") length = gets.chomp.to_i arrangements = 1 length.times do |count| arrangements = arrangements * (count+1) end puts puts("There are " + arrangements.to_s + " possible arrangements.") puts