Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
18
Task/Permutations/DuckDB/permutations.duckdb
Normal file
18
Task/Permutations/DuckDB/permutations.duckdb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
CREATE OR REPLACE FUNCTION permute(lst) as table (
|
||||
WITH RECURSIVE permute(perm, remaining) as (
|
||||
-- base case
|
||||
SELECT
|
||||
[] as perm,
|
||||
lst as remaining
|
||||
UNION ALL
|
||||
-- recursive case: add one element from remaining to perm and remove it from remaining
|
||||
SELECT
|
||||
(perm || [element]) AS perm,
|
||||
(remaining[1:i-1] || remaining[i+1:]) AS remaining
|
||||
FROM (select *, unnest(remaining) AS element, generate_subscripts(remaining,1) as i
|
||||
FROM permute)
|
||||
)
|
||||
SELECT perm
|
||||
FROM permute
|
||||
WHERE length(remaining) = 0
|
||||
);
|
||||
6
Task/Permutations/Pluto/permutations.pluto
Normal file
6
Task/Permutations/Pluto/permutations.pluto
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
require "perm"
|
||||
local fmt = require "fmt"
|
||||
|
||||
local a = {1, 2, 3}
|
||||
print($"There are {perm.count(#a)} permutations of {fmt.swrite(a)}, namely:")
|
||||
fmt.lprint(perm.list(a))
|
||||
24
Task/Permutations/TAV/permutations-1.tav
Normal file
24
Task/Permutations/TAV/permutations-1.tav
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
\( Calculate all permutations of integers 1..n
|
||||
|
||||
General variant: simple, single array, recursive, not in lexical order
|
||||
A row with n places is used, initially 0.
|
||||
The current element l replaces the free places one by one,
|
||||
and the next element l+1 is probed with the array.
|
||||
\)
|
||||
\C Use publication mode with keywords instead of symbols
|
||||
permute1 (l) to (n) fill (r):
|
||||
if l > n
|
||||
print join r \ output requires most of CPU time
|
||||
return
|
||||
for j = from 1 upto n
|
||||
if r[j] == 0
|
||||
r[j] = l
|
||||
permute1 l+1 to n fill r
|
||||
r[j] = 0
|
||||
|
||||
\( command line parameter is number of elements
|
||||
\)
|
||||
main (parms):+
|
||||
n = string parms[1] as integer else 3
|
||||
r = new row size n init 0
|
||||
permute1 1 to n fill r
|
||||
28
Task/Permutations/TAV/permutations-2.tav
Normal file
28
Task/Permutations/TAV/permutations-2.tav
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
\( Calculate all permutations of integers 1..n
|
||||
|
||||
Second variant: two arrays, recursive, reverse lexical order.
|
||||
Array (a) has the remaining elements which are each appended to the
|
||||
array (t), removed and the rest applied to the expanded (t).
|
||||
The elements of row (a) may have any value; only void or not void is used.
|
||||
\)
|
||||
\c Use native mode (symbols instead of keywords, class functions)
|
||||
permute2 (a) to (t):
|
||||
l =: a.Count \ number of non-void elements
|
||||
? l > 0
|
||||
?# i =: row a give keys \ of non-void elements only
|
||||
t[l] =: i
|
||||
a[i] =: () \ decrements a.Count
|
||||
permute2 a to t
|
||||
a[i] =: i \ any non-void value
|
||||
:>
|
||||
\ print result in reverse order; output requires most CPU time
|
||||
print tuple t::as tuple transpose
|
||||
|
||||
|
||||
\( command line parameter is number of elements
|
||||
\)
|
||||
main (parms):+
|
||||
n =: string parms[1] as integer else 3
|
||||
a =: new row from 1 upto n \ fill 1..n
|
||||
t =: new row size n \ intially void
|
||||
permute2 a to t
|
||||
17
Task/Permutations/TAV/permutations-3.tav
Normal file
17
Task/Permutations/TAV/permutations-3.tav
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
\C Publication syntax
|
||||
permute (k) list (l):
|
||||
if k == l.Count
|
||||
print row l as tuple
|
||||
return
|
||||
for i = from k upto l.Count
|
||||
row l swap i with k
|
||||
permute k+1 list l
|
||||
row l swap k with i
|
||||
|
||||
row (l) swap (i) with (k):
|
||||
t = l[i]
|
||||
l[i] = l[k]
|
||||
l[k] = t
|
||||
|
||||
main (parms):+
|
||||
permute 1 list [1, 2, 3] \ row literal, not tuple
|
||||
44
Task/Permutations/TAV/permutations-4.tav
Normal file
44
Task/Permutations/TAV/permutations-4.tav
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
\( Two arrays, iterative, not in lexical order.
|
||||
Input row (a) provides for each element where it was inserted last.
|
||||
\)
|
||||
\C Publication syntax
|
||||
permute iterative (n):
|
||||
a = new row size n \ state of last number
|
||||
r = new row size n \ output row
|
||||
l = 1
|
||||
while l > 0 \ need to start over
|
||||
\ find the key of a void element
|
||||
k = 0 \ if not found
|
||||
for j = from a[l] + 1 upto n
|
||||
if r[j] == () \ void in result
|
||||
k = j \ use it
|
||||
continue
|
||||
\ evaluate
|
||||
if k != 0
|
||||
\ key for void cell to be set
|
||||
r[k] = l
|
||||
a[l] = k
|
||||
if l == n
|
||||
\ permuation complete
|
||||
print join r
|
||||
\ backup
|
||||
k = a[l]
|
||||
r[k] = ()
|
||||
continue
|
||||
l += 1
|
||||
continue \ next level
|
||||
\ no void cell found
|
||||
if l == 1
|
||||
break \ done, no more permutations
|
||||
\ backup
|
||||
a[l] = 0
|
||||
l -= 1
|
||||
k = a[l]
|
||||
r[k] = ()
|
||||
continue
|
||||
|
||||
\( command line parameter: number of elements
|
||||
\)
|
||||
main (parms):+
|
||||
n =: string parms[1] as integer else 3
|
||||
p =: permute iterative n
|
||||
Loading…
Add table
Add a link
Reference in a new issue