🎉」 init(2025): day 1

This commit is contained in:
2025-12-01 11:25:06 +01:00
commit 6306ab23d1
52 changed files with 2012 additions and 0 deletions

1
2024/day03/.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

27
2024/day03/flake.lock generated Normal file
View File

@@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"flake": false,
"locked": {
"lastModified": 1733016324,
"narHash": "sha256-8qwPSE2g1othR1u4uP86NXxm6i7E9nHPyJX3m3lx7Q4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7e1ca67996afd8233d9033edd26e442836cc2ad6",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-24.05",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

29
2024/day03/flake.nix Normal file
View File

@@ -0,0 +1,29 @@
{
description = "a minimal test development environment for ruby";
inputs = {
nixpkgs = {
url = "nixpkgs/nixos-24.05";
flake = false;
};
};
outputs = inputs@{ nixpkgs, ... }:
{
devShell = {
x86_64-linux = let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in pkgs.mkShell {
packages = with pkgs; [
gcc ruby
];
shellHook = ''
export CC=gcc
echo -e "\x1B[0;33mentering ruby minimalist test development environment...\x1B[0m"
'';
};
};
};
}

24
2024/day03/part1.rb Normal file
View File

@@ -0,0 +1,24 @@
if File.exists?("input.txt")
file = File.open("input.txt")
file_data = file.read
file.close
else
file_data = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"
end
#puts file_data
sane_data = file_data.scan(/mul\(\d+,\d+\)/)
#puts sane_data.inspect
numbers = sane_data.map do |item|
item.scan(/\d+/).map(&:to_i)
end
#puts numbers.inspect
result = 0
for mul in numbers do
result = result + mul[0] * mul[1]
end
puts result

24
2024/day03/part2.rb Normal file
View File

@@ -0,0 +1,24 @@
if File.exists?("input.txt")
file = File.open("input.txt")
file_data = file.read
file.close
else
file_data = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))"
end
#puts file_data
sane_data = file_data.gsub(/don\'t\(\).*?do\(\)/m, "").scan(/mul\(\d+,\d+\)/)
#puts sane_data.inspect
numbers = sane_data.map do |item|
item.scan(/\d+/).map(&:to_i)
end
#puts numbers.inspect
result = 0
for mul in numbers do
result = result + mul[0] * mul[1]
end
puts result