In Bgil Midol's question, the score of a sequence of slice is defined as
sumof|startslices|∗2+sumof|endslices|∗2+sumof|stepslices|∗3
Such scoring method makes multiple slices possibly take less score, e.g.
[::25]
75[::5][::5]
30
Given the length of a string, an upper bound of number of slices1, and the one slice it equals to2, output a way of slicing with lowest score. You can assume that the result after slicing isn't empty.
6 1 [3:4] -> [3:-2]
6 9 [3:4] -> [:-2][-1:]
1000 1 [::25] -> [::25]
1000 2 [::25] -> [::5][::5]
1000 9 [1::25] -> [1::5][::5]
1000 9 [5::25] -> [::5][1::5]
9100 9 [90::91] -> [::-91][::-1]
Shortest code in each language wins.
1. Notice that [:]
is a valid slice with no effect to score
2. It can be proven that every sequence of slice can equal to one slice for a fixed string before slice
[::-2][::-1]
? (Similarly, can the input slices contain negative indices?) Test cases containing ends should probably also be supplied. \$\endgroup\$[1::2]
or[0::2](==[::2])
depending on the parity of the length of the string \$\endgroup\$startslices
,endslices
, andstepslices
? And what does the[::]
notation mean? This seems underspecified, or at least it requires some background knowledge not provided in the question. \$\endgroup\$