Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Permutations/Stata/permutations-1.stata
Normal file
1
Task/Permutations/Stata/permutations-1.stata
Normal file
|
|
@ -0,0 +1 @@
|
|||
perm 4
|
||||
41
Task/Permutations/Stata/permutations-2.stata
Normal file
41
Task/Permutations/Stata/permutations-2.stata
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
program perm
|
||||
local n=`1'
|
||||
local r=1
|
||||
forv i=1/`n' {
|
||||
local r=`r'*`i'
|
||||
}
|
||||
clear
|
||||
qui set obs `r'
|
||||
forv i=1/`n' {
|
||||
gen p`i'=0
|
||||
}
|
||||
mata: genperm()
|
||||
end
|
||||
|
||||
mata
|
||||
void genperm() {
|
||||
real scalar n, i, j, k, s, p
|
||||
real rowvector u
|
||||
st_view(a=., ., .)
|
||||
n = cols(a)
|
||||
u = 1..n
|
||||
p = 1
|
||||
do {
|
||||
a[p++, .] = u
|
||||
for (i = n; i > 1; i--) {
|
||||
if (u[i-1] < u[i]) break
|
||||
}
|
||||
if (i > 1) {
|
||||
j = i
|
||||
k = n
|
||||
while (j < k) u[(j++, k--)] = u[(k, j)]
|
||||
|
||||
s = u[i-1]
|
||||
for (j = i; u[j] < s; j++) {
|
||||
}
|
||||
u[i-1] = u[j]
|
||||
u[j] = s
|
||||
}
|
||||
} while (i > 1)
|
||||
}
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue