Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: February 16, 2025, 8:41 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bruteforce
#1
Bruteforce
Basically what i want to do is this:

Input Example 1:

abc

Output:

abc
acb
bac
bca
cba
cab

Input Example 2:

abcd

Output:

abcd
abdc
acdb
acbd
adbc
adcb
bacd
badc
bcda
bcad
bdac
bdca
cabd
cadb
cbda
cbad
cdab
cdba
dacb
dabc
dbca
dbac
dcda
dcad


What i want to do is to print all the different possibilities of a given string.


The current method i'm following:

*Swap the first character with the second character
*Swap the second character with the third character
*Repeat swapping until at least one of the character involved in swapping is the null character.


The problem with my current method:

*Hell lot of duplications,i.e,"input" outputting atleast more than once.
*Doesn't output all the combinations.

What i'd like for you to do is give me some hints as to what i'm doing wrong and give me a working pseudo code to solve my crisis(not a direct solution,please).
Yes,i could've posted this in some programmer forum,but i'm not sure how i'm supposed to form my question.I'd go there and indefinitely make myself look a fool Rolleyes This forum is more safe since we've already established i'm a moron.

P.S. 
I spend all my last years vacation trying to find a solution to this problem and i did.The problem is,it was kind of like a fluke,i think.
I spend so much time on it,it worked at last,i slept and i woke up,i tried to read my code and i was like wtf is this.
Short story short: I solved the problem but after a good night's sleep i no longer remembered how i solved it,and i couldn't even figure what i did in my code either,yeah my code was that ugly.
I've tested that program,and it works,but although it works i'm not sure if its the most efficient,also there are a lot of duplications,so instead of my cave man problem solving skills,i was wondering if someone could provide me with a methodical approach to the problem.
If its possible i'd like a Recursive as well as an iterative approach to solve the problem(i prefer iterative solution though).
Reply



Messages In This Thread
Bruteforce - by ErGingerbreadMandude - August 2, 2015 at 7:54 am
RE: Bruteforce - by vorlon13 - August 2, 2015 at 9:09 am
RE: Bruteforce - by Aractus - August 2, 2015 at 9:18 am
RE: Bruteforce - by vorlon13 - August 2, 2015 at 9:21 am
RE: Bruteforce - by ErGingerbreadMandude - August 2, 2015 at 9:33 am
RE: Bruteforce - by Alex K - August 2, 2015 at 9:47 am
RE: Bruteforce - by Aoi Magi - August 2, 2015 at 10:15 am
RE: Bruteforce - by ErGingerbreadMandude - August 2, 2015 at 10:48 am
RE: Bruteforce - by LastPoet - August 2, 2015 at 10:55 am
RE: Bruteforce - by ErGingerbreadMandude - August 2, 2015 at 11:16 am
RE: Bruteforce - by LastPoet - August 2, 2015 at 2:56 pm
RE: Bruteforce - by ErGingerbreadMandude - August 2, 2015 at 3:15 pm
RE: Bruteforce - by Ravenshire - August 2, 2015 at 3:17 pm
RE: Bruteforce - by LastPoet - August 2, 2015 at 3:25 pm
RE: Bruteforce - by emjay - August 2, 2015 at 3:44 pm
RE: Bruteforce - by Alex K - August 2, 2015 at 4:59 pm
RE: Bruteforce - by ErGingerbreadMandude - August 2, 2015 at 3:41 pm
RE: Bruteforce - by bennyboy - August 9, 2015 at 8:59 am



Users browsing this thread: 1 Guest(s)