Enter Content と思われる予備校の開催する合格祝賀会において一番大きな巨大数を構成できた参加者が勝ちのゲームで、ルールは次の通り。
Last active
March 23, 2024 18:28
-
-
Save halka9000stg/0896309def1cb9be64bab863c1a88485 to your computer and use it in GitHub Desktop.
CelebrationElection Math
This file contains 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
import "dart:math"; | |
void main(){ | |
final int voterCount = 30; | |
final int maxVote = 100; | |
final int sampleCount = 7; | |
for(_ in Iterable<int>generate(sampleCount, (int i) => i)){ | |
print(celebrationElectionSample(voterCount, maxVote)); | |
} | |
} | |
Iterable<int> celebrationElectionSample(int voterCount, int maxVote, [Random? r]) => celebrationElect(Iterable<int>.generate(voterCount, (_) => (r ?? Random()).nextInt(maxVote))); | |
Iterable<int> celebrationElect(Iterable<int> votes, {int electCount = 4, int cutbackMargin = 11}) => _celebrationElect(votes..sort(), electCount: electCount, cutbackMargin: cutbackMargin); | |
Iterable<int> _celebrationElect(Iterable<int> votes, {int electCount = 4, int cutbackMargin = 11}) => votes.where((int v) => v < Iterable<(int, int)>.generate(votes.length - 1, (int i) => (votes[i + 1], votes[i])).where(((int, int) e) => e.$1 - e.$2 >= cutbackMargin).map<int>(((int, int) e) => e.$1).fold<int>(votes.fold<int>(0, (int prev, int curr) => max<int>(prev, curr) + 1), (int prev, int curr) => min<int>(prev, curr))).reversed.take(electCount).reversed; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment