Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Minimum number of select-all/copy/paste steps for a string containing n copies of the original

This challenge is based on this Mathematics answer.

Write the shortest program or function that, when given some natural number \$n\$, outputs \$S(n)\$, which is the minimum number of steps for generating a string containing at least \$n\$ copies of the original string, using only select-all, copy, and paste operations.

In the Mathematics answer, \$S(n)\$ is found to satisfy the formula

$$ S(n) = \min_{i=1, \ldots, 8} 5 \lceil \log_4(n/u_i) \rceil+c_i $$ where \$(c_i, u_i)\$ is a tuple from the set of tuples \$ I = \{ (0,1), (3,2), (7,6), (4,3), (8,9), (12,27), (16,81), (6,5) \}\$.

Test Cases

1 => 0
2 => 3
4 => 5
8 => 8
16 => 10
32 => 13
64 => 15
128 => 18
256 => 20
512 => 23
1024 => 25
2048 => 28
4096 => 30
8192 => 33
16384 => 35
32768 => 38
65536 => 40
131072 => 43
262144 => 45
524288 => 48
1048576 => 50
2097152 => 53
100000 => 42

Answer

Cancel

-