First power of 2 that has leading decimal digits of 12: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) m (Added Delphi reference to Pascal code) |
|||
Line 671: | Line 671: | ||
p l n = ([-1 ..] >>= f) !! pred n |
p l n = ([-1 ..] >>= f) !! pred n |
||
where |
where |
||
digitCount = |
digitCount = |
||
⚫ | |||
logBase 10 (fromIntegral l :: Float) |
|||
log10pwr = logBase 10 2 |
log10pwr = logBase 10 2 |
||
f raised = |
f raised = [ds | l == ds] |
||
⚫ | |||
⚫ | |||
where |
where |
||
ds = |
ds = |
||
floor $ |
floor $ |
||
10 |
|||
** ( snd |
|||
⚫ | |||
( properFraction $ |
|||
log10pwr * realToFrac raised |
|||
) |
|||
⚫ | |||
⚫ | |||
main :: IO () |
main :: IO () |
||
Line 686: | Line 691: | ||
mapM_ |
mapM_ |
||
(\(l, n) -> printf "p(%d, %d) = %d\n" l n (p l n)) |
(\(l, n) -> printf "p(%d, %d) = %d\n" l n (p l n)) |
||
[ (12, 1), |
|||
[(12, 1), (12, 2), (123, 45), (123, 12345), (123, 678910)]</lang> |
|||
(12, 2), |
|||
(123, 45), |
|||
(123, 12345), |
|||
(123, 678910) |
|||
]</lang> |
|||
{{out}} |
{{out}} |