Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #50501
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Paul Rubin <no.email@nospam.invalid> |
| Newsgroups | comp.lang.forth |
| Subject | Re: Rosetta Code: Happy numbers |
| Date | Fri, 26 Aug 2016 18:07:40 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 16 |
| Message-ID | <87y43jow83.fsf@jester.gateway.pace.com> (permalink) |
| References | <npqefl$l8o$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="590ea01354cf4bcbcd857d7ebbd88128"; logging-data="15772"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zhUUAfHrDA8hZgSj1mcJg" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:PzCUdVd4srw8pbzv6UNHBtZHncs= sha1:Nyfyb4l0UfW+ay5WFkGDcAEE6eE= |
| Xref | csiph.com comp.lang.forth:50501 |
Show key headers only | View raw
"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