-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_solution.ps1
More file actions
146 lines (131 loc) · 3.56 KB
/
create_solution.ps1
File metadata and controls
146 lines (131 loc) · 3.56 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Year
)
if(Test-Path (Join-Path . $Year)){
Write-Error "[⚠] Project already exists. Aborting..."
return
}
Write-Host "[>] Creating folder $Year..."
New-Item "$Year" -ItemType Directory | Out-Null
Push-Location $Year
Write-Host "[>] Creating solution and respective project..."
dotnet new console | Out-Null
dotnet new sln | Out-Null
dotnet sln add . | Out-Null
Write-Host "[>] Removing <RootNamespace> from $Year.csproj..."
(Get-Content ".\$($Year).csproj") | ForEach-Object {
if($_ -notlike '*RootNamespace*'){
$_
}
} | Set-Content -Path ".\$Year.csproj"
Write-Host "[>] Adding Program.cs..."
Remove-Item 'Program.cs' # This was added by the 'dotnet new console' step above
$programContents =
@"
using AdventOfCode$Year.Day01;
using AdventOfCode$Year.Day02;
using AdventOfCode$Year.Day03;
using AdventOfCode$Year.Day04;
using AdventOfCode$Year.Day05;
using AdventOfCode$Year.Day06;
using AdventOfCode$Year.Day07;
using AdventOfCode$Year.Day08;
using AdventOfCode$Year.Day09;
using AdventOfCode$Year.Day10;
using AdventOfCode$Year.Day11;
using AdventOfCode$Year.Day12;
using AdventOfCode$Year.Day13;
using AdventOfCode$Year.Day14;
using AdventOfCode$Year.Day15;
using AdventOfCode$Year.Day16;
using AdventOfCode$Year.Day17;
using AdventOfCode$Year.Day18;
using AdventOfCode$Year.Day19;
using AdventOfCode$Year.Day20;
using AdventOfCode$Year.Day21;
using AdventOfCode$Year.Day22;
using AdventOfCode$Year.Day23;
using AdventOfCode$Year.Day24;
using AdventOfCode$Year.Day25;
Day01.Execute();
Day02.Execute();
Day03.Execute();
Day04.Execute();
Day05.Execute();
Day06.Execute();
Day07.Execute();
Day08.Execute();
Day09.Execute();
Day10.Execute();
Day11.Execute();
Day12.Execute();
Day13.Execute();
Day14.Execute();
Day15.Execute();
Day16.Execute();
Day17.Execute();
Day18.Execute();
Day19.Execute();
Day20.Execute();
Day21.Execute();
Day22.Execute();
Day23.Execute();
Day24.Execute();
Day25.Execute();
"@
Set-Content -Path "Program.cs" -Value $programContents -NoNewLine
Write-Host "[>] Creating dummy implementations for each day..."
foreach($day in 1..25)
{
$formatedDay = '{0:d2}' -f $day
New-Item "day$formatedDay" -ItemType Directory | Out-Null
Push-Location "day$formatedDay"
$classContents =
@"
namespace AdventOfCode$Year.Day$formatedDay;
public static class Day$formatedDay
{
private static List<string> ParseInput(StringReader sr){
using(sr)
{
List<string> input = [];
string? line = sr?.ReadLine();
while (line is not null)
{
if (line != string.Empty)
{
input.Add(line);
}
line = sr?.ReadLine();
}
return input;
}
}
private static int Part1(int sum)
{
return sum;
}
private static int Part2(int sum)
{
return sum;
}
public static void Execute()
{
int sum = 0;
using StringReader? sr = new(File.ReadAllText("./day$formatedDay/input.txt"));
List<string> input = ParseInput(sr);
Console.WriteLine($"[AoC $Year - Day $formatedDay - Part 1] Result: {Part1(sum)}");
Console.WriteLine($"[AoC $Year - Day $formatedDay - Part 2] Result: {Part2(sum)}");
}
}
"@
Set-Content -Path "Day$formatedDay.cs" -Value $classContents -NoNewLine
New-Item input.txt | Out-Null
New-Item problem.txt | Out-Null
Pop-Location
}
Write-Host "[>] Compiliing and running the new project..."
dotnet run
Write-Host "[>] Done"
Pop-Location