develooper Front page | perl.beginners | Postings from December 2011

working with large integers

Thread Next
From:
Jeswin
Date:
December 29, 2011 08:40
Subject:
working with large integers
Message ID:
CAAhF0RK_5CT-kjy+Mw4Sfj=HwxuVLU70Zs-VZhvtxLZ-S8ceqw@mail.gmail.com
Hi,
I'm doing one of the Project Euler exercises which asks the sum of 100
fifty-digit numbers[1]. My code is 2 parts:

I open the text file containing the digits and put into an array:
========================BEGIN_CODE=========================
open (F, "Fifty_hundred.txt") || die "Could not open Fifty_hundred.txt: $!\n";

@numbers = <F>;
close F;
========================END_CODE===========================

Next I sum the values in the array:
========================BEGIN_CODE=========================
$sum = 0;
for (@numbers) {
    $sum += $_;
}
========================END_CODE===========================

I get an answer but its wrong (according to Project Euler). Now I am
looking into the BigNum functions but I am not sure how they work and
don't really know how to use it.

Thanks



Reference:
[1] http://projecteuler.net/problem=13

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About