Skip to content

Commit

Permalink
AoC21: Remove input files
Browse files Browse the repository at this point in the history
  • Loading branch information
guerinoni committed Dec 10, 2024
1 parent 93827fe commit 0dfa6b4
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2,088 deletions.
14 changes: 14 additions & 0 deletions advent-of-code-2021/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Advent of Code 2021

## Run

In order to have all thing working, put in files under `./src/testdata` your input files.

```zsh
zig run ./src/main.zig
```

If you want to check implementation with test

```zsh
zig ./src/day01.zig
```

If you don't have a rust environment you can create as follow with different tools.

### Devbox
Expand Down
14 changes: 14 additions & 0 deletions advent-of-code-2021/devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.7/.schema/devbox.schema.json",
"packages": ["[email protected]"],
"shell": {
"init_hook": [
"echo 'Welcome to devbox!' > /dev/null"
],
"scripts": {
"test": [
"echo \"Error: no test specified\" && exit 1"
]
}
}
}
69 changes: 69 additions & 0 deletions advent-of-code-2021/devbox.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"lockfile_version": "1",
"packages": {
"[email protected]": {
"last_modified": "2024-11-28T07:51:56Z",
"resolved": "github:NixOS/nixpkgs/226216574ada4c3ecefcbbec41f39ce4655f78ef#zig",
"source": "devbox-search",
"version": "0.13.0",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/hghrph0i4b5dszz2zpimwsspm9gcf577-zig-0.13.0",
"default": true
},
{
"name": "doc",
"path": "/nix/store/axnrhkixdyhpbnmhhjqf1f7ll352c9c0-zig-0.13.0-doc"
}
],
"store_path": "/nix/store/hghrph0i4b5dszz2zpimwsspm9gcf577-zig-0.13.0"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/b382vhh6snxwj856jzqnv3gyzilmajck-zig-0.13.0",
"default": true
},
{
"name": "doc",
"path": "/nix/store/s2b2p0x8zlma1p9ia24axv81iva9c58y-zig-0.13.0-doc"
}
],
"store_path": "/nix/store/b382vhh6snxwj856jzqnv3gyzilmajck-zig-0.13.0"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/nij1rb87n0fyw0chdv2pfrgz9daidsmz-zig-0.13.0",
"default": true
},
{
"name": "doc",
"path": "/nix/store/iwrxi2xd2j19zrsw8drm37ya765h71vl-zig-0.13.0-doc"
}
],
"store_path": "/nix/store/nij1rb87n0fyw0chdv2pfrgz9daidsmz-zig-0.13.0"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/j9sp79vdhz4l6lfnvzhvcprhar803zr3-zig-0.13.0",
"default": true
},
{
"name": "doc",
"path": "/nix/store/z8y8cwy81viw4n0mmf647mvk8ni8wip8-zig-0.13.0-doc"
}
],
"store_path": "/nix/store/j9sp79vdhz4l6lfnvzhvcprhar803zr3-zig-0.13.0"
}
}
}
}
}
93 changes: 5 additions & 88 deletions advent-of-code-2021/src/day01.zig
Original file line number Diff line number Diff line change
@@ -1,84 +1,4 @@
// --- Day 1: Sonar Sweep ---

// You're minding your own business on a ship at sea when the overboard alarm goes off! You rush to see if you can help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean!

// Before you know it, you're inside a submarine the Elves keep ready for situations like this. It's covered in Christmas lights (because of course it is), and it even has an experimental antenna that should be able to track the keys if you can boost its signal strength high enough; there's a little meter that indicates the antenna's signal strength by displaying 0-50 stars.

// Your instincts tell you that in order to save Christmas, you'll need to get all fifty stars by December 25th.

// Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

// As the submarine drops below the surface of the ocean, it automatically performs a sonar sweep of the nearby sea floor. On a small screen, the sonar sweep report (your puzzle input) appears: each line is a measurement of the sea floor depth as the sweep looks further and further away from the submarine.

// For example, suppose you had the following report:

// 199
// 200
// 208
// 210
// 200
// 207
// 240
// 269
// 260
// 263

// This report indicates that, scanning outward from the submarine, the sonar sweep found depths of 199, 200, 208, 210, and so on.

// The first order of business is to figure out how quickly the depth increases, just so you know what you're dealing with - you never know if the keys will get carried into deeper water by an ocean current or a fish or something.

// To do this, count the number of times a depth measurement increases from the previous measurement. (There is no measurement before the first measurement.) In the example above, the changes are as follows:

// 199 (N/A - no previous measurement)
// 200 (increased)
// 208 (increased)
// 210 (increased)
// 200 (decreased)
// 207 (increased)
// 240 (increased)
// 269 (increased)
// 260 (decreased)
// 263 (increased)

// In this example, there are 7 measurements that are larger than the previous measurement.

// How many measurements are larger than the previous measurement?

// --- Part Two ---

// Considering every single measurement isn't as useful as you expected: there's just too much noise in the data.

// Instead, consider sums of a three-measurement sliding window. Again considering the above example:

// 199 A
// 200 A B
// 208 A B C
// 210 B C D
// 200 E C D
// 207 E F D
// 240 E F G
// 269 F G H
// 260 G H
// 263 H

// Start by comparing the first and second three-measurement windows. The measurements in the first window are marked A (199, 200, 208); their sum is 199 + 200 + 208 = 607. The second window is marked B (200, 208, 210); its sum is 618. The sum of measurements in the second window is larger than the sum of the first, so this first comparison increased.

// Your goal now is to count the number of times the sum of measurements in this sliding window increases from the previous sum. So, compare A with B, then compare B with C, then C with D, and so on. Stop when there aren't enough measurements left to create a new three-measurement sum.

// In the above example, the sum of each three-measurement window is as follows:

// A: 607 (N/A - no previous sum)
// B: 618 (increased)
// C: 618 (no change)
// D: 617 (decreased)
// E: 647 (increased)
// F: 716 (increased)
// G: 769 (increased)
// H: 792 (increased)

// In this example, there are 5 sums that are larger than the previous sum.

// Consider sums of a three-measurement sliding window. How many sums are larger than the previous sum?
// https://adventofcode.com/2021/day/1

const std = @import("std");

Expand All @@ -88,6 +8,10 @@ const Result = struct {
};

pub fn solve(input: []const u8) !Result {
if (input.len == 0) {
return Result{ .part1 = 0, .part2 = 0 };
}

var lines = std.mem.tokenize(u8, input, "\n");

var part1: u32 = 0;
Expand Down Expand Up @@ -140,10 +64,3 @@ test "sample" {
try expect(result.part1 == 7);
try expect(result.part2 == 5);
}

test "real" {
const input = @embedFile("./testdata/day01");
const result = try solve(input);
try expect(result.part1 == 1527);
try expect(result.part2 == 1575);
}
Loading

0 comments on commit 0dfa6b4

Please sign in to comment.