Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,22 @@
Rank(data, opt:=1){ ; opt = 1 Standard (default), 2 Modified, 3 Dense, 4 Ordinal, 5 Fractional
for index, val in StrSplit(data, "`n", "`r") {
RegExMatch(val, "^(\d+)\s+(.*)", Match)
if !(Match1=prev)
n := index
prev := Match1
Res1 .= n "`t" Match "`n"
Res4 .= index "`t" Match "`n"
Temp .= n ":" index " " Match "`n"
}
n:=0
while pos := RegExMatch(Temp, "`asm)^(\d+).*?\R(?!\1)|.+", Match, pos?pos+StrLen(Match):1) {
n += StrSplit(Trim(Match, "`r`n"), "`n", "`r").MaxIndex()
Res2 .= RegExReplace(Match, "`am)^\d+:\d+", n "`t")
Res3 .= RegExReplace(Match, "`am)^\d+:\d+", A_Index "`t")
R := 0
for index, val in StrSplit(Match, "`n", "`r")
R += StrSplit(val, ":").2
Res5 .= RegExReplace(Match, "`am)^\d+:\d+", RegExReplace(R / StrSplit(Trim(Match, "`r`n"), "`n", "`r").MaxIndex(), "\.?0+$") "`t")
}
return Res%opt%
}

View file

@ -0,0 +1,18 @@
data =
(
44 Solomon
42 Jason
42 Errol
41 Garry
41 Bernard
41 Barry
39 Stephen
)
MsgBox, 262144, ,% ""
. "Standard Ranking:`n" Rank(data)
. "`nModified Ranking:`n" Rank(data, 2)
. "`nDense Ranking:`n" Rank(data, 3)
. "`nOrdinal Ranking:`n" Rank(data, 4)
. "`nFractional Ranking:`n" Rank(data, 5)
return

View file

@ -0,0 +1,76 @@
(function () {
var xs = 'Solomon Jason Errol Garry Bernard Barry Stephen'.split(' '),
ns = [44, 42, 42, 41, 41, 41, 39],
sorted = xs.map(function (x, i) {
return { name: x, score: ns[i] };
}).sort(function (a, b) {
var c = b.score - a.score;
return c ? c : a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
}),
names = sorted.map(function (x) { return x.name; }),
scores = sorted.map(function (x) { return x.score; }),
reversed = scores.slice(0).reverse(),
unique = scores.filter(function (x, i) {
return scores.indexOf(x) === i;
});
// RANKINGS AS FUNCTIONS OF SCORES: SORTED, REVERSED AND UNIQUE
var rankings = function (score, index) {
return {
name: names[index],
score: score,
Ordinal: index + 1,
Standard: function (n) {
return scores.indexOf(n) + 1;
}(score),
Modified: function (n) {
return reversed.length - reversed.indexOf(n);
}(score),
Dense: function (n) {
return unique.indexOf(n) + 1;
}(score),
Fractional: function (n) {
return (
(scores.indexOf(n) + 1) +
(reversed.length - reversed.indexOf(n))
) / 2;
}(score)
};
},
tbl = [
'Name Score Standard Modified Dense Ordinal Fractional'.split(' ')
].concat(scores.map(rankings).reduce(function (a, x) {
return a.concat([
[x.name, x.score,
x.Standard, x.Modified, x.Dense, x.Ordinal, x.Fractional
]
]);
}, [])),
//[[a]] -> bool -> s -> s
wikiTable = function (lstRows, blnHeaderRow, strStyle) {
return '{| class="wikitable" ' + (
strStyle ? 'style="' + strStyle + '"' : ''
) + lstRows.map(function (lstRow, iRow) {
var strDelim = ((blnHeaderRow && !iRow) ? '!' : '|');
return '\n|-\n' + strDelim + ' ' + lstRow.map(function (v) {
return typeof v === 'undefined' ? ' ' : v;
}).join(' ' + strDelim + strDelim + ' ');
}).join('') + '\n|}';
};
return wikiTable(tbl, true, 'text-align:center');
})();

View file

@ -0,0 +1,3 @@
function ties{T<:Real}(a::Array{T,1})
unique(a[2:end][a[2:end] .== a[1:end-1]])
end

View file

@ -0,0 +1,8 @@
function rankstandard{T<:Real}(a::Array{T,1})
r = collect(1:length(a))
1 < r[end] || return r
for i in ties(a)
r[a.==i] = r[a.==i][1]
end
return r
end

View file

@ -0,0 +1,3 @@
function rankmodified{T<:Real}(a::Array{T,1})
indexin(a, a)
end

View file

@ -0,0 +1,3 @@
function rankdense{T<:Real}(a::Array{T,1})
indexin(a, unique(a))
end

View file

@ -0,0 +1,3 @@
function rankordinal{T<:Real}(a::Array{T,1})
collect(1:length(a))
end

View file

@ -0,0 +1,8 @@
function rankfractional{T<:Real}(a::Array{T,1})
r = float64(collect(1:length(a)))
1.0 < r[end] || return r
for i in ties(a)
r[a.==i] = mean(r[a.==i])
end
return r
end

View file

@ -0,0 +1,21 @@
scores = [44, 42, 42, 41, 41, 41, 39]
names = ["Solomon", "Jason", "Errol", "Garry",
"Bernard", "Barry", "Stephen"]
srank = rankstandard(scores)
mrank = rankmodified(scores)
drank = rankdense(scores)
orank = rankordinal(scores)
frank = rankfractional(scores)
println(" Name Score Std Mod Den Ord Frac")
for i in 1:length(scores)
print(@sprintf(" %-7s", names[i]))
print(@sprintf("%5d ", scores[i]))
print(@sprintf("%5d", srank[i]))
print(@sprintf("%5d", mrank[i]))
print(@sprintf("%5d", drank[i]))
print(@sprintf("%5d", orank[i]))
print(@sprintf("%7.2f", frank[i]))
println()
end

View file

@ -0,0 +1,49 @@
/**************************
44 Solomon 1 1 1 1 1
42 Jason 2 3 2 2 2.5
42 Errol 2 3 2 3 2.5
41 Garry 4 6 3 4 5
41 Bernard 4 6 3 5 5
41 Barry 4 6 3 6 5
39 Stephen 7 7 4 7 7
**************************/
Do i=1 To 7
Parse Value sourceline(i+1) With rank.i name.i .
/* say rank.i name.i */
End
pool=0
crank=0
Do i=1 To 7
If rank.i<>crank Then Do
pool=pool+1
lo.pool=i
hi.pool=i
n.pool=1
ii.pool=i
End
Else Do
n.pool=n.pool+1
hi.pool=i
ii.pool=ii.pool+i
End
crank=rank.i
pool.i=pool
End
/*
Do j=1 To pool
Say 'pool' j n.j lo.j hi.j
End
*/
cp=0
r=0
cnt.=0
Do i=1 To 7
p=pool.i
If p<>cp Then
r=r+1
res=rank.i left(name.i,8) lo.p hi.p r i ii.p/n.p
If res=sourceline(i+1) Then cnt.ok=cnt.ok+1
Say res
cp=p
End
Say cnt.ok 'correct lines'