From 68f3c84d682a7bd2d06f80db686d1cc91b58f0ce Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 6 Dec 2022 11:56:29 +0100 Subject: 2022-06 in zig --- 2022/06-tuning-trouble/example | 1 + 2022/06-tuning-trouble/example2 | 1 + 2022/06-tuning-trouble/example3 | 1 + 2022/06-tuning-trouble/example4 | 1 + 2022/06-tuning-trouble/example5 | 1 + 2022/06-tuning-trouble/first.zig | 28 ++++++++++++++++++++++++++++ 2022/06-tuning-trouble/input | 1 + 2022/06-tuning-trouble/second.zig | 37 +++++++++++++++++++++++++++++++++++++ 8 files changed, 71 insertions(+) create mode 100644 2022/06-tuning-trouble/example create mode 100644 2022/06-tuning-trouble/example2 create mode 100644 2022/06-tuning-trouble/example3 create mode 100644 2022/06-tuning-trouble/example4 create mode 100644 2022/06-tuning-trouble/example5 create mode 100644 2022/06-tuning-trouble/first.zig create mode 100644 2022/06-tuning-trouble/input create mode 100644 2022/06-tuning-trouble/second.zig (limited to '2022/06-tuning-trouble') 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; + } +} -- cgit v1.2.3