# Exponentiation Sequence

The oldest Polish salt mine, located in Bochnia*, was started in year 1248, which we can consider a magical number. We can see that it's equal to 4 digits from the sequence of exponentiations: .

As the date is actually 4 digits from the sequence, we could make it longer. We could repeat the process until we reach infinity. The sequence would look like this, if we limit it to number 2048

124816326412825651210242048


To make it look a bit better, we can separate the numbers:

1|2|4|8|16|32|64|128|256|512|1024|2048


Let's try a custom, longer sequence than the date. Let's say, we want it to have 5 digits - there are more than one possibility:

• 24816
• 81632
• 64128

Or 3 digit ones:

• 124
• 248
• 816

We could also add the 3 digit numbers to this, but let's say, that a sequence must have at least two numbers.

* There is no information about this on the English Wikipedia. If you enter the Polish version - then there is. If you visit the mine, the workers will also tell you, that it started in 1248.

## The challenge

Create a exponentiation sequence like in examples above with 2 as the base.

Given a number from range 2-27, output all possible parts of the sequence (The 2048 one or larger if you want) with amount of digits equal to the input. You cannot cut a number, so output like 481 is invalid, because 16 is cut in half.

Rules:

• Standard loopholes are forbidden.
• You can assume the input is a number inside the range.
• Your program can accept inputs larger than the range (28+), but that won't increase/decrease score.
• Spaces in output are ignored. You can output like 124 or like 4 8 16.
• Different possibilities should be separated by any character from the list: ,./| or a line feed.
• You can output as an array.
• Every possibility should include at least 2 different numbers.
• You must output a part of the sequence, you cannot mix numbers that aren't next to each other, like: 14.
• Hardcoded output isn't allowed, however, you can hardcode a string/number/array containing the full sequence.
• Input 27 should return the full 2048 sequence.
• As already mentioned before, do not cut numbers. Ex. 16 must stay 16 - you can't use 481 - you must use 4816.
• EDIT: I might have said something wrong there; 2048 is the last number which your program should support, you can add support for larger int's.

## Test cases

Input: 2

12, 24, 48


Input: 3

124, 248, 816


Input: 4

1248, 4816, 1632, 3264


Input: 5

24816, 81632, 64128


Input: 27

124816326412825651210242048


And later numbers...

If I made a mistake in any of the test cases, tell me or edit the question.

This is , so the shortest code in bytes wins!

• So this is only with 2 as the base, correct? Could you clarify that in the question? I'm not sure if it's implied by "Sequence of Exponentiations," but even if it is, I'm sure there are people out there like me who don't know that.
– cole
Commented Sep 12, 2017 at 16:56
• @cole Actually, yes, it's only with 2. Thanks for mentioning! Commented Sep 12, 2017 at 16:56
• Can output be separated by newline? Commented Sep 12, 2017 at 17:23
• No worries; like I said, I was pushing it. Some challenge authors can be incredibly flexible on the output format so, for the sake of a byte or 2, it's worth asking ;) (Note: That should not be interpreted as a suggestion!) Commented Sep 13, 2017 at 22:27
• In the intro, you should capitalize Polish. "polish" is a different English word. Commented Sep 17, 2017 at 3:45

# 05AB1E, 1211 10 bytes

Supports the sequence up to 2^95 = 39614081257132168796771975168

₃ÝoŒʒg≠}Jù


Try it online!

Explanation

₃Ý            # push range [0 ... 95]
o           # raise 2 to the power of each
Œ          # get a list of all sublists
ʒ         # filter, keep elements that satisfy:
g        # length
≠       # false (not equal to 1)
}      # end filter
J     # join each
ù    # keep numbers of length matching the input


Saved 1 byte thanks to Erik the Outgolfer
Saved 1 byte thanks to Riley

• X› can be ≠ Commented Sep 13, 2017 at 12:31
• @EriktheOutgolfer: Oh yeah. I always forget that one exist now. Thanks :) Commented Sep 13, 2017 at 12:41
• Can Y₃Ým be ₃Ýo? Commented Sep 13, 2017 at 13:35
• @Riley: Yep. I had that before, but for some reason I must have changed it. Thanks :) Commented Sep 13, 2017 at 13:46
• Trying the code now (much late after challenge end)... and your solution seems to return tons of empty arrays for me... Am I doing something wrong? Commented Nov 13, 2017 at 19:33

# Pyth, 222120 17 bytes

fqQlTjLkt#.:^L2yT


Try it Online

### Explanation

fqQlTjLkt#.:^L2yT
^L2yT  Get the powers of 2 up to 2^20
t#.:       Get all consecutive sequences of at least 2
jLk           Concatenate each
fqQlT              Get the ones whose length is the input

• 21 bytes: fqQlTmjkdftlT.:m^2d12 Commented Sep 12, 2017 at 17:22
• 20 bytes - fqQlTjLkftlT.:m^2d12 Commented Sep 12, 2017 at 17:26
• 19 bytes - fqQlTjLkftT.:m^2d12 Commented Sep 12, 2017 at 19:42
• 18 bytes - fqQlTjLkftT.:^L2yT Commented Sep 12, 2017 at 19:45
• 17 bytes - fqQlTjLkt#.:^L2yT Commented Sep 12, 2017 at 19:49

# Jelly,  19 18  16 bytes

There may be a shorter solution now that we may use any cut-off (not just 2048), although this change to the specification has allowed a one byte save from this implementation by moving to a cut-off of 32768.
--yep...

-2 bytes thanks to Erik the Outgolfer (use of V to allow implicit right argument of the filter and tightening)
--yes it is very similar to his inefficient one now; go upvote his!

⁴Ḷ2*Ẇṫ17VDL$⁼¥Ðf  A monadic link taking a number and returning a list of numbers. Try it online! ### How? ⁴Ḷ2*Ẇṫ17VDL$⁼¥Ðf - Link: number, n        e.g. 3
⁴                - literal sixteen             16
Ḷ               - lowered range               [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
2              - literal two                 2
*             - exponentiate                [1,2,4,8,16,32,...,32768]
Ẇ            - all sublists                [[1],[2],...,[1,2],[2,4],...,[1,2,4],...]
17         - literal seventeen           17
ṫ           - tail from index             [[1,2],[2,4],...,[1,2,4],...]]
V        - evaluate as Jelly code      [12,24,...,124,...]
Ðf - filter keep:
$- last two links as a monad: D - decimal list (of entry) (i.e. 816 -> [8,1,6] or 24 -> [2,4]) L - length (i.e. 816 -> 3, or 24 -> 2) ⁼ - equals (n) (i.e. 816 -> 1, or 24 -> 0) - ...resulting in [816, 124, 248]  • Is this too similar to yours? (please be honest :p) Commented Sep 12, 2017 at 18:47 • Funnily enough I was just trying to use V and it'll work for 16 rather than 1000: ⁴Ḷ2*Ẇṫ17VDL$⁼¥Ðf. Commented Sep 12, 2017 at 18:52
• I'm going for the most :p Commented Sep 12, 2017 at 18:52
• @EriktheOutgolfer they may now be similar but I am of the mind we should both keep them I'm sure you came up with yours independently and I'm sure I'd have found the eval trick too (since I was looking at exactly that, just needed to get the chaining right). Commented Sep 12, 2017 at 19:09
• @EriktheOutgolfer I have made the assumption you are male, and prefer to be referred to as such, but actually do not know either as fact; do let me know if you prefer a different pronoun! Commented Sep 12, 2017 at 19:13

# Perl 6, 62 59 bytes

{grep *.comb==$_,map {[~] 2 X**[...]$_},combinations 12,2}


Try it online!

# Japt, 222019 16 bytes

Supports input up to 639 but gaps start appearing in the sequence after 234 (See the full list of supported input ranges here). Outputs an array of strings.

IÆIo!²ãX m¬lUÃ¤c


Test it

I (64) could be replaced with L (100) but we'd be getting into scientific notation and precision inaccuracies. Filtering those out would, obviously, increase the byte count and only raise the maximum input to 736.

                     :Implicit input of integer U
I                    :64
Æ                   :Map each X in [0,64)
Io                 :  Range [0,64)
!²               :  Raise 2 to the power of each
ãX             :  Subsections of length X
m           :  Map
¬          :    Join
lU        :  Filter elements of length U
Ã       :End map
¤      :Slice off the first 2 elements
c     :Flatten


# Python 2, 105 bytes

lambda l,r=range:[x for x in[''.join(2**nfor n in r(i,j+2))for i in r(13)for j in r(i,11)]if len(x)==l]


Try it online!

# Husk, 18 17 bytes

Output is separated by newlines

fo=⁰LmṁsftQ↑12¡D1


Try it online!

### How?

           ↑12¡D1    The sequence [1,2,4...2048]
¡      Repeatedly apply function, collecting results in a list
D     double
1    initially applying to 1
↑12       Take the first 12 elements
Q          Get all sublists
ft           With a length greater than 1
mṁs             Convert each list into a string, e.g [4,8,16] -> "4816"
fo=⁰L                Keep only those whose length is equal to the input


# Jelly, 16 bytes

ȷḶ2*ẆṫȷḊVDL$⁼¥Ðf  Try it online! Note: very inefficient. Returns a list of numbers. • Tio doesn't seem to be able to parse this code... It always exceeds 60 seconds... Commented Sep 12, 2017 at 18:50 • Commented Sep 12, 2017 at 18:51 • @Soaku it works in theory - it just times out because it is very inefficient. Commented Sep 12, 2017 at 18:53 • @Soaku I meant on my comment. I have already replaced them there, and there's output [12, 24, 48]. Commented Sep 12, 2017 at 18:55 • @Soaku Why not go for the most if you can without extra cost? ;) Commented Sep 13, 2017 at 10:53 # JavaScript (ES7), 102 100 bytes Prints all matching sub-sequences with alert(). l=>[...1e11+''].map((_,k,a)=>a.map((_,x)=>(s=(g=n=>x<=k|n<k?'':g(n-1)+2**n)(x)).length-l||alert(s)))  ### Demo NB: This snippet is buffering the results and printing them to the console for user-friendliness. let f = l=>[...1e11+''].map((_,k,a)=>a.map((_,x)=>(s=(g=n=>x<=k|n<k?'':g(n-1)+2**n)(x)).length-l||alert(s))) alert = s => res += ' ' + s; for(l = 2; l <= 27; l++) { res = ''; f(l); console.log('L = ' + l + ' -->' + res); } # Haskell, 72 67 bytes f n=[s|i<-[0..99],j<-[i+1..99],s<-[show.(2^)=<<[i..j]],length s==n]  Try it online! Saved 5 bytes thanks to Laikoni I used a limit of 99 because 2^99 has a length > 27. • It's returning extra cases for an input of 27 though. Commented Sep 12, 2017 at 18:10 • You can replace 99 with 11, so it becomes more valid. Although, I did not state that numbers > 2048 are invalid. I stated only, that 2048 is the minimum range. Commented Sep 12, 2017 at 18:13 • @JonathanAllan I think it's still correct: "The 2048 one or larger if you want" I took the 633825300114114700748351602688 sequence, because it guarantees that there won't be any other solution (in the range 2-27). Actually, I think a 45 limit would be sufficient, because length$(show$2^44)++(show$2^45)==28. Commented Sep 12, 2017 at 18:27
• @jferard that was actually edited in after your answer (it actually stated "limited to 2048" before). I can shorten mine in this case too. Commented Sep 12, 2017 at 18:30
• @JonathanAllan Yes, I actually realised that some of rules in the question are wrong and misleading just after posting this anwer. Commented Sep 12, 2017 at 18:41

# Mathematica, 122 bytes

(s=#;FromDigits@F[f/@#]&/@Select[Subsequences[Array[2^#&,99,0]],l@#>1&&(l=Length)@(F=Flatten)[(f=IntegerDigits)/@#]==s&])&


Input

[27]

Output

{879609302220817592186044416, 134217728268435456536870912, 524288104857620971524194304, 163843276865536131072262144, 204840968192163843276865536, 256512102420484096819216384, 641282565121024204840968192, 163264128256512102420484096, 124816326412825651210242048}

Input [1000]
Output  1441151880758558722882303761517117445764607523034234881152921504606846976230584300921369395246116860184273879049223372036854775808184467440737095516163689348814741910323273786976294838206464147573952589676412928295147905179352825856590295810358705651712118059162071741130342423611832414348226068484722366482869645213696944473296573929042739218889465931478580854784377789318629571617095687555786372591432341913615111572745182864683827230223145490365729367654460446290980731458735308812089258196146291747061762417851639229258349412352483570327845851669882470496714065569170333976494081934281311383406679529881638685626227668133590597632773712524553362671811952641547425049106725343623905283094850098213450687247810566189700196426901374495621121237940039285380274899124224247588007857076054979824844849517601571415210995964968969903520314283042199192993792198070406285660843983859875843961408125713216879677197516879228162514264337593543950336158456325028528675187087900672316912650057057350374175801344


# C, 170 bytes

i,j;f(n){char t[99],s[12][5]={"1"};for(i=j=1;i<12;)sprintf(s+i++,"%d",j*=2);for(i=0;i<12;++i,strlen(t)-n||j>1&&puts(t))for(j=*t=0;strlen(t)<n&&j+i<12;)strcat(t,s+i+j++);}


Try it online!

Unrolled:

i,j;
f(n)
{
char t[99], s[12][5] = {"1"};
for (i=j=1; i<12;)
sprintf(s+i++, "%d", j*=2);
for (i=0; i<12; ++i, strlen(t)-n || j>1 && puts(t))
for (j=*t=0; strlen(t)<n && j+i<12;)
strcat(t, s+i+j++);
}


# K (ngn/k), 33 bytes

{(x=#:')#,/{,/'$x':|2/=12}'2+!11}  Try it online! Generates all possible sublists, then selects those of the proper length. Returns a list of strings. • {...}'2+!11 generate 2..12 (the valid sublist lengths for input from 2..27), and run the code in {...} on each of those numbers • |2/=12 generate the sequence 1 2 4 8 16 32 64 128 256 512 1024 2048 • ,/'$x': take x-length rolling windows, converting each to strings, then concatenate them (e.g., 1 2 4 8 => (1 2;2 4;4 8) => ((,"1";,"2");(,"2";,"4");(,"4";,"8")) => ("12";"24";"48"))
• (x=#:')#,/ flatten the potential strings, keeping those of the desired length

# R, 99 bytes

function(n)for(i in 1:11)for(j in i:11+1)if(sum(nchar(x<-2^(0:11))[i:j])==n)cat(x[i:j],"\n",sep="")


Try it online!

# Perl 5, 76 bytes

75 bytes of code + 1 for -a

for$i(0..10){$/='',(map$/.=2**$_,$i..$_)&&$F[0]-length$/||say$/for$i+1..11}


Try it online!

# Ruby, 94 bytes

->n{a=*b=1;a<<b*=2until b>3**n;(2..n).flat_map{|x|a.each_cons(x).map &:join}.grep /^.{#{n}}\$/}


Try it online!