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


Groups > comp.lang.forth > #41884

Re: Strings and numbers

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.forth
Subject Re: Strings and numbers
Date Wed, 09 Sep 2015 00:41:43 -0700
Organization A noiseless patient Spider
Lines 25
Message-ID <877fo0t4y0.fsf@jester.gateway.pace.com> (permalink)
References <d0c75445-60e3-402a-93a5-8f68501b28ba@googlegroups.com> <87egjjk8kn.fsf@jester.gateway.sonic.net> <bc852ff3-f547-4e0c-ab68-72b3e9c25618@googlegroups.com> <mq1tq2$jv0$1@dont-email.me> <msccfm$c7p$1@dont-email.me> <mskosf$1tr$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="4a8d07ad1a0f5884bbd8208f7dcd0e0f"; logging-data="4343"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zmy/urmNjjYhJeFBepaLm"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:HipbnAJuIQTILhTTe7s1CnNWUQw= sha1:b8lr1qBEd4s/CHjsSjMcexwlQ0g=
Xref csiph.com comp.lang.forth:41884

Show key headers only | View raw


"WJ" <w_a_x_man@yahoo.com> writes:
>> > > http://programmingpraxis.com/2015/07/21/a-number-puzzle/#comments
> No one has yet posted a Forth solution.

\ http://programmingpraxis.com/2015/07/21/a-number-puzzle

: .bit ( i -- n ) 1 swap lshift ;	   \ bits are numbered from 0
: clear-bit ( n i -- n ) .bit invert and ;	  \ clear bit i in n
: test-bit ( n i -- flag ) .bit and 0<> ;	  \ true if bit i is 1
: append-digit ( n i -- n ) swap 10 * + ;

: num { r n s -- n }
    s 0= if n else
	10 0 do 
	    n i append-digit
	    s i test-bit
	    over r mod 0= and if
		r 1+ swap  s i clear-bit recurse
	    else drop
	    then
	loop
    then ;

: go 1 0 $3ff num . ;
go

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


Thread

Strings and numbers Steve Graham <solitary.wanderer52@gmail.com> - 2015-08-03 13:24 -0700
  Re: Strings and numbers Julian Fondren <julian.fondren@gmail.com> - 2015-08-03 13:51 -0700
    Re: Strings and numbers "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-08-03 17:38 -0400
    Re: Strings and numbers Steve Graham <solitary.wanderer52@gmail.com> - 2015-08-03 14:44 -0700
  Re: Strings and numbers Paul Rubin <no.email@nospam.invalid> - 2015-08-03 20:59 -0700
    Re: Strings and numbers Steve Graham <solitary.wanderer52@gmail.com> - 2015-08-04 12:19 -0700
      Re: Strings and numbers "WJ" <w_a_x_man@yahoo.com> - 2015-08-07 09:29 +0000
        Re: Strings and numbers "WJ" <w_a_x_man@yahoo.com> - 2015-09-04 15:14 +0000
          Re: Strings and numbers "WJ" <w_a_x_man@yahoo.com> - 2015-09-07 19:34 +0000
            Re: Strings and numbers Julian Fondren <julian.fondren@gmail.com> - 2015-09-08 11:48 -0700
            Re: Strings and numbers Paul Rubin <no.email@nospam.invalid> - 2015-09-09 00:41 -0700
              Re: Strings and numbers Richard Todd <richard.wesley.todd@gmail.com> - 2015-09-10 00:32 -0700
                Re: Strings and numbers Richard Todd <richard.wesley.todd@gmail.com> - 2015-09-10 10:29 -0700
                Re: Strings and numbers Paul Rubin <no.email@nospam.invalid> - 2015-09-10 17:22 -0700
                Re: Strings and numbers Richard Todd <richard.wesley.todd@gmail.com> - 2015-09-10 21:34 -0700
                Re: Strings and numbers humptydumpty <ouatubi@gmail.com> - 2015-09-11 02:16 -0700
                Re: Strings and numbers humptydumpty <ouatubi@gmail.com> - 2015-09-11 07:33 -0700
                Re: Strings and numbers Paul Rubin <no.email@nospam.invalid> - 2015-09-13 00:12 -0700
                Re: Strings and numbers humptydumpty <ouatubi@gmail.com> - 2015-09-13 02:09 -0700
                Re: Strings and numbers Paul Rubin <no.email@nospam.invalid> - 2015-09-11 15:53 -0700
                Re: Strings and numbers Andrew Haley <andrew29@littlepinkcloud.invalid> - 2015-12-18 16:02 -0600
            Re: Strings and numbers "WJ" <w_a_x_man@yahoo.com> - 2015-09-12 23:38 +0000
              Re: Strings and numbers "WJ" <w_a_x_man@yahoo.com> - 2015-09-13 19:41 +0000
            Re: Strings and numbers "WJ" <w_a_x_man@yahoo.com> - 2015-11-29 18:09 +0000

csiph-web