Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
49
Task/Permutations/AutoHotkey/permutations-1.ahk
Normal file
49
Task/Permutations/AutoHotkey/permutations-1.ahk
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#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
|
||||
}
|
||||
33
Task/Permutations/AutoHotkey/permutations-2.ahk
Normal file
33
Task/Permutations/AutoHotkey/permutations-2.ahk
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
P(n,k="",opt=0,delim="",str="") { ; generate all n choose k permutations lexicographically
|
||||
;1..n = range, or delimited list, or string to parse
|
||||
; to process with a different min index, pass a delimited list, e.g. "0`n1`n2"
|
||||
;k = length of result
|
||||
;opt 0 = no repetitions
|
||||
;opt 1 = with repetitions
|
||||
;opt 2 = run for 1..k
|
||||
;opt 3 = run for 1..k with repetitions
|
||||
;str = string to prepend (used internally)
|
||||
;returns delimited string, error message, or (if k > n) a blank string
|
||||
i:=0
|
||||
If !InStr(n,"`n")
|
||||
If n in 2,3,4,5,6,7,8,9
|
||||
Loop, %n%
|
||||
n := A_Index = 1 ? A_Index : n "`n" A_Index
|
||||
Else
|
||||
Loop, Parse, n, %delim%
|
||||
n := A_Index = 1 ? A_LoopField : n "`n" A_LoopField
|
||||
If (k = "")
|
||||
RegExReplace(n,"`n","",k), k++
|
||||
If k is not Digit
|
||||
Return "k must be a digit."
|
||||
If opt not in 0,1,2,3
|
||||
Return "opt invalid."
|
||||
If k = 0
|
||||
Return str
|
||||
Else
|
||||
Loop, Parse, n, `n
|
||||
If (!InStr(str,A_LoopField) || opt & 1)
|
||||
s .= (!i++ ? (opt & 2 ? str "`n" : "") : "`n" )
|
||||
. P(n,k-1,opt,delim,str . A_LoopField . delim)
|
||||
Return s
|
||||
}
|
||||
1
Task/Permutations/AutoHotkey/permutations-3.ahk
Normal file
1
Task/Permutations/AutoHotkey/permutations-3.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
MsgBox % P(3)
|
||||
1
Task/Permutations/AutoHotkey/permutations-4.ahk
Normal file
1
Task/Permutations/AutoHotkey/permutations-4.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
MsgBox % P("Hello",3)
|
||||
1
Task/Permutations/AutoHotkey/permutations-5.ahk
Normal file
1
Task/Permutations/AutoHotkey/permutations-5.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
MsgBox % P("2`n3`n4`n5",2,3)
|
||||
1
Task/Permutations/AutoHotkey/permutations-6.ahk
Normal file
1
Task/Permutations/AutoHotkey/permutations-6.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
MsgBox % P("11 a text ] u+z",3,0," ")
|
||||
Loading…
Add table
Add a link
Reference in a new issue