Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #50501
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Rosetta Code: Happy numbers |
| Date | 2016-08-26 18:07 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <87y43jow83.fsf@jester.gateway.pace.com> (permalink) |
| References | <npqefl$l8o$1@dont-email.me> |
"WJ" <w_a_x_man@yahoo.com> writes:
> $memory = Hash.new
> def happy? n, seq=[]
> result =
> if $memory.include?(n)
> ... many more lines of crap bloaty code
Bleccch, how tasteless.
: ssd ( n -- n ) 0 swap \ sum of squares of digits
begin dup while 10 /mod swap dup * rot + swap repeat drop ;
: happy ( n -- flag ) dup begin ssd swap ssd ssd swap 2dup = until drop 1 = ;
: go ( n -- ) 0 swap 0 do begin 1+ dup happy until dup . loop ;
15 go =>
15 go 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 ok
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread
Rosetta Code: Happy numbers "WJ" <w_a_x_man@yahoo.com> - 2016-08-26 22:05 +0000 Re: Rosetta Code: Happy numbers Paul Rubin <no.email@nospam.invalid> - 2016-08-26 18:07 -0700
csiph-web