Filippo Vitale
May 02, 2013
190

One way to solve the Problem 411 in Clojure – Clj-Syd May 2013

During the first clj-syd hack night we all discussed possible approaches on solving the ProjectEuler problem 411 and we started solving it.

After few weeks I finally solved it and this is how I did it.

May 02, 2013

Transcript

1. clj-syd pep-411 "It was nice to meet you at the

first clj-syd hack night"
2. clj-syd pep-411 "It was nice to meet you at the

first clj-syd hack night" aka "One way to solve the Problem 411 in Clojure"

uphill path

9. Problem 411 station generation (x, y) = (2i mod n,

3i mod n) i = [0..2n]
10. Problem 411 station generation n = 22 44 stations (2n)

11 distinct stations

Σ solve(n)

Σ solve(n)

17. Naïve Algorithm generate stations (x, y) = (2i mod n,

3i mod n) i = [0..2n]

40. None

54. SortedMap of SortedSet now what?!?! same problem but 1D only...

any leverage?

69. SortedMap of SortedSet Patience Sorting [1 3 5 8 10]

[1 4 5 8 10] [1 4 6 8 10] ...

75. SortedMap of SortedSet Patience 4 [1 10 12] --> [1

2 12] --> [1 2 12 20]
76. SortedMap of SortedSet Patience 4 [1 10 12] --> [1

2 12] --> [1 2 12 20]
77. SortedMap of SortedSet Patience 4 [1 2 12 20] -->

[1 2 8 20] --> [1 2 8 14]
78. SortedMap of SortedSet Patience 4 [1 2 8 14] -->

[1 2 4 14] --> [ ? ? ? ]
79. SortedMap of SortedSet Patience 5 [1 2 8 14] -->

[1 2 4 14] --> [1 2 4 14 18]
80. SortedMap of SortedSet Patience 5 [1 2 8 14] -->

[1 2 4 14] --> [1 2 4 14 18]
81. SortedMap of SortedSet Patience 5 [1 2 4 14 18]

--> [1 2 4 6 18] --> [1 2 4 6 16]

6 16]

6 16]

6 16]

6 16]

6 16]

24,300,000
105. DS as a SortedSet Full Scale? k=30 --> n=305 -->

24,300,000 Everything --> "mod n"

24,300,000

113. Optimisations innermost loops "If a tree falls in a forest

and no one is around to hear it, does it make a sound?"