Compare commits

..

2 Commits

Author SHA1 Message Date
8f5087ac36 2024-01,02 2025-11-16 17:47:14 -08:00
68d81019e8 scaffold 2024 2025-11-14 07:54:02 -08:00
65 changed files with 369 additions and 4447 deletions

View File

@@ -6,7 +6,7 @@ Advent Of Code solutions for 2015 using C99. Builds and runs on macOS, Linux, an
Be sure to clone the top project with its submodules: Be sure to clone the top project with its submodules:
git clone --recurse-submodules https://git.burkey.co/eburk/aoc git clone --recurse-submodules https://git.burkey.co/eburk/advent-of-code
This project relies on several BSD extensions to the stdlib. OpenBSD and macOS users should be able to build the project out of the box. Linux users will need `libbsd` installed. The package is called `libbsd-dev` on Debian-based systems. This project relies on several BSD extensions to the stdlib. OpenBSD and macOS users should be able to build the project out of the box. Linux users will need `libbsd` installed. The package is called `libbsd-dev` on Debian-based systems.

View File

@@ -1,3 +1,3 @@
# 2016 # 2016
Go Solutions in Go

6
2024/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
.idea

View File

@@ -1,42 +0,0 @@
package aoc
import "core:fmt"
import "core:math"
import "core:sort"
import "core:strconv"
import "core:strings"
day01 :: proc() {
input := slurp_lines("input/01")
defer delete(input)
left := make([dynamic]int, 0, len(input))
right := make([dynamic]int, 0, len(input))
for line in input {
sp := strings.split(line, " ")
a, _ := strconv.parse_int(sp[0])
b, _ := strconv.parse_int(sp[1])
append(&left, a)
append(&right, b)
delete(sp)
}
sort.quick_sort(left[:])
sort.quick_sort(right[:])
p1: int
for i in 0 ..< len(left) {
p1 += math.abs(left[i] - right[i])
}
fmt.println(p1)
count: map[int]int
for r in right {
count[r] += 1
}
p2: int
for l in left {
p2 += l * count[l]
}
fmt.println(p2)
}

View File

@@ -1,14 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day02 :: proc() {
input := slurp_lines("input/02")
defer delete(input)
for line in input {
}
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day03 :: proc() {
input := slurp_lines("input/03")
defer delete(input)
fmt.println("Solution for Day 03 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day04 :: proc() {
input := slurp_lines("input/04")
defer delete(input)
fmt.println("Solution for Day 04 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day05 :: proc() {
input := slurp_lines("input/05")
defer delete(input)
fmt.println("Solution for Day 05 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day06 :: proc() {
input := slurp_lines("input/06")
defer delete(input)
fmt.println("Solution for Day 06 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day07 :: proc() {
input := slurp_lines("input/07")
defer delete(input)
fmt.println("Solution for Day 07 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day08 :: proc() {
input := slurp_lines("input/08")
defer delete(input)
fmt.println("Solution for Day 08 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day09 :: proc() {
input := slurp_lines("input/09")
defer delete(input)
fmt.println("Solution for Day 09 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day10 :: proc() {
input := slurp_lines("input/10")
defer delete(input)
fmt.println("Solution for Day 10 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day11 :: proc() {
input := slurp_lines("input/11")
defer delete(input)
fmt.println("Solution for Day 11 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day12 :: proc() {
input := slurp_lines("input/12")
defer delete(input)
fmt.println("Solution for Day 12 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day13 :: proc() {
input := slurp_lines("input/13")
defer delete(input)
fmt.println("Solution for Day 13 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day14 :: proc() {
input := slurp_lines("input/14")
defer delete(input)
fmt.println("Solution for Day 14 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day15 :: proc() {
input := slurp_lines("input/15")
defer delete(input)
fmt.println("Solution for Day 15 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day16 :: proc() {
input := slurp_lines("input/16")
defer delete(input)
fmt.println("Solution for Day 16 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day17 :: proc() {
input := slurp_lines("input/17")
defer delete(input)
fmt.println("Solution for Day 17 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day18 :: proc() {
input := slurp_lines("input/18")
defer delete(input)
fmt.println("Solution for Day 18 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day19 :: proc() {
input := slurp_lines("input/19")
defer delete(input)
fmt.println("Solution for Day 19 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day20 :: proc() {
input := slurp_lines("input/20")
defer delete(input)
fmt.println("Solution for Day 20 is not implemented yet")
}

18
2024/2024.csproj Normal file
View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>_2024</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- Copy input files/folders to the output directory so File.ReadAllText("input/..") works at runtime -->
<ItemGroup>
<None Update="input/**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

16
2024/2024.sln Normal file
View File

@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2024", "2024.csproj", "{F018A604-9FAE-421D-818D-5C6F7AB07FC4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F018A604-9FAE-421D-818D-5C6F7AB07FC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F018A604-9FAE-421D-818D-5C6F7AB07FC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F018A604-9FAE-421D-818D-5C6F7AB07FC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F018A604-9FAE-421D-818D-5C6F7AB07FC4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day21 :: proc() {
input := slurp_lines("input/21")
defer delete(input)
fmt.println("Solution for Day 21 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day22 :: proc() {
input := slurp_lines("input/22")
defer delete(input)
fmt.println("Solution for Day 22 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day23 :: proc() {
input := slurp_lines("input/23")
defer delete(input)
fmt.println("Solution for Day 23 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day24 :: proc() {
input := slurp_lines("input/24")
defer delete(input)
fmt.println("Solution for Day 24 is not implemented yet")
}

View File

@@ -1,11 +0,0 @@
package aoc
import "core:fmt"
import "core:log"
import "core:os"
day25 :: proc() {
input := slurp_lines("input/25")
defer delete(input)
fmt.println("Solution for Day 25 is not implemented yet")
}

34
2024/Day01.cs Normal file
View File

@@ -0,0 +1,34 @@
namespace _2024;
public class Day01 : ISolution {
public void Run() {
// Read all lines from the input file
var lines = File.ReadAllLines("input/01");
// Two lists to hold the first and second integers per line
var left = new List<int>();
var right = new List<int>();
foreach (var line in lines) {
if (string.IsNullOrWhiteSpace(line)) continue;
var parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2) {
Console.WriteLine("Bad parse");
return;
}
if (int.TryParse(parts[0], out var a) && int.TryParse(parts[1], out var b)) {
left.Add(a);
right.Add(b);
}
}
var leftSorted = left.OrderBy(x => x).ToList();
var rightSorted = right.OrderBy(x => x).ToList();
Console.WriteLine(leftSorted.Select((t, i) => Math.Abs(t - rightSorted[i])).Sum());
Console.WriteLine(left.Sum(i => right.Count(x => x == i) * i));
}
}

24
2024/Day02.cs Normal file
View File

@@ -0,0 +1,24 @@
namespace _2024;
public class Day02 : ISolution
{
public void Run()
{
var input = File.ReadAllText("input/02")
.Split('\n')
.Select(line => line.Split(' ')
.Select(int.Parse)
.ToList())
.ToList();
Console.WriteLine(PartOne(input));
}
private static int PartOne(List<List<int>> list) {
return list.Select(line => Enumerable.Range(1, Math.Max(0, line.Count - 1))
.Select(i => line[i] - line[i - 1])
.ToList())
.Where(diffs => diffs.All(d => d > 0) || diffs.All(d => d < 0))
.Count(diffs => !diffs.Any(d => Math.Abs(d) is < 1 or > 3));
}
}

10
2024/Day03.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day03 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/03");
Console.WriteLine("The solution for day 03 is not implmented yet");
}
}

10
2024/Day04.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day04 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/04");
Console.WriteLine("The solution for day 04 is not implmented yet");
}
}

10
2024/Day05.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day05 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/05");
Console.WriteLine("The solution for day 05 is not implmented yet");
}
}

10
2024/Day06.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day06 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/06");
Console.WriteLine("The solution for day 06 is not implmented yet");
}
}

10
2024/Day07.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day07 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/07");
Console.WriteLine("The solution for day 07 is not implmented yet");
}
}

10
2024/Day08.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day08 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/08");
Console.WriteLine("The solution for day 08 is not implmented yet");
}
}

10
2024/Day09.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day09 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/09");
Console.WriteLine("The solution for day 09 is not implmented yet");
}
}

10
2024/Day10.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day10 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/10");
Console.WriteLine("The solution for day 10 is not implmented yet");
}
}

10
2024/Day11.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day11 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/11");
Console.WriteLine("The solution for day 11 is not implmented yet");
}
}

10
2024/Day12.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day12 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/12");
Console.WriteLine("The solution for day 12 is not implmented yet");
}
}

10
2024/Day13.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day13 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/13");
Console.WriteLine("The solution for day 13 is not implmented yet");
}
}

10
2024/Day14.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day14 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/14");
Console.WriteLine("The solution for day 14 is not implmented yet");
}
}

10
2024/Day15.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day15 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/15");
Console.WriteLine("The solution for day 15 is not implmented yet");
}
}

10
2024/Day16.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day16 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/16");
Console.WriteLine("The solution for day 16 is not implmented yet");
}
}

10
2024/Day17.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day17 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/17");
Console.WriteLine("The solution for day 17 is not implmented yet");
}
}

10
2024/Day18.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day18 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/18");
Console.WriteLine("The solution for day 18 is not implmented yet");
}
}

10
2024/Day19.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day19 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/19");
Console.WriteLine("The solution for day 19 is not implmented yet");
}
}

10
2024/Day20.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day20 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/20");
Console.WriteLine("The solution for day 20 is not implmented yet");
}
}

10
2024/Day21.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day21 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/21");
Console.WriteLine("The solution for day 21 is not implmented yet");
}
}

10
2024/Day22.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day22 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/22");
Console.WriteLine("The solution for day 22 is not implmented yet");
}
}

10
2024/Day23.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day23 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/23");
Console.WriteLine("The solution for day 23 is not implmented yet");
}
}

10
2024/Day24.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day24 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/24");
Console.WriteLine("The solution for day 24 is not implmented yet");
}
}

10
2024/Day25.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace _2024;
public class Day25 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/25");
Console.WriteLine("The solution for day 25 is not implmented yet");
}
}

31
2024/Program.cs Normal file
View File

@@ -0,0 +1,31 @@
using _2024;
Console.Write("Enter a day: ");
var input = Console.ReadLine();
if (!int.TryParse(input, out var day)) {
Console.Error.WriteLine("Error: input is not a valid integer.");
Environment.Exit(1);
}
if (day is < 1 or > 25) {
Console.Error.WriteLine("Error: day must be between 1 and 25.");
Environment.Exit(1);
}
var dayStr = day.ToString();
if (day < 10) {
dayStr = "0" + dayStr;
}
// Instantiate an ISolution named 's' based on the day, e.g., Day02 for day == 2, then run it
var typeName = $"_2024.Day{dayStr}";
var type = typeof(ISolution).Assembly.GetType(typeName);
if (type is null || !typeof(ISolution).IsAssignableFrom(type)) {
Console.Error.WriteLine($"Error: could not find a solution class for day {dayStr}.");
Environment.Exit(1);
}
var s = (ISolution)Activator.CreateInstance(type)!;
s.Run();

View File

@@ -1,3 +1,3 @@
# 2024 # 2024
Odin Solutions in C# using dotnet core 9

5
2024/Solution.cs Normal file
View File

@@ -0,0 +1,5 @@
namespace _2024;
public interface ISolution {
void Run();
}

View File

@@ -1,22 +0,0 @@
package aoc
import "core:log"
import "core:os"
import "core:strings"
Pair :: struct($T: typeid) {
a: $T,
b: $T,
}
slurp_file :: proc(path: string) -> string {
input, ok := os.read_entire_file(path)
if !ok {
log.fatal("Failed to read input")
}
return string(input)
}
slurp_lines :: proc(path: string) -> []string {
return strings.split_lines(slurp_file(path))
}

View File

@@ -1,46 +0,0 @@
package aoc
import "core:strconv"
import "core:fmt"
import "core:os"
main :: proc() {
buf := [4]u8{}
fmt.print("Enter a day between 1 and 25: ")
sz, err := os.read(os.stdin, buf[:])
if err != nil {
fmt.println(err)
panic("read failure")
}
day, _ := strconv.parse_int(string(buf[:sz]))
switch(day) {
case 1: day01()
case 2: day02()
case 3: day03()
case 4: day04()
case 5: day05()
case 6: day06()
case 7: day07()
case 8: day08()
case 9: day09()
case 10: day10()
case 11: day11()
case 12: day12()
case 13: day13()
case 14: day14()
case 15: day15()
case 16: day16()
case 17: day17()
case 18: day18()
case 19: day19()
case 20: day20()
case 21: day21()
case 22: day22()
case 23: day23()
case 24: day24()
case 25: day25()
}
}

View File

@@ -1 +0,0 @@
ruby 3.4.7

View File

@@ -1,25 +0,0 @@
input = File.readlines('input/01')
pos = 50
p1 = 0
p2 = 0
input.each do |line|
dir = line[0]
n = line[1..].to_i
(1..n).each do
if dir == 'R'
pos = (pos - 1 + 100) % 100
else
pos = (pos + 1) % 100
end
if pos.zero?
p2 += 1
end
end
if pos.zero?
p1 += 1
end
end
puts p1
puts p2

View File

@@ -1,3 +0,0 @@
# 2025
Ruby 3.4.7

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,6 @@ Advent Of Code solutions using a different language each year
2023: TBD 2023: TBD
2024: Odin 2024: C#
2025: Ruby 2025: TBD