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


Groups > comp.lang.forth > #24192

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:31 +0000
Organization A noiseless patient Spider
Message-ID <kr8a3i$efv$1@dont-email.me> (permalink)
References <2f19628a-24d6-4480-85af-f081e9208643@googlegroups.com> <khldd4$576$1@dont-email.me>

Show all headers | View raw


WJ wrote:

> > Find the difference between the sum of the squares of the first
> > one hundred natural numbers and the square of the sum.
> > 
> > 006.fs
> > 
> > #! /usr/bin/gforth
> > 
> > : sumsq  ( n -- sumsq )
> > ( returns the sum of the square of all integers to n )
> > 0 swap 1+ 0 do
> >   i dup * + 
> > loop
> > ;
> > 
> > : sqsum ( n -- sqsum )
> > ( returns the square of the sum of all integers to n )
> > dup 1+ * 2 / dup *
> > ;
> > 
> > : pe006 ( -- )
> > 100 dup sqsum swap sumsq - . cr
> > ;
> > 
> > pe006
> 
> Factor:
> 
> USING: math.ranges ;
> 
> 101 100 * 2/ sq
> 100 [1,b] 0 [ sq + ] reduce - .
> 25164150

Julia:

julia> square( sum(1:100) ) - sum( map(square, 1:100) )
25164150

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:31 +0000

csiph-web