Hi everyone,
I was in the project euler page and i tried to solve the question 8 using
clojure. No big deal, was really cool.
So , i cant figure out what is the time complexity for the *code* below
I thought that was O(n^2), but running the code for different input seems
that the complexity is O(n).
(def list-of-list (list (list 1 2 3 4 5) ( list 2 3 4 5 6) ( list 9 8 7 6
5) ))
(defn project-euler-8 [ ]
(let[begin (System/currentTimeMillis) ]
(println (str "Result = "
* (**apply** **max** **(**map** #**(**reduce** ***** %1**)*
* **(**for** [i **(**range** **(**count** list-of-list**)**)**]
*
* **(**take** 5 **(**drop** i list-of-list**)**)**)**)**)**)**)*
(println (str "Time = " ( - (System/currentTimeMillis) begin ) ) )
)
)
The map reduce could be translated like two nested for ?
This is O(n^2), isn“t ?
for ( list-of-list )
for ( sublist)
product *= element
Regards
Dantas, Thiago
ps: Sorry for my english, im not a good writer ! :)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en