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


Groups > comp.lang.forth > #24192

Re: project euler problems in forth

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail
From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Re: project euler problems in forth
Date Sat, 6 Jul 2013 05:31:32 +0000 (UTC)
Organization A noiseless patient Spider
Lines 40
Message-ID <kr8a3i$efv$1@dont-email.me> (permalink)
References <2f19628a-24d6-4480-85af-f081e9208643@googlegroups.com> <khldd4$576$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-1
Injection-Date Sat, 6 Jul 2013 05:31:32 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="965e626b16a3aac771d408edfb64bee6"; logging-data="14847"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18t9p2/OgT4IFh3VDdH2Gv+"
User-Agent XanaNews/1.18.1.6
X-Antivirus-Status Clean
X-Antivirus avast! (VPS 130705-1, 07/05/2013), Outbound message
Cancel-Lock sha1:QIoS/dZzcd4zKfj4uyAPLYLT37A=
Xref csiph.com comp.lang.forth:24192

Show key headers only | 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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

project euler problems in forth bob wilkinson <wilkinson.bob@gmail.com> - 2013-03-11 03:25 -0700
  Re: project euler problems in forth m.a.m.hendrix@tue.nl - 2013-03-11 04:32 -0700
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 11:31 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-06-14 15:50 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 12:13 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 12:26 +0000
      Re: project euler problems in forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-03-11 10:13 -0500
        Re: project euler problems in forth Doug Hoffman <glidedog@gmail.com> - 2013-03-11 11:34 -0400
          Re: project euler problems in forth The Beez <the.beez.speaks@gmail.com> - 2013-03-11 14:43 -0700
            Re: project euler problems in forth Doug Hoffman <glidedog@gmail.com> - 2013-03-12 04:50 -0400
  Re: project euler problems in forth Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-03-11 12:46 +0000
    Re: project euler problems in forth Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-03-11 12:56 +0000
  Re: project euler problems in forth albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-03-11 12:43 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 12:49 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 19:44 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 13:54 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 20:04 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-07-06 05:31 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 20:19 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 20:44 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-11 23:00 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-07-06 05:47 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-12 00:15 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-12 00:46 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-12 01:06 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-07-06 06:13 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-12 02:29 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-06-18 10:44 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-07-06 05:51 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-12 03:09 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-06-18 16:16 +0000
      Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-06-18 16:21 +0000
  Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-03-12 09:45 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-06-18 11:51 +0000
    Re: project euler problems in forth "WJ" <w_a_x_man@yahoo.com> - 2013-07-06 05:53 +0000

csiph-web