Compare commits

..

4 Commits

Author SHA1 Message Date
b6f0b50ca2 wip 2025-12-06 06:19:55 -08:00
064dc676cd 2025-01 2025-12-01 08:34:10 -08:00
517dede130 2024 rescaffold 2025-11-25 13:12:19 -08:00
ca26da6b3b start 2024, 2024-01 2025-11-25 11:22:03 -08:00
68 changed files with 4529 additions and 369 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:
git clone --recurse-submodules https://git.burkey.co/eburk/advent-of-code
git clone --recurse-submodules https://git.burkey.co/eburk/aoc
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
Solutions in Go
Go

6
2024/.gitignore vendored
View File

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

42
2024/01.odin Normal file
View File

@@ -0,0 +1,42 @@
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)
}

65
2024/02.odin Normal file
View File

@@ -0,0 +1,65 @@
package aoc
import "core:fmt"
import "core:math"
import "core:strconv"
import "core:strings"
day02 :: proc() {
input := slurp_lines("input/02")
defer delete(input)
p1: int
p2: int
for line in input {
sp := strings.split(line, " ")
report := make([dynamic]int, 0, len(sp))
for s in sp {
i, _ := strconv.parse_int(s)
append(&report, i)
}
if validate(report) {
p1 += 1
}
p2_valid := true
for i := 0; i < len(report); i += 1 {
cpy := make([dynamic]int, 0, len(report))
copy(cpy[:], report[:])
ordered_remove(&cpy, i)
if !validate(cpy) {
p2_valid = false
delete(cpy)
break
}
delete(cpy)
}
if p2_valid {
p2 += 1
}
delete(report)
}
fmt.println(p1)
fmt.println(p2)
}
validate :: proc(report: [dynamic]int) -> bool {
increasing := false
if report[0] < report[1] {
increasing = true
}
for i := 1; i < len(report); i += 1 {
if increasing && report[i - 1] > report[i] {
return false
}
if !increasing && report[i - 1] < report[i] {
return false
}
diff := math.abs(report[i - 1] - report[i])
if diff < 1 || diff > 3 {
return false
}
}
return true
}

11
2024/03.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/04.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/05.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/06.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/07.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/08.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/09.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/10.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/11.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/12.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/13.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/14.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/15.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/16.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/17.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/18.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/19.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/20.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

BIN
2024/2024 Executable file

Binary file not shown.

View File

@@ -1,18 +0,0 @@
<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>

View File

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

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

11
2024/21.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/22.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/23.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/24.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

11
2024/25.odin Normal file
View File

@@ -0,0 +1,11 @@
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")
}

View File

@@ -1,34 +0,0 @@
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));
}
}

View File

@@ -1,24 +0,0 @@
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));
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,10 +0,0 @@
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");
}
}

View File

@@ -1,31 +0,0 @@
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
Solutions in C# using dotnet core 9
Odin

View File

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

22
2024/aoc.odin Normal file
View File

@@ -0,0 +1,22 @@
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))
}

46
2024/main.odin Normal file
View File

@@ -0,0 +1,46 @@
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()
}
}

1
2025/.tool-versions Normal file
View File

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

25
2025/01.rb Normal file
View File

@@ -0,0 +1,25 @@
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

30
2025/02.rb Normal file
View File

@@ -0,0 +1,30 @@
def valid(str, p2)
(1..str.size / 2).each do |i|
sub = str[0, i]
return false if str[i..] == sub
if p2 && str.size > 2
chunks = str[i..].chars.each_slice(sub.size).map(&:join)
puts chunks
end
end
true
end
input = File.read('input/test').split(',')
p1 = 0
p2 = 0
input.each do |line|
sp = line.split('-')
a = sp[0].to_i
b = sp[1].to_i
(a..b).each do |i|
p1 += i unless valid(i.to_s, false)
p2 += i unless valid(i.to_s, true)
end
end
puts p1
puts p2

3
2025/README.md Normal file
View File

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

4036
2025/input/01 Normal file

File diff suppressed because it is too large Load Diff

1
2025/input/02 Normal file
View File

@@ -0,0 +1 @@
9191896883-9191940271,457499-518693,4952-6512,960-1219,882220-1039699,2694-3465,3818-4790,166124487-166225167,759713819-759869448,4821434-4881387,7271-9983,1182154-1266413,810784-881078,802-958,1288-1491,45169-59445,25035-29864,379542-433637,287-398,75872077-75913335,653953-689335,168872-217692,91-113,475-590,592-770,310876-346156,2214325-2229214,85977-112721,51466993-51620441,8838997-8982991,534003-610353,32397-42770,17-27,68666227-68701396,1826294188-1826476065,1649-2195,141065204-141208529,7437352-7611438,10216-13989,33-44,1-16,49-74,60646-73921,701379-808878

View File

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