Compare commits

...

5 Commits

  1. 0
      2020/elixir/README.md
  2. 0
      2020/elixir/day1/README
  3. 0
      2020/elixir/day1/day1part1.exs
  4. 0
      2020/elixir/day1/day1part2.exs
  5. 0
      2020/elixir/day1/day1refactored.exs
  6. 0
      2020/elixir/day1/input
  7. 0
      2020/elixir/day10/README
  8. 0
      2020/elixir/day10/day10part1.exs
  9. 0
      2020/elixir/day10/day10part2-refactored.exs
  10. 0
      2020/elixir/day10/day10part2.exs
  11. 0
      2020/elixir/day10/input
  12. 0
      2020/elixir/day11/README
  13. 0
      2020/elixir/day11/day11part1.exs
  14. 0
      2020/elixir/day11/day11part2.exs
  15. 0
      2020/elixir/day11/input
  16. 0
      2020/elixir/day12/README
  17. 0
      2020/elixir/day12/day12part1.exs
  18. 0
      2020/elixir/day12/day12part2.exs
  19. 0
      2020/elixir/day12/input
  20. 0
      2020/elixir/day13/README
  21. 0
      2020/elixir/day13/day13part1.exs
  22. 0
      2020/elixir/day13/day13part2-cheating.exs
  23. 0
      2020/elixir/day13/day13part2.exs
  24. 0
      2020/elixir/day13/input
  25. 0
      2020/elixir/day14/README
  26. 0
      2020/elixir/day14/day14part1.exs
  27. 0
      2020/elixir/day14/day14part2.exs
  28. 0
      2020/elixir/day14/input
  29. 0
      2020/elixir/day15/README
  30. 0
      2020/elixir/day15/day15.exs
  31. 0
      2020/elixir/day16/README
  32. 0
      2020/elixir/day16/day16part1.exs
  33. 0
      2020/elixir/day16/day16part2-simpler-transpose.exs
  34. 0
      2020/elixir/day16/day16part2.exs
  35. 0
      2020/elixir/day16/input
  36. 0
      2020/elixir/day17/README
  37. 0
      2020/elixir/day17/day17part1.exs
  38. 0
      2020/elixir/day17/day17part2.exs
  39. 0
      2020/elixir/day17/input
  40. 0
      2020/elixir/day18/README
  41. 0
      2020/elixir/day18/day18part1.exs
  42. 0
      2020/elixir/day18/day18part2.exs
  43. 0
      2020/elixir/day18/input
  44. 0
      2020/elixir/day2/README
  45. 0
      2020/elixir/day2/day2part1.exs
  46. 0
      2020/elixir/day2/day2part2.exs
  47. 0
      2020/elixir/day2/input
  48. 0
      2020/elixir/day21/README
  49. 0
      2020/elixir/day21/day21part1.exs
  50. 0
      2020/elixir/day21/day21part2.exs
  51. 0
      2020/elixir/day21/input
  52. 0
      2020/elixir/day23/README
  53. 0
      2020/elixir/day23/day23part1.exs
  54. 0
      2020/elixir/day23/day23part2.exs
  55. 0
      2020/elixir/day24/README
  56. 0
      2020/elixir/day24/day24part1.exs
  57. 0
      2020/elixir/day24/day24part2.exs
  58. 0
      2020/elixir/day24/input
  59. 0
      2020/elixir/day25/README
  60. 0
      2020/elixir/day25/day25part1.exs
  61. 0
      2020/elixir/day25/input
  62. 0
      2020/elixir/day3/README
  63. 0
      2020/elixir/day3/day3part1.exs
  64. 0
      2020/elixir/day3/day3part2.exs
  65. 0
      2020/elixir/day3/input
  66. 0
      2020/elixir/day4/README
  67. 0
      2020/elixir/day4/day4part1.exs
  68. 0
      2020/elixir/day4/day4part2.exs
  69. 0
      2020/elixir/day4/input
  70. 0
      2020/elixir/day5/README
  71. 0
      2020/elixir/day5/day5part1-bitstring.exs
  72. 0
      2020/elixir/day5/day5part1.exs
  73. 0
      2020/elixir/day5/day5part2-bitstring.exs
  74. 0
      2020/elixir/day5/day5part2.exs
  75. 0
      2020/elixir/day5/input
  76. 0
      2020/elixir/day6/README
  77. 0
      2020/elixir/day6/day6part1.exs
  78. 0
      2020/elixir/day6/day6part2.exs
  79. 0
      2020/elixir/day6/input
  80. 0
      2020/elixir/day7/README
  81. 0
      2020/elixir/day7/day7part1.exs
  82. 0
      2020/elixir/day7/day7part2.exs
  83. 0
      2020/elixir/day7/input
  84. 0
      2020/elixir/day8/README
  85. 0
      2020/elixir/day8/day8part1.exs
  86. 0
      2020/elixir/day8/day8part2.exs
  87. 0
      2020/elixir/day8/input
  88. 0
      2020/elixir/day9/README
  89. 0
      2020/elixir/day9/day9part1.exs
  90. 0
      2020/elixir/day9/day9part2.exs
  91. 0
      2020/elixir/day9/input
  92. 16
      2020/zig/.gitattributes
  93. 4
      2020/zig/.gitignore
  94. 20
      2020/zig/LICENSE
  95. 32
      2020/zig/README.md
  96. 146
      2020/zig/build.zig
  97. 50
      2020/zig/src/day01.zig
  98. 44
      2020/zig/src/day02.zig
  99. 44
      2020/zig/src/day03.zig
  100. 44
      2020/zig/src/day04.zig
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,16 @@
# See https://git-scm.com/docs/gitattributes
# See https://help.github.com/articles/dealing-with-line-endings/
# Default behavior, if core.autocrlf is unset.
* text=auto
# Files to be converted to native line endings on checkout.
*.cpp text
*.h text
# Text files to always have CRLF (dos) line endings on checkout.
*.bat text eol=crlf
# Text files to always have LF (unix) line endings on checkout.
*.sh text eol=lf
*.zig text eol=lf

@ -0,0 +1,4 @@
zig-cache/
zig-out/
data/
build_runner.zig

@ -0,0 +1,20 @@
Copyright (c) 2020-2021 Martin Wickham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -0,0 +1,32 @@
# Advent Of Code Zig Template
This repo provides a template for Advent of Code participants using Zig. It contains a main file for each day, a build.zig file set up with targets for each day, and Visual Studio Code files for debugging.
This template tracks the master branch of Zig, *not* 0.8.1. It may not work with older versions.
## How to use this template:
The src/ directory contains a main file for each day. Put your code there. The build command `zig build dayXX [target and mode options] -- [program args]` will build and run the specified day. You can also use `zig build install_dayXX [target and mode options]` to build the executable for a day and put it into `zig-out/bin` without executing it. By default this template does not link libc, but you can set `should_link_libc` to `true` in build.zig to change that. If you add new files with tests, add those files to the list of test files in test_all.zig. The command `zig build test` will run tests in all of these files. You can also use `zig build test_dayXX` to run tests in a specific day, or `zig build install_tests_dayXX` to create a debuggable test executable in `zig-out/bin`.
Each day contains a decl like this:
```zig
const data = @embedFile("../data/day05.txt");
```
To use this system, save your input for a day in the data/ directory with the appropriate name. Reference this decl to load the contents of that file as a compile time constant. If a day has no input, or you prefer not to embed it in this form, simply don't reference this decl. If it's unused, it will not try to load the file, and it won't error if the file does not exist.
This repo also contains Visual Studio Code project files for debugging. These are meant to work with the C/C++ plugin. There is a debug configuration for each day. By default all days are built in debug mode, but this can be changed by editing `.vscode/tasks.json` if you have a need for speed.
If you would like to contribute project files for other development environments, please send a PR.
## Setting up ZLS
Zig has a reasonably robust language server, which can provide autocomplete for VSCode and many other editors. It can help significantly with exploring the std lib and suggesting parameter completions. To set it up, make sure you have an up-to-date master build of Zig (which you can [download here](https://ziglang.org/download/)), and then run the following commands:
```
git clone --recurse-submodules https://github.com/zigtools/zls
cd zls
zig build -Drelease-fast
zig-out/bin/zls configure
```
The last command will direct you to documentation for connecting it to your preferred editor. If you are using VSCode, the documentation [can be found here](https://github.com/zigtools/zls/wiki/Installing-for-Visual-Studio-Code).

@ -0,0 +1,146 @@
const std = @import("std");
const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep;
// set this to true to link libc
const should_link_libc = false;
fn linkObject(b: *Builder, obj: *LibExeObjStep) void {
if (should_link_libc) obj.linkLibC();
_ = b;
// Add linking for packages or third party libraries here
}
const required_zig_version = std.SemanticVersion.parse("0.9.0-dev.1920+de81c504b") catch unreachable;
pub fn build(b: *Builder) void {
if (comptime @import("builtin").zig_version.order(required_zig_version) == .lt) {
std.debug.print(
\\Error: Your version of Zig is missing features that are needed for this template.
\\You will need to download a newer build.
\\
\\ https://ziglang.org/download/
\\
\\
, .{});
std.os.exit(1);
}
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const install_all = b.step("install_all", "Install all days");
const install_all_tests = b.step("install_tests_all", "Install tests for all days");
const run_all = b.step("run_all", "Run all days");
// Set up an exe for each day
var day: u32 = 1;
while (day <= 25) : (day += 1) {
const dayString = b.fmt("day{:0>2}", .{day});
const zigFile = b.fmt("src/{s}.zig", .{dayString});
const exe = b.addExecutable(dayString, zigFile);
exe.setTarget(target);
exe.setBuildMode(mode);
linkObject(b, exe);
exe.install();
const install_cmd = b.addInstallArtifact(exe);
const run_test = b.addTest(zigFile);
run_test.setTarget(target);
run_test.setBuildMode(mode);
linkObject(b, exe);
const build_test = b.addTestExe(b.fmt("test_{s}", .{dayString}), zigFile);
build_test.setTarget(target);
build_test.setBuildMode(mode);
linkObject(b, exe);
const install_test = b.addInstallArtifact(build_test);
{
const step_key = b.fmt("install_{s}", .{dayString});
const step_desc = b.fmt("Install {s}.exe", .{dayString});
const install_step = b.step(step_key, step_desc);
install_step.dependOn(&install_cmd.step);
install_all.dependOn(&install_cmd.step);
}
{
const step_key = b.fmt("test_{s}", .{dayString});
const step_desc = b.fmt("Run tests in {s}", .{zigFile});
const step = b.step(step_key, step_desc);
step.dependOn(&run_test.step);
}
{
const step_key = b.fmt("install_tests_{s}", .{dayString});
const step_desc = b.fmt("Install test_{s}.exe", .{dayString});
const step = b.step(step_key, step_desc);
step.dependOn(&install_test.step);
install_all_tests.dependOn(&install_test.step);
}
const run_cmd = exe.run();
run_cmd.step.dependOn(&install_cmd.step);
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_desc = b.fmt("Run {s}", .{dayString});
const run_step = b.step(dayString, run_desc);
run_step.dependOn(&run_cmd.step);
run_all.dependOn(&run_cmd.step);
}
// Set up tests for util.zig
{
const test_util = b.step("test_util", "Run tests in util.zig");
const test_cmd = b.addTest("src/util.zig");
test_cmd.setTarget(target);
test_cmd.setBuildMode(mode);
linkObject(b, test_cmd);
test_util.dependOn(&test_cmd.step);
}
// Set up test executable for util.zig
{
const test_util = b.step("install_tests_util", "Run tests in util.zig");
const test_exe = b.addTestExe("test_util", "src/util.zig");
test_exe.setTarget(target);
test_exe.setBuildMode(mode);
linkObject(b, test_exe);
const install = b.addInstallArtifact(test_exe);
test_util.dependOn(&install.step);
}
// Set up a step to run all tests
{
const test_step = b.step("test", "Run all tests");
const test_cmd = b.addTest("src/test_all.zig");
test_cmd.setTarget(target);
test_cmd.setBuildMode(mode);
linkObject(b, test_cmd);
test_step.dependOn(&test_cmd.step);
}
// Set up a step to build tests (but not run them)
{
const test_build = b.step("install_tests", "Install test_all.exe");
const test_exe = b.addTestExe("test_all", "src/test_all.zig");
test_exe.setTarget(target);
test_exe.setBuildMode(mode);
linkObject(b, test_exe);
const test_exe_install = b.addInstallArtifact(test_exe);
test_build.dependOn(&test_exe_install.step);
}
}

@ -0,0 +1,50 @@
const std = @import("std");
const tokenize = std.mem.tokenize;
const parseInt = std.fmt.parseInt;
const print = std.debug.print;
const data = @embedFile("../data/day01.txt");
pub fn main() !void {
var it = tokenize(u8, data, "\n");
// Not sure if allocating a massive buffer and tracking the size is the right approach?
var buffer: [1000]u16 = undefined;
var i: usize = 0;
while (it.next()) |line| {
const int = try parseInt(u16, line, 10);
buffer[i] = int;
// Can we use continue expression?
i = i + 1;
}
try part1(buffer[0..i]);
try part2(buffer[0..i]);
}
fn part1(input: []u16) !void {
for (input) |a, i| {
for (input[(i+1)..]) |b| {
if (a + b == 2020) {
const answer = @as(u32, a) * b;
print("Part1: {d}\n", .{answer});
return;
}
}
}
}
fn part2(input: []u16) !void {
for (input) |a, i| {
for (input[(i+1)..]) |b, j| {
for (input[(j+1)..]) |c| {
if (a + b + c == 2020) {
const answer = @as(u32, a) * b * c;
print("Part2: {d}\n", .{answer});
return;
}
}
}
}
}

@ -0,0 +1,44 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const List = std.ArrayList;
const Map = std.AutoHashMap;
const StrMap = std.StringHashMap;
const BitSet = std.DynamicBitSet;
const Str = []const u8;
const util = @import("util.zig");
const gpa = util.gpa;
const data = @embedFile("../data/day02.txt");
pub fn main() !void {
}
// Useful stdlib functions
const tokenize = std.mem.tokenize;
const split = std.mem.split;
const indexOf = std.mem.indexOfScalar;
const indexOfAny = std.mem.indexOfAny;
const indexOfStr = std.mem.indexOfPosLinear;
const lastIndexOf = std.mem.lastIndexOfScalar;
const lastIndexOfAny = std.mem.lastIndexOfAny;
const lastIndexOfStr = std.mem.lastIndexOfLinear;
const trim = std.mem.trim;
const sliceMin = std.mem.min;
const sliceMax = std.mem.max;
const parseInt = std.fmt.parseInt;
const parseFloat = std.fmt.parseFloat;
const min = std.math.min;
const min3 = std.math.min3;
const max = std.math.max;
const max3 = std.math.max3;
const print = std.debug.print;
const assert = std.debug.assert;
const sort = std.sort.sort;
const asc = std.sort.asc;
const desc = std.sort.desc;

@ -0,0 +1,44 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const List = std.ArrayList;
const Map = std.AutoHashMap;
const StrMap = std.StringHashMap;
const BitSet = std.DynamicBitSet;
const Str = []const u8;
const util = @import("util.zig");
const gpa = util.gpa;
const data = @embedFile("../data/day03.txt");
pub fn main() !void {
}
// Useful stdlib functions
const tokenize = std.mem.tokenize;
const split = std.mem.split;
const indexOf = std.mem.indexOfScalar;
const indexOfAny = std.mem.indexOfAny;
const indexOfStr = std.mem.indexOfPosLinear;
const lastIndexOf = std.mem.lastIndexOfScalar;
const lastIndexOfAny = std.mem.lastIndexOfAny;
const lastIndexOfStr = std.mem.lastIndexOfLinear;
const trim = std.mem.trim;
const sliceMin = std.mem.min;
const sliceMax = std.mem.max;
const parseInt = std.fmt.parseInt;
const parseFloat = std.fmt.parseFloat;
const min = std.math.min;
const min3 = std.math.min3;
const max = std.math.max;
const max3 = std.math.max3;
const print = std.debug.print;
const assert = std.debug.assert;
const sort = std.sort.sort;
const asc = std.sort.asc;
const desc = std.sort.desc;

@ -0,0 +1,44 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const List = std.ArrayList;
const Map = std.AutoHashMap;
const StrMap = std.StringHashMap;
const BitSet = std.DynamicBitSet;
const Str = []const u8;
const util = @import("util.zig");
const gpa = util.gpa;
const data = @embedFile("../data/day04.txt");
pub fn main() !void {
}
// Useful stdlib functions
const tokenize = std.mem.tokenize;
const split = std.mem.split;
const indexOf = std.mem.indexOfScalar;
const indexOfAny = std.mem.indexOfAny;
const indexOfStr = std.mem.indexOfPosLinear;
const lastIndexOf = std.mem.lastIndexOfScalar;
const lastIndexOfAny = std.mem.lastIndexOfAny;
const lastIndexOfStr = std.mem.lastIndexOfLinear;
const trim = std.mem.trim;
const sliceMin = std.mem.min;
const sliceMax = std.mem.max;
const parseInt = std.fmt.parseInt;
const parseFloat = std.fmt.parseFloat;
const min = std.math.min;
const min3 = std.math.min3;
const max = std.math.max;
const max3 = std.math.max3;
const print = std.debug.print;
const assert = std.debug.assert;
const sort = std.sort.sort;
const asc = std.sort.asc;
const desc = std.sort.desc;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save