On Sat, 29 Apr 2017 22:05:16 +0000, Robert L. wrote: >> 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
It does not help a student if you do their homework for them, much better to provide hints & guidance -- Why do mathematicians insist on using words that already have another meaning? "It is the complex case that is easier to deal with." "If it doesn't happen at a corner, but at an edge, it nonetheless happens at a corner." -- https://mail.python.org/mailman/listinfo/python-list