Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Day17
- {
- public static string Solve1(string input) => string.Join(',', Solve(SplitNumbers(input).First));
- public static long Solve2(string input)
- {
- long[] expect = input.Split(Environment.Newline + Environment.Newline)[1].Replace("Program: ", string.Empty).Split(",").Select(long.Parse).ToArray();
- long A = 0L;
- int j = 15;
- bool ok = true;
- while (j >= 0)
- {
- int i = 0;
- int t = ok || A % 8L > 0L ? (int)(A % 8L) : 8;
- for (i = t; i < 8; i++)
- {
- if (Crunch(A) == expect[j])
- break;
- A += 1L;
- }
- if (i == 8)
- {
- A = A / 8L;
- ok = false;
- j += 1;
- }
- else
- {
- A = A * 8L;
- ok = true;
- j -= 1;
- }
- }
- return A / 8L;
- }
- // Interpreted Crunch,0,3,3,0
- private static IEnumerable<long> Solve(long @init)
- {
- while (@init > 0L)
- {
- yield return Crunch(@init);
- @init = @init >> 3;
- }
- }
- // Interpreted 2,4,1,5,7,5,1,6,4,2,5,5
- private static long Crunch(long A)
- {
- int R = (int)(A % 8L);
- int R101 = R ^ 5;
- return (R101 ^ 6 ^ A >> R101) % 8L;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement