September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1 @@
perm 4

View file

@ -0,0 +1,49 @@
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
i = n
for (i = n; i > 1; i--) {
if (u[i-1] < u[i]) break
}
if (i > 1) {
j = i
k = n
while (j < k) {
s = u[j]
u[j] = u[k]
u[k] = s
j++
k--
}
s = u[i-1]
j = i
for (j = i; u[j] < s; j++) {
}
u[i-1] = u[j]
u[j] = s
}
} while (i > 1)
}
end