ngw@nofeed.org wrote:
The task was "Write a program that prints a
multiplication table of primes numbers."
require 'prime'
def prime_mul_table n
a = Prime.take(n)
width = (a[-1]**2).to_s.size
matrix = [" ",*a].zip((a + a.product(a).map{|m,n| m*n}).each_slice(n)).
map{|x,xs| [x,*xs].map{|x| x.to_s.rjust(width)}.join " "}
end
prime_mul_table(12).each{|r| puts r}
2 3 5 7 11 13 17 19 23 29 31 37
2 4 6 10 14 22 26 34 38 46 58 62 74
3 6 9 15 21 33 39 51 57 69 87 93 111
5 10 15 25 35 55 65 85 95 115 145 155 185
7 14 21 35 49 77 91 119 133 161 203 217 259
11 22 33 55 77 121 143 187 209 253 319 341 407
13 26 39 65 91 143 169 221 247 299 377 403 481
17 34 51 85 119 187 221 289 323 391 493 527 629
19 38 57 95 133 209 247 323 361 437 551 589 703
23 46 69 115 161 253 299 391 437 529 667 713 851
29 58 87 145 203 319 377 493 551 667 841 899 1073
31 62 93 155 217 341 403 527 589 713 899 961 1147
37 74 111 185 259 407 481 629 703 851 1073 1147 1369
--
The report card by the American Society of Civil Engineers showed the national infrastructure a single grade above failure, a step from declining to the point where everyday things simply stop working the way people expect them to. --- washingtonpost.com/local/trafficandcommuting/us-infrastructure-gets-d-in-annual-report/2013/03/19/c48cb010-900b-11e2-9cfd-36d6c9b5d7ad_story.html
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)