main.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. )
  6. func main() {
  7. blocks := generate_blocks()
  8. fmt.Println(len(blocks))
  9. fmt.Println(blocks[0])
  10. }
  11. func generate_blocks() []int {
  12. var blocks []int
  13. decvals := [9]int{49, 50, 51, 52, 53, 54, 55, 56, 57}
  14. for counter := 123456789; counter <= 987654321; counter++ {
  15. // Convert number to string ([]byte)
  16. digits := strconv.Itoa(counter)
  17. // Check if every number is only represented only once
  18. var valid bool
  19. valid = true
  20. for decval := range decvals {
  21. var count int
  22. for digit := range digits {
  23. if digits[digit] == byte(decvals[decval]) {
  24. count = count + 1
  25. }
  26. }
  27. if count != 1 {
  28. valid = false
  29. }
  30. }
  31. if valid {
  32. blocks = append(blocks, counter)
  33. }
  34. }
  35. return blocks
  36. }
  37. // counter: 123456789
  38. // 1st Digit: 1 (49)
  39. // 2nd Digit: 2 (50)
  40. // 3rd Digit: 3 (51)
  41. // 4th Digit: 4 (52)
  42. // 5th Digit: 5 (53)
  43. // 6th Digit: 6 (54)
  44. // 7th Digit: 7 (55)
  45. // 8th Digit: 8 (56)
  46. // 9th Digit: 9 (57)
  47. // 362880
  48. // 1 2 3
  49. // 4 5 6
  50. // 7 8 9
  51. // 1: 1 2 3 4 7
  52. // 2: 1 2 3 5 8
  53. // 3: 1 2 3 6 9
  54. // 4: 1 4 5 6 7
  55. // 5: 2 4 5 6 8
  56. // 6: 3 4 5 6 9
  57. // 7: 1 4 7 8 9
  58. // 8: 2 5 7 8 9
  59. // 9: 3 6 7 8 9