Skip to content

Commit

Permalink
18-2: remove all complexity of the previous solution
Browse files Browse the repository at this point in the history
  • Loading branch information
milanaleksic committed Jan 2, 2024
1 parent 7d99044 commit 6f4ed85
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions src/day18.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ const util = @import("util.zig");
const mem = std.mem;
const print = std.debug.print;

const Dig = enum {
Surface,
Hole,
};

const Ground = struct {
dig: Dig = Dig.Surface,
escapes: ?bool = null,
visited: bool = false,
};

const Coord = struct {
x: i64,
y: i64,
Expand Down Expand Up @@ -46,29 +35,6 @@ const Data = struct {
try coords.append(coord);
}

// shift all nodes to absolute values for simplicity
var minX: i64 = 0;
var minY: i64 = 0;
for (coords.items) |coordIter| {
if (coordIter.x < minX) {
minX = coordIter.x;
}
if (coordIter.y < minY) {
minY = coordIter.y;
}
}

if (minX < 0 or minY < 0) {
for (coords.items) |*coordFinal| {
if (minX < 0) {
coordFinal.x -= minX;
}
if (minY < 0) {
coordFinal.y -= minY;
}
}
}

return Self{
.allocator = allocator,
.numberOfSteps = numberOfSteps,
Expand Down Expand Up @@ -101,29 +67,6 @@ const Data = struct {
try coords.append(coord);
}

// shift all nodes to absolute values for simplicity
var minX: i64 = 0;
var minY: i64 = 0;
for (coords.items) |coordIter| {
if (coordIter.x < minX) {
minX = coordIter.x;
}
if (coordIter.y < minY) {
minY = coordIter.y;
}
}

if (minX < 0 or minY < 0) {
for (coords.items) |*coordFinal| {
if (minX < 0) {
coordFinal.x -= minX;
}
if (minY < 0) {
coordFinal.y -= minY;
}
}
}

return Self{
.allocator = allocator,
.numberOfSteps = numberOfSteps,
Expand Down

0 comments on commit 6f4ed85

Please sign in to comment.