输入:
我们接受两个输入:
b
具有两个不同值的输入:Left
和Right
。†- 和一个正整数
n
。
输出:
基于向左/向右输入,我们输出范围内的以下两个序列之一1-n
(在显示前125个项目的序列以下):
Left:
1, 6, 7, 56, 57, 62, 63, 960, 961, 966, 967, 1016, 1017, 1022, 1023, 31744, 31745, 31750, 31751, 31800, 31801, 31806, 31807, 32704, 32705, 32710, 32711, 32760, 32761, 32766, 32767, 2064384, 2064385, 2064390, 2064391, 2064440, 2064441, 2064446, 2064447, 2065344, 2065345, 2065350, 2065351, 2065400, 2065401, 2065406, 2065407, 2096128, 2096129, 2096134, 2096135, 2096184, 2096185, 2096190, 2096191, 2097088, 2097089, 2097094, 2097095, 2097144, 2097145, 2097150, 2097151, 266338304, 266338305, 266338310, 266338311, 266338360, 266338361, 266338366, 266338367, 266339264, 266339265, 266339270, 266339271, 266339320, 266339321, 266339326, 266339327, 266370048, 266370049, 266370054, 266370055, 266370104, 266370105, 266370110, 266370111, 266371008, 266371009, 266371014, 266371015, 266371064, 266371065, 266371070, 266371071, 268402688, 268402689, 268402694, 268402695, 268402744, 268402745, 268402750, 268402751, 268403648, 268403649, 268403654, 268403655, 268403704, 268403705, 268403710, 268403711, 268434432, 268434433, 268434438, 268434439, 268434488, 268434489, 268434494, 268434495, 268435392, 268435393, 268435398, 268435399, 268435448, 268435449
Right:
1, 4, 7, 32, 39, 56, 63, 512, 527, 624, 639, 896, 911, 1008, 1023, 16384, 16415, 16864, 16895, 19968, 19999, 20448, 20479, 28672, 28703, 29152, 29183, 32256, 32287, 32736, 32767, 1048576, 1048639, 1050560, 1050623, 1079296, 1079359, 1081280, 1081343, 1277952, 1278015, 1279936, 1279999, 1308672, 1308735, 1310656, 1310719, 1835008, 1835071, 1836992, 1837055, 1865728, 1865791, 1867712, 1867775, 2064384, 2064447, 2066368, 2066431, 2095104, 2095167, 2097088, 2097151, 134217728, 134217855, 134225792, 134225919, 134471680, 134471807, 134479744, 134479871, 138149888, 138150015, 138157952, 138158079, 138403840, 138403967, 138411904, 138412031, 163577856, 163577983, 163585920, 163586047, 163831808, 163831935, 163839872, 163839999, 167510016, 167510143, 167518080, 167518207, 167763968, 167764095, 167772032, 167772159, 234881024, 234881151, 234889088, 234889215, 235134976, 235135103, 235143040, 235143167, 238813184, 238813311, 238821248, 238821375, 239067136, 239067263, 239075200, 239075327, 264241152, 264241279, 264249216, 264249343, 264495104, 264495231, 264503168, 264503295, 268173312, 268173439, 268181376, 268181503, 268427264, 268427391
您问这些序列是如何产生的?
从1到默认序列n=10
为:
As integer:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
As binary:
1 10 11 100 101 110 111 1000 1001 1010
当我们向左伸展时,二进制文件将变为:
1, 110, 111, 111000, 111001, 111110, 111111, 1111000000, 1111000001, 1111000110
为什么?最后一位仅使用一次;单-使用两次;倒数第二次使用了3次;等等
So `1010` will become (spaces added as clarification): `1111 000 11 0`
这些新的向左拉伸的二进制字符串将转换回整数:
1, 6, 7, 56, 57, 62, 63, 960, 961, 966
至于右延伸,第一位只使用一次;第二次 第三三遍;像这样:
As binary:
1, 100, 111, 100000, 100111, 111000, 111111, 1000000000, 1000001111, 1001110000
As integer:
1, 4, 7, 32, 39, 56, 63, 512, 527, 624
挑战规则:
- †您可以采用任意两个不同的值,但请说明使用哪个。因此,它可以是
1/0
,true/false
,null/undefined
,"left"/"right"
,等。 n
始终大于0。- 您应支持的最大输出量至少为您语言的默认整数(大多数语言为32位)。
- 输出格式灵活。可以打印或作为数组/列表返回。可以使用空格,逗号,管道等作为分隔符。你的来电。(再次,请说明您的使用习惯。)
n < 128
,以使结果适合32位整数?