Books I Like

Sunday, January 3, 2010

Solving Project Euler Problem #16 in Clojure

Problem Statement :

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?


Solution :
The easiest way to multiply a number by 2 is to perform a left bit shift.
Get the number, convert it to string, put the indices in a map and apply a "+" function on it.


(println (apply + (map #(Integer/parseInt (str %1)) (str (bit-shift-left 2 999)))))

4 comments:

Anonymous said...

Hello!
You may probably be very interested to know how one can make real money on investments.
There is no need to invest much at first.
You may begin earning with a money that usually is spent
on daily food, that's 20-100 dollars.
I have been participating in one company's work for several years,
and I'm ready to let you know my secrets at my blog.

Please visit my pages and send me private message to get the info.

P.S. I make 1000-2000 per day now.

http://theinvestblog.com [url=http://theinvestblog.com]Online Investment Blog[/url]

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

logically

Anonymous said...

hi to all anshu-manymoods.blogspot.comers this is my frst post and thought i would say hello to you all -
regards speak again soon
garry m

Get at Amazon