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


Groups > comp.lang.forth > #53539

Re: Challenge for Christmas

From Gerry Jackson <gerry@jackson9000.fsnet.co.uk>
Newsgroups comp.lang.forth
Subject Re: Challenge for Christmas
Date 2016-12-26 07:44 +0000
Organization A noiseless patient Spider
Message-ID <o3qhm8$vch$1@dont-email.me> (permalink)
References <26197516-a481-4262-a604-5cae2c7dc49a@googlegroups.com> <2016Dec25.175253@mips.complang.tuwien.ac.at> <c87c7c04-7c90-4d38-84d2-996c42c27f1f@googlegroups.com> <o3p28k$65t$1@dont-email.me> <c7d95ba0-e963-4e9f-87e0-05d37194ffb7@googlegroups.com>

Show all headers | View raw


On 25/12/2016 21:21, lehs wrote:
> I'm afraid non of the solutions above are correct. Try the buffer 3,6,15 for example. Neither solution gives the correct answer for u=6 or u=18. As far as I can see.
>

As NN points out, reverse the order. Only minor changes are needed

create vec 3 , 6 , 15 , here 1 cells - constant end-vec

: factor?   ( u u2 -- u3)
    >r                            ( -- u  ) ( R: -- u2 )
    begin
       dup r@ /mod swap 0=        ( -- u quot rem=0 )
    while                         ( -- u quot )
       nip                        ( -- quot)
    repeat
    r> 2drop                      ( -- u' )
;

: is-a-product  ( u ad1 ad2 -- f )
    do
       i @            ( -- u u2 )
       factor?        ( -- u' )
       -1 cells
    +loop
    1 =
;

: go ( u -- ) vec end-vec is-a-product if ." yes" else ." no" then ;

6 go  yes ok
18 go  yes ok

-- 
Gerry

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-24 06:10 -0800
  Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-24 14:17 -0800
    Re: Challenge for Christmas mhx@iae.nl - 2016-12-24 15:37 -0800
    Re: Challenge for Christmas mhx@iae.nl - 2016-12-24 15:43 -0800
    Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 01:25 -0800
      Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-25 06:59 -0800
        Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 07:26 -0800
          Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-25 07:57 -0800
            Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 08:07 -0800
              Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-25 08:25 -0800
  Challenge for Christmas Ilya Tarasov <ilya74.tarasov@gmail.com> - 2016-12-25 07:39 -0800
  Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-25 16:52 +0000
    Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 09:33 -0800
      Re: Challenge for Christmas Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-12-25 18:15 +0000
        Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-25 13:21 -0800
          Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-25 16:51 -0800
            Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 00:48 -0800
              Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 01:36 -0800
              Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 01:39 -0800
                Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-26 04:36 -0800
                Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 07:40 -0800
                Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-26 15:53 +0000
                Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 08:57 -0800
                Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-27 13:12 +0000
                Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-27 16:58 +0100
                Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-27 16:01 +0000
                Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-27 19:10 +0100
                Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-27 18:08 +0000
                Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-27 20:13 +0100
                Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-28 08:19 +0000
                Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-28 12:49 +0100
                Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-28 14:26 +0000
                Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-29 13:13 +0000
                Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-27 12:29 -0800
                Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-27 22:25 +0100
                Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-27 14:19 -0800
                Re: Challenge for Christmas november.nihal@gmail.com - 2016-12-27 14:14 -0800
                Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-28 11:06 +0000
                Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-28 04:22 -0800
              Re: Challenge for Christmas john <anon@example.com> - 2016-12-26 13:05 +0000
                Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 07:45 -0800
          Re: Challenge for Christmas Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-12-26 07:44 +0000
        Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-26 13:21 +0000
          Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-26 13:57 +0000
            Re: Challenge for Christmas anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-26 14:58 +0000
  Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-26 17:24 +0100
    Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 09:15 -0800
    Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-26 11:45 -0800
    Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-30 10:47 -0800
      Re: Challenge for Christmas albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-31 15:31 +0100
        Re: Challenge for Christmas lehs <skydda.barnen@gmail.com> - 2016-12-31 10:53 -0800

csiph-web