Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,60 @@
|
|||
PatienceSort(A){
|
||||
P:=0, Pile:=[], Result:=[]
|
||||
for k, v in A
|
||||
{
|
||||
Pushed := 0
|
||||
loop % P
|
||||
{
|
||||
i := A_Index
|
||||
if Pile[i].Count() && (Pile[i, 1] >= v)
|
||||
{
|
||||
Pile[i].InsertAt(1, v)
|
||||
pushed := true
|
||||
break
|
||||
}
|
||||
}
|
||||
if Pushed
|
||||
continue
|
||||
P++
|
||||
Pile[p] := []
|
||||
Pile[p].InsertAt(1, v)
|
||||
}
|
||||
|
||||
; optional to show steps ;;;;;;;;;;;;;;;;;;;;;;;
|
||||
loop % P
|
||||
{
|
||||
i := A_Index, step := ""
|
||||
for k, v in Pile[i]
|
||||
step .= v ", "
|
||||
step := "Pile" i " = " Trim(step, ", ")
|
||||
steps .= step "`n"
|
||||
}
|
||||
MsgBox % steps
|
||||
; end optional ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
loop % A.Count()
|
||||
{
|
||||
Collect:=[]
|
||||
loop % P
|
||||
if Pile[A_index].Count()
|
||||
Collect.Push(Pile[A_index, 1])
|
||||
|
||||
for k, v in Collect
|
||||
if k=1
|
||||
m := v
|
||||
else if (v < m)
|
||||
{
|
||||
m := v
|
||||
break
|
||||
}
|
||||
|
||||
Result.push(m)
|
||||
loop % P
|
||||
if (m = Pile[A_index, 1])
|
||||
{
|
||||
Pile[A_index].RemoveAt(1)
|
||||
break
|
||||
}
|
||||
}
|
||||
return Result
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
Test := [[4, 65, 2, -31, 0, 99, 83, 782, 1]
|
||||
,["n", "o", "n", "z", "e", "r", "o", "s", "u", "m"]
|
||||
,["dog", "cow", "cat", "ape", "ant", "man", "pig", "ass", "gnu"]]
|
||||
|
||||
for i, v in Test{
|
||||
X := PatienceSort(V)
|
||||
output := ""
|
||||
for k, v in X
|
||||
output .= v ", "
|
||||
MsgBox % "[" Trim(output, ", ") "]"
|
||||
}
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue