Euler Solution 13

From ProgSoc Wiki

Jump to: navigation, search

Contents

Solutions for Problem 13

Work out the first ten digits of the sum of these one-hundred 50-digit numbers.

Lisp by SanguineV

Runtime (script mode): 40.8ms

(begin (display (substring (number->string (+
; Insert the numbers here...
)) 0 10) (newline))
(exit)

It's really easy when you have the right language for the job. ;)

Python by Althalus

Runtime: 14ms

from math import sqrt
import time
start_time = time.time()

hugenum  = \
37107287533902102798797998220837590246510135740250+ \
46376937677490009712648124896970078050417018260538+ \
74324986199524741059474233309513058123726617309629+ \
# .... Trimmed for brevity on the wiki ....
53503534226472524250874054075591789781264330331690

print(str(hugenum)[0:10])
run_time = time.time() - start_time
print (run_time)

Disappointingly easy compared to some of the problems solved by many more people?

Ruby by ctd

Runtime: 10ms

sum = 37107287533902102798797998220837590246510135740250 \
	 + 46376937677490009712648124896970078050417018260538 \
	 + 74324986199524741059474233309513058123726617309629 \
	 + 91942213363574161572522430563301811072406154908250 \
	 + 23067588207539346171171980310421047513778063246676 \
	 + 89261670696623633820136378418383684178734361726757 \
	 + 28112879812849979408065481931592621691275889832738 \
	 + 44274228917432520321923589422876796487670272189318 \
	 + 47451445736001306439091167216856844588711603153276 \
        # etc...
	 + 53503534226472524250874054075591789781264330331690; 
puts sum.to_s()[0,10]
Personal tools