[challenge] String Permutations 06-03-2015, 09:51 PM
#1
Warning: this challenge is a HUGE pain in the dick and took me 2+ hours to complete
The purpose of said pain in the dick challenge to write a program which prints all the permutations of a string in alphabetical order separated by a comma, considering that digits < upper case letters < lower case letters.
In case you're confused, a permutation is simply a way of arranging characters in a given set of data. This is done a lot in grade school math and science.
I/O example:
Input:
Output:
Guidelines:
The code you will need to permute (one set per line) is:
Rules:
- No imports unless required
- No use of semicolons when not absolutely necessary
- Code < 6 lines AND 250 characters or less = 20 NSP prize
- Don't bother copying all the text to show output, just post a screenshot
[spoiler=My Code:]
Code (omitted user from filepath):
7 lines, 364 characters
Output:
fits perfectly in a default-sized windows cmd window, which is nice
![[Image: 2f2Bd3d.png]](https://i.imgur.com/2f2Bd3d.png)
[/spoiler]
Some Encouragement:
This challenge is listed under "hard" on CodeEval, which, believe me, is really, really, fucking hard.
The only reason I got this done was because I had a few hours to kill during school, which is currently in moratorium.
The purpose of said pain in the dick challenge to write a program which prints all the permutations of a string in alphabetical order separated by a comma, considering that digits < upper case letters < lower case letters.
In case you're confused, a permutation is simply a way of arranging characters in a given set of data. This is done a lot in grade school math and science.
I/O example:
Input:
Code:
acb
fde
ighOutput:
Code:
abc,acb,bac,bca,cab,cba
def,dfe,edf,efd,fde,fed
ghi,gih,hgi,hig,igh,ihgGuidelines:
The code you will need to permute (one set per line) is:
Code:
AV7
A2La
faHd
7peP
eAg
y68B
HgAf
mt06p
V2c4
FfNhRules:
- No imports unless required
- No use of semicolons when not absolutely necessary
- Code < 6 lines AND 250 characters or less = 20 NSP prize
- Don't bother copying all the text to show output, just post a screenshot
[spoiler=My Code:]
Code (omitted user from filepath):
7 lines, 364 characters
Code:
File.open("C:/Users/Kagetane/Desktop/Code/Ruby/test.txt").each_line { |line| perms = []
v = line.include?("\n") ? line.split("")[0..-2] : line.split("")[0..-1]
v.permutation.map { |str| perm = []
str.include?("\n") and str != v[-1] ? str = nil : nil
str.each { |u| perm << u } if str != nil
perms << perm.join("") }
puts perms.sort.join(",") }Output:
fits perfectly in a default-sized windows cmd window, which is nice
![[Image: 2f2Bd3d.png]](https://i.imgur.com/2f2Bd3d.png)
[/spoiler]
Some Encouragement:
This challenge is listed under "hard" on CodeEval, which, believe me, is really, really, fucking hard.
The only reason I got this done was because I had a few hours to kill during school, which is currently in moratorium.
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.

















![[+]](https://sinister.li/images/modern/collapse_collapsed.png)













![[Image: 3447WyE.png]](http://i.imgur.com/3447WyE.png)









![[Image: PPueK6Y.png]](http://i.imgur.com/PPueK6Y.png)
![[Image: CDUAq9d.png]](http://i.imgur.com/CDUAq9d.png)