-
Notifications
You must be signed in to change notification settings - Fork 0
/
wichteln.ps1
49 lines (38 loc) · 1.5 KB
/
wichteln.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function Get-RandomWichtelAssignment {
param (
[array]$participants,
[array]$couples = @()
)
$wichtelParticipants = $participants.Clone()
do {
$shuffledParticipants = $wichtelParticipants | Get-Random -Count $participants.Count
$isValid = $true
$wichtelAssignment = @{}
for ($i = 0; $i -lt $participants.Count; $i++) {
$gifter = $participants[$i]
$presentee = $shuffledParticipants[$i]
# import couples or other exclude combinations from input file "excluding.txt"
# unwanted combinations (2 names) are noted as "Person1 & Person2"
if ($couples -contains "$gifter & $presentee" -or $couples -contains "$presentee & $gifter") {
$isValid = $false
break
}
$wichtelAssignment[$gifter] = $presentee
if ($gifter -eq $presentee) {
$isValid = $false
break
}
}
}
while (!$isValid)
return $wichtelAssignment
}
# import participants via inputfile "participants.txt"
$participants = Get-Content -Path "input/participants.txt"
# import couples or or other excludes combinations via inputfile "excluding.txt"
$couples = Get-Content -Path "input/excluding.txt"
$assignment = Get-RandomWichtelAssignment -participants $participants -couples $couples
foreach ($gifter in $assignment.Keys) {
$presentee = $assignment[$gifter]
Write-Host "$gifter beschenkt $presentee"
}