Created
October 30, 2025 01:48
-
-
Save Anticubex/ee820a9fd618293ca99232f03cf4a0fc to your computer and use it in GitHub Desktop.
Uiua Ranked Pairs Voting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Ranked Pairs Voting | |
| # Uiua 0.18.0-dev.2 | |
| EnumerateRows ← ≡⌟˜⨂ | |
| GetRankedPairs ← ( | |
| ⧅>2⇡ | |
| ⤚≡⌟[⟜-⊃/+⧻♭>∩⌟(≡⊚⌕)°⊟] | |
| ∩⌞▽⊸(¬/=⍉) # Filter ties | |
| ≡(⨬∘∩⇌⊸(>°⊟)) | |
| ⊏⍖⊢⍉ | |
| ) | |
| CausesCycle ← ( | |
| ˜⊙(∩¤°˜⊟) # AdjMat Frontier Visited | |
| ⍢(⟜⊃(⊚/↥˜⊏)⋅⊂|¬↥⋅⊃(=0⧻|/↥∊)) | |
| ≠0⧻⋅⊙◌ | |
| ) | |
| AdjancencyMatrix ← ∧(⨬⍜⊡⋅1◌◡CausesCycle) | |
| # Winners must have outgoing | |
| # but no ingoing edges | |
| Winners ← ⊚׬∩/↥⟜⍉ | |
| RankedPairs ← ⊏⊸( | |
| ⊃⋅⧻EnumerateRows | |
| ⊃GetRankedPairs(↯[⟜∘]⊙0) | |
| AdjancencyMatrix | |
| Winners | |
| ) | |
| # Test 1 | |
| # {"Alice" "Bob" "Charlie"} | |
| # ⍥₃{"Alice" "Bob" "Charlie"} | |
| # ⊂⍥₂{"Bob" "Charlie" "Alice"} | |
| # ⊂⍥₄{"Charlie" "Alice""Bob"} | |
| # RankedPairs# Charlie | |
| # Test 2 | |
| {"Alice" "Bob" "Charlie" "David"} | |
| [{"David" "Bob" "Charlie" "Alice"} | |
| {"Bob" "Alice" "Charlie" "David"}] | |
| RankedPairs # Bob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment