Skip to content

Instantly share code, notes, and snippets.

@Jared314
Created October 26, 2013 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jared314/7173598 to your computer and use it in GitHub Desktop.
Save Jared314/7173598 to your computer and use it in GitHub Desktop.
Project Euler #8: Find the greatest product, of 5 consecutive digits, in a string
(def data (str "37900490610897696126265185408732594047834333441947"
"01850393807417064181700348379116686008018966949867"
"75587222482716536850061657037580780205386629145841"
"06964490601037178417735301109842904952970798120105"
"47016802197685547844962006690576894353336688823830"
"22913337214734911490555218134123051689058329294117"
"83011983450277211542535458190375258738804563705619"
"55277740874464155295278944953199015261800156422805"
"72771774460964310684699893055144451845092626359982"
"79063901081322647763278370447051079759349248247518"))
(reduce #(max %1 (apply * %2))
Integer/MIN_VALUE
(partition 5 1 (map #(Character/getNumericValue %) data)))
;; or
(->> data
(map #(Character/getNumericValue %))
(partition 5 1)
(reduce #(max %1 (apply * %2)) Integer/MIN_VALUE))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment