 # Untitled

Mar 27th, 2021
780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package main
2.
3. import "fmt"
4.
5. var segs = int {
6.     6,
7.     2,
8.     5,
9.     5,
10.     4,
11.     5,
12.     6,
13.     3,
14.     7,
15.     6,
16. }
17.
18. func main() {
19.     // There is a ten digit number, if you subtract shogun26 from it, secrets will be revealed!
20.     // The number is odd.
21.     for i := 1; i < 9999999999; i += 2 {
22.         if i % 10000000 == 1 {
23.             fmt.Printf("%d%%\n", (i - 1) / 100000000)
24.         }
25.
26.         // The number yields zero only on single digit modulo 1, 3 and 7.
27.         if i % 3 != 0 { continue }
28.         if i % 5 == 0 { continue }
29.         if i % 7 != 0 { continue }
30.         if i % 9 == 0 { continue }
31.
32.         parts := []int{
33.             (i / 1000000000) % 10,
34.             (i / 100000000) % 10,
35.             (i / 10000000) % 10,
36.             (i / 1000000) % 10,
37.             (i / 100000) % 10,
38.             (i / 10000) % 10,
39.             (i / 1000) % 10,
40.             (i / 100) % 10,
41.             (i / 10) % 10,
42.             (i / 1) % 10,
43.         }
44.
45.         // The last digit is higher than the first.
46.         if parts <= parts {
47.             continue
48.         }
49.
50.         // First and last trio of digits have all increasing digits left to right.
51.         if parts >= parts || parts >= parts || parts >= parts || parts >= parts {
52.             continue
53.         }
54.
55.         // If you add all the digits you get 39.
56.         var sum int
57.         for _, p := range parts {
58.             sum += p
59.         }
60.         if sum != 39 {
61.             continue
62.         }
63.
64.         // There is exactly one digit which is surrounded by two even digits which are different.
65.         // There is exactly one digit which is surrounded by two even digits which are the same.
66.         var same, diff int
67.         for n := 1; n < 9; n++ {
68.             if parts[n-1]%2 == 0 && parts[n+1]%2 == 0 {
69.                 if parts[n-1] == parts[n+1] {
70.                     same++
71.                 } else {
72.                     diff++
73.                 }
74.             }
75.         }
76.         if same != 1 || diff != 1 {
77.             continue
78.         }
79.
80.         // Every possible neighbouring pairs of digits except three has the left digit lower than the right digit.
81.         var jumps int
82.         for n := 0; n < 9; n++ {
83.             if parts[n] >= parts[n+1] {
84.                 jumps++
85.             }
86.         }
87.         if jumps != 3 {
88.             continue
89.         }
90.
91.         // The sum of all even digits is one more than the sum of all odd digits.
92.         var evens, odds int
93.         for _, p := range parts {
94.             if p % 2 == 0 {
95.                 evens += p
96.             } else {
97.                 odds += p
98.             }
99.         }
100.         if evens != 1 + odds {
101.             continue
102.         }
103.
104.         // Writing the number on a 7-segment display would use 43 segments.
105.         var segCount int
106.         for _, p := range parts {
107.             segCount += segs[p]
108.         }
109.         if segCount != 43 {
110.             continue
111.         }
112.
113.         // Every digit four must be surrounded on both sides by numbers of the same parities. No digit counts as even unless the number is mentioned in the bible, then it counts as odd.
114.         if !fourSurrounded(parts) {
115.             continue
116.         }
117.
118.         // Only one digit is repeated three times.
119.         // Only one digit is repeated two times.
120.         // There are exactly five digits which only appear once.
121.         // There are neither any zeroes, eights nor nines.
122.         // All other digits are represented at least once.
123.         var counts int
124.         var freqs int
125.         for _, p := range parts {
126.             freqs[counts[p]]--
127.             counts[p]++
128.             freqs[counts[p]]++
129.         }
130.         if counts > 0 || counts > 0 || counts > 0 || freqs != 5 || freqs != 1 || freqs != 1 {
131.             continue
132.         }
133.
134.         // The largest prime factor is 7 digits long.
135.         lp := largestPrimeFactors(i)
136.         println(lp)
137.         if lp < 1000000 || lp > 9999999 {
138.             continue
139.         }
140.
141.         fmt.Printf("%d %v (sum: %d, largest prime: %d, events: %d, odds: %d, 7-seg segments: %d)\n", i, parts, sum, lp, evens, odds, segCount)
142.         return
143.     }
144. }
145.
146.
147. func largestPrimeFactors(i int) int {
148.     var factors []int
149.     d := 2
150.     for i > 1 {
151.         for i%d == 0 {
152.             factors = append(factors, d)
153.             i /= d
154.         }
155.         d++
156.         if d*d > i {
157.             if i > 1 {
158.                 factors = append(factors, i)
159.                 break
160.             }
161.         }
162.     }
163.
164.     max := 0
165.     for _, f := range factors {
166.         if f > max {
167.             max = f
168.         }
169.     }
170.
171.     return max
172. }
173.
174. func fourSurrounded(parts []int) bool {
175.     // Every digit four must be surrounded on both sides by numbers of the same parities. No digit counts as even unless the number is mentioned in the bible, then it counts as odd.
176.     for n, p := range parts {
177.         if p == 4 {
178.             var leftEven, rightEven bool
179.             if n == 0 {
180.                 leftEven = false
181.             } else {
182.                 leftEven = parts[n-1] % 2 == 0
183.             }
184.
185.             if n == 8 {
186.                 rightEven = false
187.             } else {
188.                 rightEven = parts[n+1] % 2 == 0
189.             }
190.
191.             if leftEven != rightEven {
192.                 return false
193.             }
194.         }
195.     }
196.     return true
197. }
198.
RAW Paste Data