From 182c71a2390b728fee51f235560ded1a6f14a797 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 15 Jun 2022 23:08:35 +0200 Subject: [PATCH] Shorten vote --- vote.apln | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/vote.apln b/vote.apln index 709a057..d40604b 100644 --- a/vote.apln +++ b/vote.apln @@ -1,26 +1,11 @@ :Namespace vote Ballot←{ - voter←{ - ⍺:?⍨⍵ - n←?⍵ - (⍳n)@(n↑?⍨⍵)⊢⍵⍴0 - } - ,⍨∘≢⌸(⍺>0)voter¨⍵⍴|⍺ + ,⍨∘≢⌸0⌈(n?¨⍵⍴n)-(⍺<0)×1-⍨?⍵⍴n←|⍺ } IRV←{ - ⍵ IRVruns (⊂∘⍋⌷⊢)⍵[;1]{⍺,+⌿⍵}⌸⍨1⍳⍨¨⍵[;2] - } - IRVruns←{ - eliminate←{ - ⍝ A loser rating of 0 is worst, - ⍝ so give it a large value - res←⍵[;1],⍪↓⍉0@⍺⊢⍉r-r>⍤1 0⊢(⌈⌿,r)@(=∘0)(r←↑⍵[;2])[;⍺] - ⍝ remove the blank votes now - res⌿⍨~∨/res⍷⍨⊂0⍴⍨⊃⌽⍴r - } - 1=≢⍵:⊃⍵ ⍝ We have a winner - losers←⍵[(⍸⌊⌿⍷⊢)⍵[;2];1] - ⍵=⍥≢losers:⊂⍵ ⍝ it was a tie - (⊂⍵),IRV⊃eliminate⌿losers,⊂⍺ ⍝ Calculate next rounds with the loses removed + ⍵{ + 1=≢⍵:⊃⍵ ⋄ ⍵=⍥≢l←⍵[(⍸⌊⌿⍷⊢)⍵[;2];1]:⊂⍵ + (⊂⍵),IRV⊃{u⌿⍨~∨/(⊂0⍴⍨⊃⌽⍴r)⍷u←⍵[;1],⍪↓⍉0@⍺⊢⍉r-r>⍤1 0⊢(⌈⌿,r)@(=∘0)(r←↑⍵[;2])[;⍺]}⌿l,⊂⍺ + }(⊂∘⍋⌷⊢)⍵[;1]{⍺,+⌿⍵}⌸⍨1⍳⍨¨⍵[;2] } :EndNamespace -- 2.45.2