r/dailyprogrammer • u/nottoobadguy • Feb 20 '12
[2/20/2012] Challenge #12 [easy]
Write a small program that can take a string:
"hi!"
and print all the possible permutations of the string:
"hi!"
"ih!"
"!hi"
"h!i"
"i!h"
etc...
thanks to hewts for this challenge!
17
Upvotes
7
u/luxgladius 0 0 Feb 20 '12
I suggest that using builtin permutation generators of the language really isn't that instructive...
Perl:
3
u/JerMenKoO 0 0 Feb 20 '12
Python:
2
u/eruonna Feb 20 '12
Haskell:
2
u/[deleted] Feb 20 '12
Perl. Actually went about this a unique way, I think. Numbers in sequence already permutate if going from smallest possible to highest possible.
Eg: Input: 3241 Counting 1234 to 4321 will pass all 24 possible combination. Take a string and assign it integers based on letter position then run through the valid sets.
2
u/Crystal_Cuckoo Feb 21 '12
Python:
1
u/kuzux 0 0 Feb 20 '12
Clojure:
1
u/nothingatall544 Feb 20 '12
It's not pretty, elegant, or filled with magic but it does work.
Java:
1
u/drb226 0 0 Feb 21 '12
Haskell: cheating a bit by using
permutationsfromData.ListI threw
nubin there to remove duplicate permutations. Usage:1
u/lukz 2 0 Feb 21 '12
Common Lisp
Special care taken for the case when the word contains double letters, e.g. "hill", so that some words are not printed twice.
1
u/Devanon Feb 22 '12
Here is my recursive implementation in C:
1
u/Steve132 0 1 Mar 02 '12
1
u/ragtag_creature Dec 12 '22
R