Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
62
Task/Ranking-methods/EasyLang/ranking-methods.easy
Normal file
62
Task/Ranking-methods/EasyLang/ranking-methods.easy
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
func[] StandardRank d[] .
|
||||
for i to len d[]
|
||||
if i = 1 or d[i] <> d[i - 1] : k = i
|
||||
r[] &= k
|
||||
.
|
||||
return r[]
|
||||
.
|
||||
func[] ModifiedRank d[] .
|
||||
for i to len d[]
|
||||
k = i
|
||||
j = i + 1
|
||||
while j <= len d[] and d[i] = d[j]
|
||||
k = j
|
||||
j += 1
|
||||
.
|
||||
r[] &= k
|
||||
.
|
||||
return r[]
|
||||
.
|
||||
func[] DenseRank d[] .
|
||||
for i to len d[]
|
||||
if i = 1 or d[i] <> d[i - 1] : k += 1
|
||||
r[] &= k
|
||||
.
|
||||
return r[]
|
||||
.
|
||||
func[] OrdinalRank d[] .
|
||||
for i to len d[] : r[] &= i
|
||||
return r[]
|
||||
.
|
||||
func[] FractionalRank d[] .
|
||||
i = 1
|
||||
while i <= len d[]
|
||||
f = i
|
||||
j = i + 1
|
||||
while j <= len d[] and d[i] = d[j]
|
||||
f += j
|
||||
j += 1
|
||||
.
|
||||
f /= (j - i)
|
||||
while i < j
|
||||
r[] &= f
|
||||
i += 1
|
||||
.
|
||||
.
|
||||
return r[]
|
||||
.
|
||||
data[] = [ 44 42 42 41 41 41 39 ]
|
||||
names$[] = [ "Solomon" "Jason" "Errol" "Garry" "Bernard" "Barry" "Stephen" ]
|
||||
#
|
||||
proc show name$ r[] .
|
||||
print name$ & " Ranking"
|
||||
for i to len names$[]
|
||||
print " " & r[i] & " - " & data[i] & " " & names$[i]
|
||||
.
|
||||
print ""
|
||||
.
|
||||
show "Standard" StandardRank data[]
|
||||
show "Modified" ModifiedRank data[]
|
||||
show "Dense" DenseRank data[]
|
||||
show "Ordinal" OrdinalRank data[]
|
||||
show "Fractional" FractionalRank data[]
|
||||
142
Task/Ranking-methods/PowerShell/ranking-methods-1.ps1
Normal file
142
Task/Ranking-methods/PowerShell/ranking-methods-1.ps1
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
function Get-Ranking
|
||||
{
|
||||
[CmdletBinding(DefaultParameterSetName="Standard")]
|
||||
[OutputType([PSCustomObject])]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
Position=0)]
|
||||
[string]
|
||||
$InputObject,
|
||||
|
||||
[Parameter(Mandatory=$false,
|
||||
ParameterSetName="Standard")]
|
||||
[switch]
|
||||
$Standard,
|
||||
|
||||
[Parameter(Mandatory=$false,
|
||||
ParameterSetName="Modified")]
|
||||
[switch]
|
||||
$Modified,
|
||||
|
||||
[Parameter(Mandatory=$false,
|
||||
ParameterSetName="Dense")]
|
||||
[switch]
|
||||
$Dense,
|
||||
|
||||
[Parameter(Mandatory=$false,
|
||||
ParameterSetName="Ordinal")]
|
||||
[switch]
|
||||
$Ordinal,
|
||||
|
||||
[Parameter(Mandatory=$false,
|
||||
ParameterSetName="Fractional")]
|
||||
[switch]
|
||||
$Fractional
|
||||
)
|
||||
|
||||
Begin
|
||||
{
|
||||
function Get-OrdinalRank ([PSCustomObject[]]$Values)
|
||||
{
|
||||
for ($i = 0; $i -lt $Values.Count; $i++)
|
||||
{
|
||||
$Values[$i].Rank = $i + 1
|
||||
}
|
||||
|
||||
$Values
|
||||
}
|
||||
|
||||
function Get-Rank ([PSCustomObject[]]$Scores)
|
||||
{
|
||||
foreach ($score in $Scores)
|
||||
{
|
||||
$score.Group | ForEach-Object {$_.Rank = $score.Rank}
|
||||
}
|
||||
|
||||
$Scores.Group
|
||||
}
|
||||
|
||||
function New-Competitor ([string]$Name, [int]$Score, [int]$Rank = 0)
|
||||
{
|
||||
[PSCustomObject]@{
|
||||
Name = $Name
|
||||
Score = $Score
|
||||
Rank = $Rank
|
||||
}
|
||||
}
|
||||
|
||||
$competitors = @()
|
||||
$scores = @()
|
||||
}
|
||||
Process
|
||||
{
|
||||
@($input) | ForEach-Object {$competitors += New-Competitor -Name $_.Split()[1] -Score $_.Split()[0]}
|
||||
}
|
||||
End
|
||||
{
|
||||
$scores = $competitors |
|
||||
Sort-Object -Property Score -Descending |
|
||||
Group-Object -Property Score |
|
||||
Select-Object -Property @{Name="Score"; Expression={[int]$_.Name}}, @{Name="Rank"; Expression={0}}, Count, Group
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName)
|
||||
{
|
||||
"Standard"
|
||||
{
|
||||
$rank = 1
|
||||
|
||||
for ($i = 0; $i -lt $scores.Count; $i++)
|
||||
{
|
||||
$scores[$i].Rank = $rank
|
||||
$rank += $scores[$i].Count
|
||||
}
|
||||
|
||||
Get-Rank $scores
|
||||
}
|
||||
"Modified"
|
||||
{
|
||||
$rank = 0
|
||||
|
||||
foreach ($score in $scores)
|
||||
{
|
||||
$rank = $score.Count + $rank
|
||||
$score.Rank = $rank
|
||||
}
|
||||
|
||||
Get-Rank $scores
|
||||
}
|
||||
"Dense"
|
||||
{
|
||||
for ($i = 0; $i -lt $scores.Count; $i++)
|
||||
{
|
||||
$scores[$i].Rank = $i + 1
|
||||
}
|
||||
|
||||
Get-Rank $scores
|
||||
}
|
||||
"Ordinal"
|
||||
{
|
||||
Get-OrdinalRank $competitors
|
||||
}
|
||||
"Fractional"
|
||||
{
|
||||
Get-OrdinalRank $competitors | Group-Object -Property Score | ForEach-Object {
|
||||
if ($_.Count -gt 1)
|
||||
{
|
||||
$rank = ($_.Group.Rank | Measure-Object -Average).Average
|
||||
|
||||
foreach ($competitor in $_.Group)
|
||||
{
|
||||
$competitor.Rank = $rank
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$competitors
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Task/Ranking-methods/PowerShell/ranking-methods-2.ps1
Normal file
1
Task/Ranking-methods/PowerShell/ranking-methods-2.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
$scores = "44 Solomon","42 Jason","42 Errol","41 Garry","41 Bernard","41 Barry","39 Stephen"
|
||||
1
Task/Ranking-methods/PowerShell/ranking-methods-3.ps1
Normal file
1
Task/Ranking-methods/PowerShell/ranking-methods-3.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
$scores | Get-Ranking -Standard
|
||||
1
Task/Ranking-methods/PowerShell/ranking-methods-4.ps1
Normal file
1
Task/Ranking-methods/PowerShell/ranking-methods-4.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
$scores | Get-Ranking -Modified
|
||||
1
Task/Ranking-methods/PowerShell/ranking-methods-5.ps1
Normal file
1
Task/Ranking-methods/PowerShell/ranking-methods-5.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
$scores | Get-Ranking -Dense
|
||||
1
Task/Ranking-methods/PowerShell/ranking-methods-6.ps1
Normal file
1
Task/Ranking-methods/PowerShell/ranking-methods-6.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
$scores | Get-Ranking -Ordinal
|
||||
1
Task/Ranking-methods/PowerShell/ranking-methods-7.ps1
Normal file
1
Task/Ranking-methods/PowerShell/ranking-methods-7.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
$scores | Get-Ranking -Fractional
|
||||
Loading…
Add table
Add a link
Reference in a new issue