Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #24194

Re: project euler problems in forth

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Re: project euler problems in forth
Date 2013-07-06 05:51 +0000
Organization A noiseless patient Spider
Message-ID <kr8b82$ij3$1@dont-email.me> (permalink)
References <2f19628a-24d6-4480-85af-f081e9208643@googlegroups.com> <khm3up$nac$1@dont-email.me>

Show all headers | View raw


WJ wrote:

> > Find the sum of the digits in the number 100!
> 
> 
> Factor:
> 
> USING: math.ranges math.parser grouping ;
> 
> : factorial ( m -- n )
>   [1,b] 1 [ * ] reduce ;
> 
> : prob20 ( -- n )
>   100 factorial number>string  1 group
>   0 [ string>number + ] reduce ;
> 
> prob20 .
> 648

Julia:

julia> mapreduce(int, +, split( repr (factorial(BigInt(100))), ""))
648

Back to comp.lang.forth | Previous | Next | Find similar


Thread

Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-07-06 05:51 +0000

csiph-web