Permutations: Difference between revisions
Content added Content deleted
m (→{{header|Common Lisp}}: botched lang tag) |
(→{{header|AutoHotkey}}: AutoHotkey example) |
||
Line 352: | Line 352: | ||
</pre> |
</pre> |
||
=={{header|AutoHotkey}}== |
|||
from the forum topic http://www.autohotkey.com/forum/viewtopic.php?t=77959 |
|||
<lang AutoHotkey>#NoEnv |
|||
StringCaseSense On |
|||
o := str := "Hello" |
|||
Loop |
|||
{ |
|||
str := perm_next(str) |
|||
If !str |
|||
{ |
|||
MsgBox % clipboard := o |
|||
break |
|||
} |
|||
o.= "`n" . str |
|||
} |
|||
perm_Next(str){ |
|||
p := 0, sLen := StrLen(str) |
|||
Loop % sLen |
|||
{ |
|||
If A_Index=1 |
|||
continue |
|||
t := SubStr(str, sLen+1-A_Index, 1) |
|||
n := SubStr(str, sLen+2-A_Index, 1) |
|||
If ( t < n ) |
|||
{ |
|||
p := sLen+1-A_Index, pC := SubStr(str, p, 1) |
|||
break |
|||
} |
|||
} |
|||
If !p |
|||
return false |
|||
Loop |
|||
{ |
|||
t := SubStr(str, sLen+1-A_Index, 1) |
|||
If ( t > pC ) |
|||
{ |
|||
n := sLen+1-A_Index, nC := SubStr(str, n, 1) |
|||
break |
|||
} |
|||
} |
|||
return SubStr(str, 1, p-1) . nC . Reverse(SubStr(str, p+1, n-p-1) . pC . SubStr(str, n+1)) |
|||
} |
|||
Reverse(s){ |
|||
Loop Parse, s |
|||
o := A_LoopField o |
|||
return o |
|||
} |
|||
</lang> |
|||
Output: |
|||
<pre style="height:40ex;overflow:scroll">Hello |
|||
Helol |
|||
Heoll |
|||
Hlelo |
|||
Hleol |
|||
Hlleo |
|||
Hlloe |
|||
Hloel |
|||
Hlole |
|||
Hoell |
|||
Holel |
|||
Holle |
|||
eHllo |
|||
eHlol |
|||
eHoll |
|||
elHlo |
|||
elHol |
|||
ellHo |
|||
elloH |
|||
eloHl |
|||
elolH |
|||
eoHll |
|||
eolHl |
|||
eollH |
|||
lHelo |
|||
lHeol |
|||
lHleo |
|||
lHloe |
|||
lHoel |
|||
lHole |
|||
leHlo |
|||
leHol |
|||
lelHo |
|||
leloH |
|||
leoHl |
|||
leolH |
|||
llHeo |
|||
llHoe |
|||
lleHo |
|||
lleoH |
|||
lloHe |
|||
lloeH |
|||
loHel |
|||
loHle |
|||
loeHl |
|||
loelH |
|||
lolHe |
|||
loleH |
|||
oHell |
|||
oHlel |
|||
oHlle |
|||
oeHll |
|||
oelHl |
|||
oellH |
|||
olHel |
|||
olHle |
|||
oleHl |
|||
olelH |
|||
ollHe |
|||
olleH</pre> |
|||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
The procedure PROC_NextPermutation() will give the next lexicographic permutation of an integer array. |
The procedure PROC_NextPermutation() will give the next lexicographic permutation of an integer array. |