mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 16:23:00 +00:00
26 lines
633 B
Python
26 lines
633 B
Python
import itertools
|
|
import random
|
|
from typing import Sequence
|
|
|
|
from ..dav_common import dav_get_file
|
|
|
|
|
|
async def get_loesungswort() -> str:
|
|
fp = await dav_get_file("loesungswort.txt")
|
|
return fp.read().decode("utf8").strip()
|
|
|
|
|
|
|
|
async def set_length(seq: Sequence, length: int) -> list:
|
|
# `seq` unendlich wiederholen
|
|
infinite = itertools.cycle(seq)
|
|
# Die ersten `length` einträge nehmen
|
|
return list(itertools.islice(infinite, length))
|
|
|
|
|
|
async def shuffle(seq: Sequence) -> list:
|
|
# Zufallsgenerator
|
|
rnd = random.Random(await get_loesungswort())
|
|
|
|
# Elemente mischen
|
|
return rnd.sample(seq, len(seq))
|