473,804 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Permutations of a given string

Write a program to print all the permutations of a given string.
Jul 4 '08 #1
16 3069
saki said:
Write a program to print all the permutations of a given string.
Okay.

ginrst ginrts ginsrt ginstr gintrs gintsr girnst girnts girsnt girstn
girtns girtsn gisnrt gisntr gisrnt gisrtn gistnr gistrn gitnrs gitnsr
gitrns gitrsn gitsnr gitsrn gnirst gnirts gnisrt gnistr gnitrs gnitsr
gnrist gnrits gnrsit gnrsti gnrtis gnrtsi gnsirt gnsitr gnsrit gnsrti
gnstir gnstri gntirs gntisr gntris gntrsi gntsir gntsri grinst grints
grisnt gristn gritns gritsn grnist grnits grnsit grnsti grntis grntsi
grsint grsitn grsnit grsnti grstin grstni grtins grtisn grtnis grtnsi
grtsin grtsni gsinrt gsintr gsirnt gsirtn gsitnr gsitrn gsnirt gsnitr
gsnrit gsnrti gsntir gsntri gsrint gsritn gsrnit gsrnti gsrtin gsrtni
gstinr gstirn gstnir gstnri gstrin gstrni gtinrs gtinsr gtirns gtirsn
gtisnr gtisrn gtnirs gtnisr gtnris gtnrsi gtnsir gtnsri gtrins gtrisn
gtrnis gtrnsi gtrsin gtrsni gtsinr gtsirn gtsnir gtsnri gtsrin gtsrni
ignrst ignrts ignsrt ignstr igntrs igntsr igrnst igrnts igrsnt igrstn
igrtns igrtsn igsnrt igsntr igsrnt igsrtn igstnr igstrn igtnrs igtnsr
igtrns igtrsn igtsnr igtsrn ingrst ingrts ingsrt ingstr ingtrs ingtsr
inrgst inrgts inrsgt inrstg inrtgs inrtsg insgrt insgtr insrgt insrtg
instgr instrg intgrs intgsr intrgs intrsg intsgr intsrg irgnst irgnts
irgsnt irgstn irgtns irgtsn irngst irngts irnsgt irnstg irntgs irntsg
irsgnt irsgtn irsngt irsntg irstgn irstng irtgns irtgsn irtngs irtnsg
irtsgn irtsng isgnrt isgntr isgrnt isgrtn isgtnr isgtrn isngrt isngtr
isnrgt isnrtg isntgr isntrg isrgnt isrgtn isrngt isrntg isrtgn isrtng
istgnr istgrn istngr istnrg istrgn istrng itgnrs itgnsr itgrns itgrsn
itgsnr itgsrn itngrs itngsr itnrgs itnrsg itnsgr itnsrg itrgns itrgsn
itrngs itrnsg itrsgn itrsng itsgnr itsgrn itsngr itsnrg itsrgn itsrng
ngirst ngirts ngisrt ngistr ngitrs ngitsr ngrist ngrits ngrsit ngrsti
ngrtis ngrtsi ngsirt ngsitr ngsrit ngsrti ngstir ngstri ngtirs ngtisr
ngtris ngtrsi ngtsir ngtsri nigrst nigrts nigsrt nigstr nigtrs nigtsr
nirgst nirgts nirsgt nirstg nirtgs nirtsg nisgrt nisgtr nisrgt nisrtg
nistgr nistrg nitgrs nitgsr nitrgs nitrsg nitsgr nitsrg nrgist nrgits
nrgsit nrgsti nrgtis nrgtsi nrigst nrigts nrisgt nristg nritgs nritsg
nrsgit nrsgti nrsigt nrsitg nrstgi nrstig nrtgis nrtgsi nrtigs nrtisg
nrtsgi nrtsig nsgirt nsgitr nsgrit nsgrti nsgtir nsgtri nsigrt nsigtr
nsirgt nsirtg nsitgr nsitrg nsrgit nsrgti nsrigt nsritg nsrtgi nsrtig
nstgir nstgri nstigr nstirg nstrgi nstrig ntgirs ntgisr ntgris ntgrsi
ntgsir ntgsri ntigrs ntigsr ntirgs ntirsg ntisgr ntisrg ntrgis ntrgsi
ntrigs ntrisg ntrsgi ntrsig ntsgir ntsgri ntsigr ntsirg ntsrgi ntsrig
rginst rgints rgisnt rgistn rgitns rgitsn rgnist rgnits rgnsit rgnsti
rgntis rgntsi rgsint rgsitn rgsnit rgsnti rgstin rgstni rgtins rgtisn
rgtnis rgtnsi rgtsin rgtsni rignst rignts rigsnt rigstn rigtns rigtsn
ringst ringts rinsgt rinstg rintgs rintsg risgnt risgtn risngt risntg
ristgn ristng ritgns ritgsn ritngs ritnsg ritsgn ritsng rngist rngits
rngsit rngsti rngtis rngtsi rnigst rnigts rnisgt rnistg rnitgs rnitsg
rnsgit rnsgti rnsigt rnsitg rnstgi rnstig rntgis rntgsi rntigs rntisg
rntsgi rntsig rsgint rsgitn rsgnit rsgnti rsgtin rsgtni rsignt rsigtn
rsingt rsintg rsitgn rsitng rsngit rsngti rsnigt rsnitg rsntgi rsntig
rstgin rstgni rstign rsting rstngi rstnig rtgins rtgisn rtgnis rtgnsi
rtgsin rtgsni rtigns rtigsn rtings rtinsg rtisgn rtisng rtngis rtngsi
rtnigs rtnisg rtnsgi rtnsig rtsgin rtsgni rtsign rtsing rtsngi rtsnig
sginrt sgintr sgirnt sgirtn sgitnr sgitrn sgnirt sgnitr sgnrit sgnrti
sgntir sgntri sgrint sgritn sgrnit sgrnti sgrtin sgrtni sgtinr sgtirn
sgtnir sgtnri sgtrin sgtrni signrt signtr sigrnt sigrtn sigtnr sigtrn
singrt singtr sinrgt sinrtg sintgr sintrg sirgnt sirgtn sirngt sirntg
sirtgn sirtng sitgnr sitgrn sitngr sitnrg sitrgn sitrng sngirt sngitr
sngrit sngrti sngtir sngtri snigrt snigtr snirgt snirtg snitgr snitrg
snrgit snrgti snrigt snritg snrtgi snrtig sntgir sntgri sntigr sntirg
sntrgi sntrig srgint srgitn srgnit srgnti srgtin srgtni srignt srigtn
sringt srintg sritgn sritng srngit srngti srnigt srnitg srntgi srntig
srtgin srtgni srtign srting srtngi srtnig stginr stgirn stgnir stgnri
stgrin stgrni stignr stigrn stingr stinrg stirgn stirng stngir stngri
stnigr stnirg stnrgi stnrig strgin strgni strign string strngi strnig
tginrs tginsr tgirns tgirsn tgisnr tgisrn tgnirs tgnisr tgnris tgnrsi
tgnsir tgnsri tgrins tgrisn tgrnis tgrnsi tgrsin tgrsni tgsinr tgsirn
tgsnir tgsnri tgsrin tgsrni tignrs tignsr tigrns tigrsn tigsnr tigsrn
tingrs tingsr tinrgs tinrsg tinsgr tinsrg tirgns tirgsn tirngs tirnsg
tirsgn tirsng tisgnr tisgrn tisngr tisnrg tisrgn tisrng tngirs tngisr
tngris tngrsi tngsir tngsri tnigrs tnigsr tnirgs tnirsg tnisgr tnisrg
tnrgis tnrgsi tnrigs tnrisg tnrsgi tnrsig tnsgir tnsgri tnsigr tnsirg
tnsrgi tnsrig trgins trgisn trgnis trgnsi trgsin trgsni trigns trigsn
trings trinsg trisgn trisng trngis trngsi trnigs trnisg trnsgi trnsig
trsgin trsgni trsign trsing trsngi trsnig tsginr tsgirn tsgnir tsgnri
tsgrin tsgrni tsignr tsigrn tsingr tsinrg tsirgn tsirng tsngir tsngri
tsnigr tsnirg tsnrgi tsnrig tsrgin tsrgni tsrign tsring tsrngi tsrnig
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 4 '08 #2
saki wrote:
Write a program to print all the permutations of a given string.
for (i=0; i<MAXTRIES;i++ )

printf("DO YOUR OWN HOMEWORK!!!\n") ;
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 4 '08 #3
"saki" wrote:
Write a program to print all the permutations of a given string.
Wikipedia is often helpful, see if this gets you started.

http://en.wikipedia.org/wiki/Permuta...mplementations
Jul 4 '08 #4
saki wrote:
Write a program to print all the permutations of a given string.
#define GIVEN_STRING ""
int main(void) {
return 0;
}

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jul 4 '08 #5
On 4 Jul, 14:18, saki <sakethstud...@ gmail.comwrote:
Write a program to print all the permutations of a given string.
(define (permutations s)
(if (null? s)
(list nil)
(flatmap (lambda (x)
(map (lambda (p) (cons x p))
(permutaions (remove x s))))
s)))

[SICP p124]

--
Nick Keighley

Jul 4 '08 #6
Eric Sosman <es*****@ieee-dot-org.invalidwrit es:
saki wrote:
>Write a program to print all the permutations of a given string.

#define GIVEN_STRING ""
int main(void) {
return 0;
}
The empty string has one permutation.

Oh, I see, you didn't print a new-line after printing the permutation.

Which actually raises a nearly interesting issue. C99 7.19.2p2 says:

A text stream is an ordered sequence of characters composed into
_lines_, each line consisting of zero or more characters plus a
terminating new-line character. Whether the last line requires a
terminating new-line character is implementation-defined.

It's not clear from this wording whether an empty stream, consisting
of zero lines, is valid. I have no doubt that it was intended to be
the case; this is merely an issue about the wording in the standard.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 4 '08 #7
saki <sa***********@ gmail.comwrites :
Write a program to print all the permutations of a given string.
Not even if you said "please".

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 4 '08 #8
On Fri, 04 Jul 2008 12:37:12 -0700, Keith Thompson wrote:
Which actually raises a nearly interesting issue. C99 7.19.2p2 says:

A text stream is an ordered sequence of characters composed into
_lines_, each line consisting of zero or more characters plus a
terminating new-line character. Whether the last line requires a
terminating new-line character is implementation-defined.

It's not clear from this wording whether an empty stream, consisting of
zero lines, is valid. I have no doubt that it was intended to be the
case; this is merely an issue about the wording in the standard.
Your inference that an empty stream contains zero lines is only valid on
implementations that define a line as requiring a newline character.
Under implementations which define the final newline as optional or
forbidden, the empty (zero-character) stream may contain 1 line.

In any case if you are going to be picky over an entirely academic point,
the standard you quote above says "lines" not "line or lines", so one
could argue that a one-line stream was invalid. Even discussing it would
be a bit sad though...

viza
Jul 5 '08 #9
viza <to******@gm-il.com.obviousc hange.invalidwr ites:
On Fri, 04 Jul 2008 12:37:12 -0700, Keith Thompson wrote:
>Which actually raises a nearly interesting issue. C99 7.19.2p2 says:

A text stream is an ordered sequence of characters composed into
_lines_, each line consisting of zero or more characters plus a
terminating new-line character. Whether the last line requires a
terminating new-line character is implementation-defined.

It's not clear from this wording whether an empty stream, consisting of
zero lines, is valid. I have no doubt that it was intended to be the
case; this is merely an issue about the wording in the standard.

Your inference that an empty stream contains zero lines is only valid on
implementations that define a line as requiring a newline character.
Under implementations which define the final newline as optional or
forbidden, the empty (zero-character) stream may contain 1 line.

In any case if you are going to be picky over an entirely academic point,
the standard you quote above says "lines" not "line or lines", so one
could argue that a one-line stream was invalid.
Yes, you're right; I was going to mention that.
Even discussing it would
be a bit sad though...
Why? What's wrong with discussing an opportunity to improve the
wording of the standard (apart from the fact that it would be more
appropriate i comp.std.c)?

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 5 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
5685
by: Steve Goldman | last post by:
Hi, I am trying to come up with a way to develop all n-length permutations of a given list of values. The short function below seems to work, but I can't help thinking there's a better way. Not being a computer scientist, I find recursive functions to be frightening and unnatural. I'd appreciate if anyone can tell me the pythonic idiom to accomplish this. Thanks for your help,
9
3135
by: Jeff Kish | last post by:
Hi. I realize this might be more of a "figure out the algorithm" thing than strictly an std question.. sorry if it is off topic? It certainly was in the other group! Also, I'm pretty old, not in school.. just trying to figure this out., so it isn't an assignment.
4
8205
by: darin dimitrov | last post by:
Hello, I need help with an algoritm that given a set of "n" distinct numbers will generate all the possible permutations of fixed length "m" of these numbers WITH repetitions (a total of n^m possibilities). For example: given the set {1, 2} would output: 111,112,121,122,211,212,221,222 if we fix m=3.
7
4192
by: Chris Lasher | last post by:
Hi all, How can one count all the permutations of a substring in a string? For a more concrete example, let's say targetstr = 'AAA' and probestr = 'AA' I want to consider how many times one can count probestr ('AA') in targetstr ('AAA'). The value in this example is, obviously, 2: you can match the first and second A's as 'AA' and also the second and third
17
4709
by: anurag | last post by:
hey can anyone help me in writing a code in c (function) that prints all permutations of a string.please help
7
2513
by: Christian Meesters | last post by:
Hi, I'd like to hack a function which returns all possible permutations as lists (or tuples) of two from a given list. So far, I came up with this solution, but it turned out to be too slow for the given problem, because the list passed ("atomlist") can be some 1e5 items long: def permute(atomlist, size = 2): """ returns a list of atoms grouped by two
0
12595
by: JosAH | last post by:
Greetings, last week I stated that a lot of topics in a lot of forums mention all sorts of sorting problems. Last week's tip gave an answer to quite a bit of those sorting problems. Another "favourite" (mind the quotes) topic is about permutations and combinations. This week's tip shows how permutations can be generated in an efficient way. A next tip talks about how combinations can be generated efficiently. First here's an...
1
10939
by: JosAH | last post by:
Greetings, last week we talked a bit about generating permutations and I told you that this week will be about combinations. Not true; there's a bit more to tell about permutations and that's what this Tip Of The Week is about. Maybe later we'll talk a bit about combinations (if anyone's interested). The little utility class we implemented last week was able to generate a next permutation (if any) given a current permutation. But what...
2
5902
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the dictionary essentially creates the following array: Key Value
0
10583
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.