First power of 2 that has leading decimal digits of 12: Difference between revisions
Content deleted Content added
→{{header|Go}}: Added translation of alternative Pascal version. |
Add Factor |
||
Line 37:
__TOC__
=={{header|Factor}}==
A translation of the first Pascal example:
{{trans|Pascal}}
{{works with|Factor|0.99 2019-10-06}}
<lang factor>USING: formatting fry generalizations kernel literals math
math.functions math.parser sequences tools.time ;
CONSTANT: ld10 $[ 2 log 10 log / ]
: p ( L n -- m )
swap [ 0 0 ]
[ '[ over _ >= ] ]
[ [ log10 >integer 10^ ] keep ] tri*
'[
1 + dup ld10 * dup >integer - 10 log * e^ _ * truncate
_ number= [ [ 1 + ] dip ] when
] until nip ;
[
12 1
12 2
123 45
123 12345
123 678910
[ 2dup p "%d %d p = %d\n" printf ] 2 5 mnapply
] time</lang>
{{out}}
<pre>
12 1 p = 7
12 2 p = 80
123 45 p = 12710
123 12345 p = 3510491
123 678910 p = 193060223
Running time: 44.208249282 seconds
</pre>
=={{header|Go}}==
|