Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- var segs = [10]int {
- 6,
- 2,
- 5,
- 5,
- 4,
- 5,
- 6,
- 3,
- 7,
- 6,
- }
- func main() {
- // There is a ten digit number, if you subtract shogun26 from it, secrets will be revealed!
- // The number is odd.
- for i := 1; i < 9999999999; i += 2 {
- if i % 10000000 == 1 {
- fmt.Printf("%d%%\n", (i - 1) / 100000000)
- }
- // The number yields zero only on single digit modulo 1, 3 and 7.
- if i % 3 != 0 { continue }
- if i % 5 == 0 { continue }
- if i % 7 != 0 { continue }
- if i % 9 == 0 { continue }
- parts := []int{
- (i / 1000000000) % 10,
- (i / 100000000) % 10,
- (i / 10000000) % 10,
- (i / 1000000) % 10,
- (i / 100000) % 10,
- (i / 10000) % 10,
- (i / 1000) % 10,
- (i / 100) % 10,
- (i / 10) % 10,
- (i / 1) % 10,
- }
- // The last digit is higher than the first.
- if parts[9] <= parts[0] {
- continue
- }
- // First and last trio of digits have all increasing digits left to right.
- if parts[0] >= parts[1] || parts[1] >= parts[2] || parts[7] >= parts[8] || parts[8] >= parts[9] {
- continue
- }
- // If you add all the digits you get 39.
- var sum int
- for _, p := range parts {
- sum += p
- }
- if sum != 39 {
- continue
- }
- // There is exactly one digit which is surrounded by two even digits which are different.
- // There is exactly one digit which is surrounded by two even digits which are the same.
- var same, diff int
- for n := 1; n < 9; n++ {
- if parts[n-1]%2 == 0 && parts[n+1]%2 == 0 {
- if parts[n-1] == parts[n+1] {
- same++
- } else {
- diff++
- }
- }
- }
- if same != 1 || diff != 1 {
- continue
- }
- // Every possible neighbouring pairs of digits except three has the left digit lower than the right digit.
- var jumps int
- for n := 0; n < 9; n++ {
- if parts[n] >= parts[n+1] {
- jumps++
- }
- }
- if jumps != 3 {
- continue
- }
- // The sum of all even digits is one more than the sum of all odd digits.
- var evens, odds int
- for _, p := range parts {
- if p % 2 == 0 {
- evens += p
- } else {
- odds += p
- }
- }
- if evens != 1 + odds {
- continue
- }
- // Writing the number on a 7-segment display would use 43 segments.
- var segCount int
- for _, p := range parts {
- segCount += segs[p]
- }
- if segCount != 43 {
- continue
- }
- // 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.
- if !fourSurrounded(parts) {
- continue
- }
- // Only one digit is repeated three times.
- // Only one digit is repeated two times.
- // There are exactly five digits which only appear once.
- // There are neither any zeroes, eights nor nines.
- // All other digits are represented at least once.
- var counts [10]int
- var freqs [10]int
- for _, p := range parts {
- freqs[counts[p]]--
- counts[p]++
- freqs[counts[p]]++
- }
- if counts[0] > 0 || counts[8] > 0 || counts[9] > 0 || freqs[1] != 5 || freqs[2] != 1 || freqs[3] != 1 {
- continue
- }
- // The largest prime factor is 7 digits long.
- lp := largestPrimeFactors(i)
- println(lp)
- if lp < 1000000 || lp > 9999999 {
- continue
- }
- 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)
- return
- }
- }
- func largestPrimeFactors(i int) int {
- var factors []int
- d := 2
- for i > 1 {
- for i%d == 0 {
- factors = append(factors, d)
- i /= d
- }
- d++
- if d*d > i {
- if i > 1 {
- factors = append(factors, i)
- break
- }
- }
- }
- max := 0
- for _, f := range factors {
- if f > max {
- max = f
- }
- }
- return max
- }
- func fourSurrounded(parts []int) bool {
- // 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.
- for n, p := range parts {
- if p == 4 {
- var leftEven, rightEven bool
- if n == 0 {
- leftEven = false
- } else {
- leftEven = parts[n-1] % 2 == 0
- }
- if n == 8 {
- rightEven = false
- } else {
- rightEven = parts[n+1] % 2 == 0
- }
- if leftEven != rightEven {
- return false
- }
- }
- }
- return true
- }
Add Comment
Please, Sign In to add comment