首先,1
您可以重复执行以下两个操作之一:
将数字加倍。
要么
以任何您想要的方式重新排列其数字,但不得有任何前导零。
以链接的Math.SE帖子为例,我们可以1000
通过以下步骤进行操作:
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 125, 250, 500, 1000
您可以通过此过程获得哪些数字,最短的解决方案是什么?
挑战
给定正整数,如果可能的话N
,确定N
上述过程可以达到的最短整数序列。如果有几个最佳解决方案,请输出其中任何一个。如果不存在这样的序列,则应输出一个空列表。
该序列可以采用任何方便,明确的字符串或列表格式。
您可以编写程序或函数,通过STDIN(或最接近的替代方案),命令行参数或函数自变量获取输入,并通过STDOUT(或最接近的替代方案),函数返回值或函数(out)参数输出结果。
这是代码高尔夫球,因此最短的答案(以字节为单位)获胜。
测试用例
这是所有可达的数字列表,最大为256,包括256。第一列是数字(您的输入),第二列是最佳步骤数(可用于检查解决方案的有效性),第三列是专栏是到达那里的一种最佳顺序:
1 1 {1}
2 2 {1,2}
4 3 {1,2,4}
8 4 {1,2,4,8}
16 5 {1,2,4,8,16}
23 7 {1,2,4,8,16,32,23}
29 10 {1,2,4,8,16,32,23,46,92,29}
32 6 {1,2,4,8,16,32}
46 8 {1,2,4,8,16,32,23,46}
58 11 {1,2,4,8,16,32,23,46,92,29,58}
61 6 {1,2,4,8,16,61}
64 7 {1,2,4,8,16,32,64}
85 12 {1,2,4,8,16,32,23,46,92,29,58,85}
92 9 {1,2,4,8,16,32,23,46,92}
104 15 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,104}
106 14 {1,2,4,8,16,32,64,128,256,265,530,305,610,106}
107 14 {1,2,4,8,16,32,23,46,92,29,58,85,170,107}
109 18 {1,2,4,8,16,32,23,46,92,184,368,386,772,277,554,455,910,109}
116 12 {1,2,4,8,16,32,23,46,92,29,58,116}
122 7 {1,2,4,8,16,61,122}
124 16 {1,2,4,8,16,32,23,46,92,29,58,85,170,107,214,124}
125 11 {1,2,4,8,16,32,64,128,256,512,125}
128 8 {1,2,4,8,16,32,64,128}
136 18 {1,2,4,8,16,32,23,46,92,184,148,296,592,259,518,158,316,136}
140 15 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,140}
142 16 {1,2,4,8,16,32,23,46,92,29,58,85,170,107,214,142}
145 17 {1,2,4,8,16,32,23,46,92,184,368,736,376,752,257,514,145}
146 18 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,104,208,416,146}
148 11 {1,2,4,8,16,32,23,46,92,184,148}
149 16 {1,2,4,8,16,32,64,128,182,364,728,287,574,457,914,149}
152 11 {1,2,4,8,16,32,64,128,256,512,152}
154 17 {1,2,4,8,16,32,23,46,92,184,368,736,376,752,257,514,154}
158 16 {1,2,4,8,16,32,23,46,92,184,148,296,592,259,518,158}
160 14 {1,2,4,8,16,32,64,128,256,265,530,305,610,160}
161 13 {1,2,4,8,16,32,23,46,92,29,58,116,161}
163 18 {1,2,4,8,16,32,23,46,92,184,148,296,592,259,518,158,316,163}
164 18 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,104,208,416,164}
166 20 {1,2,4,8,16,32,23,46,92,184,368,736,376,752,257,514,154,308,616,166}
167 17 {1,2,4,8,16,32,23,46,92,184,148,296,269,538,358,716,167}
169 23 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,104,208,416,461,922,229,458,916,169}
170 13 {1,2,4,8,16,32,23,46,92,29,58,85,170}
176 17 {1,2,4,8,16,32,23,46,92,184,148,296,269,538,358,716,176}
182 9 {1,2,4,8,16,32,64,128,182}
184 10 {1,2,4,8,16,32,23,46,92,184}
185 16 {1,2,4,8,16,32,23,46,92,184,148,296,592,259,518,185}
188 23 {1,2,4,8,16,32,23,46,92,184,148,296,592,259,518,185,370,740,470,940,409,818,188}
190 18 {1,2,4,8,16,32,23,46,92,184,368,386,772,277,554,455,910,190}
194 16 {1,2,4,8,16,32,64,128,182,364,728,287,574,457,914,194}
196 23 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,104,208,416,461,922,229,458,916,196}
203 16 {1,2,4,8,16,32,64,128,256,265,530,305,610,160,320,203}
205 13 {1,2,4,8,16,32,64,128,256,512,125,250,205}
208 16 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,104,208}
209 19 {1,2,4,8,16,32,23,46,92,184,368,736,376,752,257,514,145,290,209}
212 8 {1,2,4,8,16,61,122,212}
214 15 {1,2,4,8,16,32,23,46,92,29,58,85,170,107,214}
215 11 {1,2,4,8,16,32,64,128,256,512,215}
218 9 {1,2,4,8,16,32,64,128,218}
221 8 {1,2,4,8,16,61,122,221}
223 14 {1,2,4,8,16,32,23,46,92,29,58,116,232,223}
227 20 {1,2,4,8,16,32,23,46,92,184,148,296,592,259,518,158,316,361,722,227}
229 20 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,104,208,416,461,922,229}
230 16 {1,2,4,8,16,32,64,128,256,265,530,305,610,160,320,230}
232 13 {1,2,4,8,16,32,23,46,92,29,58,116,232}
233 22 {1,2,4,8,16,32,23,46,92,184,368,736,376,752,257,514,154,308,616,166,332,233}
235 19 {1,2,4,8,16,32,23,46,92,184,148,296,269,538,358,716,176,352,235}
236 19 {1,2,4,8,16,32,23,46,92,184,148,296,592,259,518,158,316,632,236}
238 19 {1,2,4,8,16,32,64,128,256,512,125,250,205,410,104,208,416,832,238}
239 25 {1,2,4,8,16,32,23,46,92,184,368,736,376,752,257,514,154,308,616,166,332,233,466,932,239}
241 16 {1,2,4,8,16,32,23,46,92,29,58,85,170,107,214,241}
244 8 {1,2,4,8,16,61,122,244}
247 21 {1,2,4,8,16,32,23,46,92,184,148,296,592,259,518,158,316,632,362,724,247}
248 17 {1,2,4,8,16,32,23,46,92,29,58,85,170,107,214,124,248}
250 12 {1,2,4,8,16,32,64,128,256,512,125,250}
251 11 {1,2,4,8,16,32,64,128,256,512,251}
253 19 {1,2,4,8,16,32,23,46,92,184,148,296,269,538,358,716,176,352,253}
256 9 {1,2,4,8,16,32,64,128,256}
如果您想要更多的测试数据,请使用以下表格,最多1000张,包括1000张。
这些表上未出现的任何数字都应产生一个空列表(前提是该数字在表的范围内)。