Humble numbers: Difference between revisions

→‎{{header|Factor}}: more efficient counting; keep track of next digit threshold instead of calling log10 on 20 million numbers
(→‎{{header|Factor}}: more efficient counting; keep track of next digit threshold instead of calling log10 on 20 million numbers)
Line 39:
IN: rosetta-code.humble-numbers
TUPLE: humble-iterator 2s 3s 5s 7s digits ;
{ #digits initial: 1 } { target initial: 10 } ;
: <humble-iterator> ( -- humble-iterator )
Line 58 ⟶ 59:
 
: count-digits ( humble-iterator n -- )
[ over target>> >=
[ 1 ] 2dip log10 1 + >integer swap digits>> at+ ;
[ [ 1 + ] change-#digits [ 10 * ] change-target ] when ]
[ drop 1 swap [ #digits>> ] [ digits>> ] bi at+ ] bi ;
 
: ?pop ( 2s 3s 5s 7s n -- )
Line 179 ⟶ 182:
Total number of humble numbers found: 21,307,183
</pre>
 
=={{header|Go}}==
Not particularly fast and uses a lot of memory but easier to understand than the 'log' based methods for generating 7-smooth numbers.
1,827

edits