AVIO4NA5ST34SYHOGSVLHES63AN5IOV3KKE563AFCIEQC7ZJYFRQC
_ = allocator;
return 0;
}
const ARRAY_SIZE = 1_000_000;
const input = INPUT;
var cc = try CrabCups(u20, ARRAY_SIZE).init(allocator.?);
defer {
cc.cups.deinit();
}
try cc.parse(input);
// fill up the array
var item: u20 = input.len;
while (item < ARRAY_SIZE) : (item += 1) {
cc.cups.items[item] = item + 1;
}
// fill up fixes...
const tmp = (try std.fmt.parseUnsigned(usize, input[input.len - 1 ..], 10)) - 1;
// last item should point to first
cc.cups.items[cc.cups.items.len - 1] = cc.current;
// parsed last item should point to first item in fill up
cc.cups.items[tmp] = input.len;
fn move(self: *@This(), allocator: std.mem.Allocator) !void {
const cup1 = self.cups.orderedRemove(1);
const cup2 = self.cups.orderedRemove(1);
const cup3 = self.cups.orderedRemove(1);
var ret: usize = 0;
const cup1 = cc.cups.items[0];
const cup2 = cc.cups.items[cup1];
ret = cup1 + 1;
ret *= cup2 + 1;
const destination = blk: {
var dest: CupType = self.cups.items[0];
while (true) : (dest -= 1) {
if (dest == 0) dest = 9;
if (dest != self.cups.items[0] and dest != cup1 and dest != cup2 and dest != cup3) {
break;
}
}
break :blk dest;
};
// std.debug.print("destination: {}\n", .{destination});
fn CrabCups(comptime CupType: anytype, comptime SIZE: usize) type {
const Cups = std.ArrayList(CupType);
for ([_]usize{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }) |offset| {
next.appendAssumeCapacity(self.cups.items[offset % self.cups.items.len]);
// cup_label points to next cup
fn parse(self: *@This(), input: Str) !void {
var array = try self.cups.addManyAsArray(SIZE);
var prev: CupType = undefined;
for (input) |_, idx| {
const cup_label = (try std.fmt.parseUnsigned(CupType, input[idx .. idx + 1], 10)) - 1;
if (idx == 0) self.current = cup_label;
if (idx != 0) array[prev] = cup_label;
if (idx == input.len - 1) array[cup_label] = self.current;
prev = cup_label;
}
fn parseInput(allocator: std.mem.Allocator, input: Str) anyerror!CrabCups {
var ret: CrabCups = undefined;
ret.cups = try std.ArrayList(CupType).initCapacity(allocator, 9);
const cup1 = self.cups.items[self.current];
const cup2 = self.cups.items[cup1];
const cup3 = self.cups.items[cup2];
return ret;
const destination = blk: {
var dest: CupType = self.current;
while (true) {
if (dest != 0) dest -= 1 else dest = SIZE - 1;
if (dest != self.current and dest != cup1 and dest != cup2 and dest != cup3) {
break;
}
}
break :blk dest;
};
// std.debug.print("destination: {}\n", .{destination + 1});
// 1. point current to item after cup3
self.cups.items[self.current] = self.cups.items[cup3];
// 2. point cup3 to destination's next
self.cups.items[cup3] = self.cups.items[destination];
// 3. point destination to cup1
self.cups.items[destination] = cup1;
// update current
self.current = self.cups.items[self.current];
}
};