Advertisement
Guest User

2024day17singleDigits

a guest
Dec 18th, 2024
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. public static class Day17
  2. {
  3. public static string Solve1(string input) => string.Join(',', Solve(SplitNumbers(input).First));
  4.  
  5. public static long Solve2(string input)
  6. {
  7. long[] expect = input.Split(Environment.Newline + Environment.Newline)[1].Replace("Program: ", string.Empty).Split(",").Select(long.Parse).ToArray();
  8. long A = 0L;
  9. int j = 15;
  10. bool ok = true;
  11. while (j >= 0)
  12. {
  13. int i = 0;
  14. int t = ok || A % 8L > 0L ? (int)(A % 8L) : 8;
  15. for (i = t; i < 8; i++)
  16. {
  17. if (Crunch(A) == expect[j])
  18. break;
  19. A += 1L;
  20. }
  21. if (i == 8)
  22. {
  23. A = A / 8L;
  24. ok = false;
  25. j += 1;
  26. }
  27. else
  28. {
  29. A = A * 8L;
  30. ok = true;
  31. j -= 1;
  32. }
  33. }
  34. return A / 8L;
  35. }
  36.  
  37. // Interpreted Crunch,0,3,3,0
  38. private static IEnumerable<long> Solve(long @init)
  39. {
  40. while (@init > 0L)
  41. {
  42. yield return Crunch(@init);
  43. @init = @init >> 3;
  44. }
  45. }
  46.  
  47. // Interpreted 2,4,1,5,7,5,1,6,4,2,5,5
  48. private static long Crunch(long A)
  49. {
  50. int R = (int)(A % 8L);
  51. int R101 = R ^ 5;
  52. return (R101 ^ 6 ^ A >> R101) % 8L;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement