diff options
author | Julien Dessaux | 2022-12-06 11:56:29 +0100 |
---|---|---|
committer | Julien Dessaux | 2022-12-06 11:56:29 +0100 |
commit | 68f3c84d682a7bd2d06f80db686d1cc91b58f0ce (patch) | |
tree | 4317f8924b74ac823fbf534b6f350c58fa5b7dcd /2022 | |
parent | 2022-05 in zig (diff) | |
download | advent-of-code-68f3c84d682a7bd2d06f80db686d1cc91b58f0ce.tar.gz advent-of-code-68f3c84d682a7bd2d06f80db686d1cc91b58f0ce.tar.bz2 advent-of-code-68f3c84d682a7bd2d06f80db686d1cc91b58f0ce.zip |
2022-06 in zig
Diffstat (limited to '')
-rw-r--r-- | 2022/06-tuning-trouble/example | 1 | ||||
-rw-r--r-- | 2022/06-tuning-trouble/example2 | 1 | ||||
-rw-r--r-- | 2022/06-tuning-trouble/example3 | 1 | ||||
-rw-r--r-- | 2022/06-tuning-trouble/example4 | 1 | ||||
-rw-r--r-- | 2022/06-tuning-trouble/example5 | 1 | ||||
-rw-r--r-- | 2022/06-tuning-trouble/first.zig | 28 | ||||
-rw-r--r-- | 2022/06-tuning-trouble/input | 1 | ||||
-rw-r--r-- | 2022/06-tuning-trouble/second.zig | 37 |
8 files changed, 71 insertions, 0 deletions
diff --git a/2022/06-tuning-trouble/example b/2022/06-tuning-trouble/example new file mode 100644 index 0000000..7980a82 --- /dev/null +++ b/2022/06-tuning-trouble/example @@ -0,0 +1 @@ +mjqjpqmgbljsphdztnvjfqwrcgsmlb diff --git a/2022/06-tuning-trouble/example2 b/2022/06-tuning-trouble/example2 new file mode 100644 index 0000000..19fe247 --- /dev/null +++ b/2022/06-tuning-trouble/example2 @@ -0,0 +1 @@ +bvwbjplbgvbhsrlpgdmjqwftvncz diff --git a/2022/06-tuning-trouble/example3 b/2022/06-tuning-trouble/example3 new file mode 100644 index 0000000..0f12ee2 --- /dev/null +++ b/2022/06-tuning-trouble/example3 @@ -0,0 +1 @@ +nppdvjthqldpwncqszvftbrmjlhg diff --git a/2022/06-tuning-trouble/example4 b/2022/06-tuning-trouble/example4 new file mode 100644 index 0000000..38510e7 --- /dev/null +++ b/2022/06-tuning-trouble/example4 @@ -0,0 +1 @@ +nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg diff --git a/2022/06-tuning-trouble/example5 b/2022/06-tuning-trouble/example5 new file mode 100644 index 0000000..e1d0a43 --- /dev/null +++ b/2022/06-tuning-trouble/example5 @@ -0,0 +1 @@ +zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw diff --git a/2022/06-tuning-trouble/first.zig b/2022/06-tuning-trouble/first.zig new file mode 100644 index 0000000..0d20f2a --- /dev/null +++ b/2022/06-tuning-trouble/first.zig @@ -0,0 +1,28 @@ +const std = @import("std"); + +const example = @embedFile("example"); +const example2 = @embedFile("example2"); +const example3 = @embedFile("example3"); +const example4 = @embedFile("example4"); +const example5 = @embedFile("example5"); +const input = @embedFile("input"); + +pub fn main() anyerror!void { + try std.testing.expectEqual(solve(example), 7); + try std.testing.expectEqual(solve(example2), 5); + try std.testing.expectEqual(solve(example3), 6); + try std.testing.expectEqual(solve(example4), 10); + try std.testing.expectEqual(solve(example5), 11); + const result = solve(input); + try std.io.getStdOut().writer().print("{}\n", .{result}); +} + +fn solve(puzzle: []const u8) u64 { + var i: u64 = 3; + while (true) : (i += 1) { + if (puzzle[i] == puzzle[i - 1] or puzzle[i] == puzzle[i - 2] or puzzle[i] == puzzle[i - 3] or puzzle[i - 1] == puzzle[i - 2] or puzzle[i - 1] == puzzle[i - 3] or puzzle[i - 2] == puzzle[i - 3]) { + continue; + } + return i + 1; + } +} diff --git a/2022/06-tuning-trouble/input b/2022/06-tuning-trouble/input new file mode 100644 index 0000000..fa89a81 --- /dev/null +++ b/2022/06-tuning-trouble/input @@ -0,0 +1 @@ +nfddjzjjjmrjjfttzctzzhqzqbbvhhcfcpcqpcqpccsmsvsswbwzwfffnvfvpfvffhnnrgngzgrrhvhfhvvmjvjcccvppqdppbnbjjzlzflfccjjtctqccrhrnhnqhqwwjssjjhpjjcqqdgghddhfdfbffdpfdfzdddthhrcrbrqrbqqbcbnnwbbzcbzccmqqwllrljjjpqpdpsddmbmccwwgngmmzzzpbpspnprnppprmmwfwffrrpsrrchrrrrdqdfddnvnjnppqmqhhpshhjmhjhzjhhhzllbpbnnngdgzgmmjvvprrhqrhqhpqhqqrnqnddvjvvftfggfcgfffgrghhbmbzzjczzcscrccgbbjbqjbjsbsqbqttbqbfqqqrzrmzrmmcwcmwmrwmwnmnfnjjbdjbbslltjjmgmrmllhbhsbsmsqmqllvjjrvjrjcrrtztjzjbjsbbrjjvbjjgqjjpjsszpszsnznllvmlmfmppbvbzvvddtbtrbttchthjthjhnjnqnqrrllnflnnljnnzjjswjwllpmmpnnqnrrndnnbwwmcmcmbbhjjbbfpfvpvttcvvhshqqznzqqdndldmllpgptgptpbblzlddgqqdmmvpvvrccfvvjrvjjgpggqcggjbgbqqcgqccgppffjppzczmzdmmqppwcwlcwwhccfpcphcctvtzthtzhhnmnvmnnvqnqnpnqqwqsqdsszwzbwwgcwcrrtprrfhhcmcqcdcvdcccnpptgpgwpprsprsrdrtdrtrntrtprtppstsccbwwvnvpnvpnptpqttzbzcznzhzhddfbflfcchvchhplhlwhhlhglhhwqqzlqzlzvlvtlvtvrttglttslslclslqssslclbbrjrpjjcscfsfppjlplhplptlltlflglffdttmffrggfjjmllbnlnbnznqnfffmhhnmmsgmsmfsszggpnnhmhnnpwnndqqlmqmnmtnmtnttvtztlzlnzzsdsnssvhsszcscffcpczpcpffpwfwnwhnntnssptthccbnndppgjgpjpssbnnpgnpppjtjqqzfqqrrbmmbdddzjzvzwzssnpsnspnpvnpppjppvsvffmpffbcffslfsfmsmmqzzmttnsnqsqcsqsbqbcclqqphpttvrtrlrhrthhlppscsrsjjvljlmlwlslblqqqgdsbrzwzjzwcjrwbpfmjtmdgjvbcfvtvmsfjtjcmtlzmsjlnmhcswcmjndggdsmqfmmdngjpvrsbhrchldnhdhfdlwccnfmgbwfzppgzzcvblvsmqbfghrgdwlzdcvpqthgbdlwbrfpsvlgpdqznftswgwvchjfrblbdsqjmzchfhlrjhpbrdgvgrrmhrnrdbrdsfsgzvqfdtnvddbtcjwphrhgpqlzjssrgzjcncjnbrzvhgbwpgtfnqhpspmgptzcgvjqgzpmwtjtzldqnclmplwdpzcppgcbrsnlzfgmlnljjhfzrftnhdfnqchgdqrfcjszvbmdrghwzmjnwgnrlptljzqrwsmcfwvbcjgsfdjhnqgzzztmcgmndbtdwvqmzlfcmhfgpqztwgjdccncdccpgbcvhfzbhhbjhgjpdzcmrwgtvrmzdwjtmlzllmgplpqjwwwvbrzgmvpcvwchcwfgbjtzrfctgvfrpphbnsbjlswrztqmchtzfstzdgdwwvhpdhztbmsrbqmndpgvnwwdtgzcddvmvbjstqmjvtzlzgrhzhvplwnpphctvtlvnpmwfzmqcvrnfmmgtsgbcjpffrvbpqpszfpjsjtzqmcnzhnjnpwtvgfqntnhhjhmbvmlvmqgggrnfmmmsvfsqffbvwtzlfhlbjqhrltzwfstvjqhbbblqdbcmgtjgmzdtpslbzsgnmpzsswjlwdpzpmmvmpntbhnqlwrcrfbghzhwlhhpjqztjjrrfscrtwtnlqlqmdbmbfnvngvvthhghgsvqlqvgvmtjmjtwpcznzqhhfpqqfphcdrtzjjhsffslthzwpmsnltnjmfgpsjgqzdwrtgnhflhrnjwqftpnqgptgvgjptzhhtqhtddsfhppmmqcrsnlnrswpjhqgzbpwzfzptzqzzwltlrmjwjrwdgvvzhshqqrhtzmvqpfljlvpmrzbqpscpvsfdbdbcbdwwhpmldlrgpwslzhtbpgtzscfhjlgwcgbhcbftpftvpggvcdvndqnfvfqbwrjtdcbwpsbqpzmwdhjpmjhjmlcdphrjbgsnmcmvfnrggfvttclmbvsfjpnbndbblnbdfqzmsldlswdrtzqsqppjshtlrtccthmmpjgddbbgfgthnzdffbtrpchzgbvqvjcsnpgbrzrczzmzrmhjrlvvgmsqddjsqmcqfmwnhznbczzjlpmhnfwjtrfgffsjdlwgdwwlvdpdlvszphntrvttczgnwffsdsvjmqbthgcgfjgznrfnbplbvgsjbsglhnrjpbldhmznqgqpvldvhcpmmwzfjdjdbnprtrrnwsszjhmngvmtsrqdqdsprwhjpsqwqbsdtpptwlbfbsvdgrplrvpnfbzwrdsdbvhpgwcnqvwdcswdmdltchnngpmlqvchbnrpzcnfhvlzbwbnmssbhpvvmpcwvrwzpfpssndwwfnrslpjwhwrfsswmgtszrhczcrclpldpwpghgptmzzjjjtvjcnncjpfbcvldbnlnqtsqdswcsrqcfgvwbwdvbdwwzndfvcstjbfngtqqwsbpdjdgqdlsnwgcvmmhrqcqvdbqdqczzwzlfgffbwzbfdnpvprzmqclllsdvctwjfgqbchhmsntlvnlspwtnhgshwrvzccfmfrscqwrvdccwqnrccctjrvvnqbrphrfvfrfldbbthhrdzvdmfbctsmvgwmvpdslgbcpqqdvpsjcdvmctwghdsjtmhhvdswbcvtmsnsztfghnnfhflmmnmdqpvpdplllzgqgnsjwsrgzfwhrwhcscvrgcrgjdghqjfbswtgjsvnpqznrvbdbrplwdmbqhtbcfccnpwqlsdstnpcfpbfgqrzmcqhflmcfvbbnwrrblnfslsrwpwlbvqfhgpdwzmgvftssrvdmhnmwdfqmsvqbltlmmwmjrrhgpgznqbwhcqgphvzqmntbbdhhpnlbbffjgmcdntgwmtblwlzrcdcdbtrllrdnznrrsglnwhtwbrfdrpvgqwsgzwghbtsfwqlchgsnvfmvnzntlsnlwrnjjltrpmhwnzmhrqdlvvzbfgwlwgdsgcjcjfvhbcjgzlqtsljvzcvlppqdszvdbsmgddrtmvbcpbpppcpvhzfsjrmtcpzljbhpnjjmcdwslrhslccpljrtvcscbcltpshpnrqvtdfzbbfqtpbvznvrbflwvbvrhqpzltsdrnqccsfgzzftvjfqslcnmfvwtpdbjhtzwrgvntgnfvqtdrjdgglvrnqfzsbhnvhcdbctthdrjnvwlcsjtmphpvlqjngwjnngmqqnslrrsdfpfbvsvcwjtfmwtbpnnghtvvwlphbnsgflvsfdcqrctvjfjrwqjdmbbcclwvlstbgbfqjgbpbqfwdbpmnvqnfpbhrfhwltmcszpwnvtvhrvpcqhzdppjwttlhgsnvmsrwrnwvgzpbwljjjsjzctftzftvmsstpjnzvmmrgbbpmfmfrszwjdgzfhpvsfdqbbhgvfvqrrtqwlwzwwsnnmmvmlwjzvgrwhmffzwrqwbcdtbtzpspbnqgprdqtzrpmgvnmbsnjnvtzgmhqqtrvltbsrwjlssncdppgpmzqzbzvbpjpfwmvgsbhffzpbctmqvfwhsgdjtwqhrhmgnqpvmpjzhppvcbrpwmdshzcrwzdzcjmhfvjgtbznsmdjphlssmlmbhtmnsqnjfsjwhjvgztnwhmnztqppchngdnhzwpsvqqpzdwgbhcbzvmbnqmghbhgvrqhtfzhgvqdbpvdrjsqrdnhqhrwdlczvtnzwfrqhnffwdvtrnqsmmcjtrhmgbwcmnzbbvdsrlbbtwslhghwprpglpq diff --git a/2022/06-tuning-trouble/second.zig b/2022/06-tuning-trouble/second.zig new file mode 100644 index 0000000..5ff7dc0 --- /dev/null +++ b/2022/06-tuning-trouble/second.zig @@ -0,0 +1,37 @@ +const std = @import("std"); + +const example = @embedFile("example"); +const example2 = @embedFile("example2"); +const example3 = @embedFile("example3"); +const example4 = @embedFile("example4"); +const example5 = @embedFile("example5"); +const input = @embedFile("input"); + +pub fn main() anyerror!void { + try std.testing.expectEqual(solve(example), 19); + try std.testing.expectEqual(solve(example2), 23); + try std.testing.expectEqual(solve(example3), 23); + try std.testing.expectEqual(solve(example4), 29); + try std.testing.expectEqual(solve(example5), 26); + const result = solve(input); + try std.io.getStdOut().writer().print("{}\n", .{result}); +} + +fn solve(puzzle: []const u8) u64 { + var n: u64 = 13; + outer: while (true) : (n += 1) { + var i: u64 = n; + while (i >= n - 13) : (i -= 1) { + var j: u64 = i - 1; + while (j >= n - 13) : (j -= 1) { + if (puzzle[i] == puzzle[j]) { + continue :outer; + } + if (j == 0) { + break; + } + } + } + return n + 1; + } +} |