Advertisement
R7900

DayTwentyfive

Mar 31st, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using static AdventOfCode2020.Common;
  5.  
  6. namespace AdventOfCode2020.Days
  7. {
  8. public class DayTwentyfive
  9. {
  10. private readonly List<long> _input;
  11.  
  12. public DayTwentyfive()
  13. {
  14. _input = ReadFile("daytwentyfive.txt").Select(long.Parse).ToList();
  15. }
  16.  
  17. public void Process()
  18. {
  19. Console.WriteLine($"Merry Christmas!");
  20. Console.WriteLine($"Part 1: {PartOne()}");
  21. Console.WriteLine($"Part 2: null");
  22. }
  23.  
  24. public long PartOne()
  25. {
  26. var doorLoopSize = GetLoopSize(_input[1], 7);
  27. return Transform(_input[0], doorLoopSize);
  28. }
  29.  
  30. private long GetLoopSize(long pubKey, long subject)
  31. {
  32. var current = 1L;
  33. for (int i = 1; ; i++)
  34. {
  35. current = current * subject % 20201227;
  36. if (pubKey == current)
  37. {
  38. return i;
  39. }
  40. }
  41. }
  42.  
  43. private long Transform(long subject, long loop)
  44. {
  45. var current = 1L;
  46. for (int i = 1; i <= loop; i++)
  47. {
  48. current = current * subject % 20201227;
  49. }
  50. return current;
  51. }
  52. }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement