Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #58370
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta: Count in factors |
| Date | 2017-04-29 22:01 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <oe32ge$cr3$1@gioia.aioe.org> (permalink) |
> Task
>
> Write a program which counts up from 1, displaying each
> number as the multiplication of its prime factors.
>
> For the purpose of this task, 1 (unity) may be shown as itself.
>
>
> Example
>
> 2 is prime, so it would be shown as itself.
> 6 is not prime; it would be shown as 2 x 3
> 2144 is not prime; it would be shown as 2 x 2 x 2 x 2 x 2 x 67
require 'prime'
puts " 1: 1" ;
(2..23).each{|n|
printf "%2d: %s\n", n,
Prime.prime_division(n).map{|f,c| ([f]*c).join ' x '}.join(' x ')
}
1: 1
2: 2
3: 3
4: 2 x 2
5: 5
6: 2 x 3
7: 7
8: 2 x 2 x 2
9: 3 x 3
10: 2 x 5
11: 11
12: 2 x 2 x 3
13: 13
14: 2 x 7
15: 3 x 5
16: 2 x 2 x 2 x 2
17: 17
18: 2 x 3 x 3
19: 19
20: 2 x 2 x 5
21: 3 x 7
22: 2 x 11
23: 23
In Forth?
--
Amazon bans book after it received 300 5-star reviews.
http://www.tomatobubble.com/worldwarii.html
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Rosetta: Count in factors "Robert L." <No_spamming@noWhere_7073.org> - 2017-04-29 22:01 +0000
csiph-web