# Exponential-ish number sequence

Your program must print out this exact sequence:

1
2
4
10
24
54
116
242
496
1006
2028
4074
8168
16358
32740
65506
131040
262110
NOPE!


As usual, shortest program wins. Standard code golf rules apply.

• How did you come up with this sequence and why does it end where it does? – dylnan Dec 27 '17 at 20:25
• @dylnan It's your task to find the rule :) – Mr. Xcoder Dec 27 '17 at 20:25
• @Mr.Xcoder that's silly. As soon as anyone finds the rule it will be obvious in their code. – Sparr Dec 27 '17 at 21:04
• Why are you printing NOPE!? Once you have the sequence you can continue it. – Edmund Dec 27 '17 at 21:09
• IMO the NOPE! just makes each submission longer by about 10 bytes, and doesn’t serve any purpose when it comes to making the challenge more interesting. – Mr. Xcoder Dec 27 '17 at 21:15

# SOGL V0.12, 16 bytes

1O'²∫ūF-«O"NOPE!


Try it Here!

Explanation:

1O                output 1
'²∫             17 times do, pushing 1-indexed counter
ū              calculate 2^pop
F-            subtract from that the counter
«           multiply by 2
O          output
"NOPE!    push "NOPE!", which gets printed at the end as implicit output hasn't been disabled. This gets pushed every iteration of the loop, to save a byte


# Python 2, 51 bytes

i=0;exec"print 2**i-i<<(i>0);i+=1;"*18;print"NOPE!"


Try it online!

Notices that the formula is 2(2n-n), for all n except 0.

Saved two bytes thanks to Wheat Wizard (i<<1-(i<1) changed to i<<(i>0), duh!).

### Python 2, 53 bytes

i=0;exec"print[2**i-i<<(i>0),'NOPE!'][i>17];i+=1;"*19


Try it online!

• I wrote exactly the same for i in range(18):print(2**i-i)*2-(i<1) print"NOPE!" solution, but was too late, it seems :) – Steadybox Dec 27 '17 at 20:38
• 51 – Wheat Wizard Dec 27 '17 at 21:40
• @WheatWizard Thanks! That was the cleverish trick I was looking for! – Mr. Xcoder Dec 27 '17 at 21:41
• Don't know if it helps but, f(n)=2*(f(n-1)+n) for all n except 0 – Wheat Wizard Dec 27 '17 at 21:46
• 54 using the OP's method, but probably can't be golfed to be shorter than yours – FlipTack Dec 28 '17 at 12:17

# Fortran 95, 82 74 bytes

Compiled with gfortran, with the -cpp flag to enable preprocessing, or saving the file with .F95 extension.

#define p print*,
program w
p 1
do i=1,17
p 2*(2**i-i)
enddo
p'NOPE!'
end


# Emojicode, 96 bytes

🏁🍇😀🔡1 2🔂i⏩1 18🍇😀🔡✖2➖🏇🏂2.0🚀i i 10🍉😀🔤NOPE!🔤🍉


Try it online!

• +1 for the 😀 icon, will look forward to this language – WORNG ALL Dec 28 '17 at 17:57

# Jelly, 20 bytes

17Rµ2*_×2“NOPE!”ṭ1;Y


Try it online!

Explanation

17Rµ2*_×2“NOPE!”ṭ1;Y
17R                   range(17):[1,2,...17]
2*                exponentiate: [2*1, 2*2,...2*17]
_               subtract: [2*1-1, 2*2-1,...2*17-17]
×2             times 2. Ḥ would need an additional syntax character but ×2 doesn't.
“NOPE!”ṭ     append "NOPE!" to the above list
1;   prepend 1 to the above list
Y  join by newlines and implicitly print


A recursive Jelly solution, 26 bytes

’ß+_3$ḤµṖṖ$¡
18RÇ€Y⁷“NOPE!


Took the Y⁷“NOPE! trick from Jonathan Allan.

Try it online!

• @JonathanAllan In this case it can't. Since Ḥ is a monad Jelly applies it to the right argument of _. – dylnan Dec 27 '17 at 20:54
• Yeah I noticed :) -- you can use ⁸ but no save there either – Jonathan Allan Dec 27 '17 at 20:55

# Matlab (R2016b), 71 69 bytes

Saved 2 bytes thanks to @Giuseppe (replace 2*(i-2) by 2*i-4)

This version prints exactly as required:

a=1;for i=1:18,fprintf('%d\n',a),a=2*a+max(2*i-4,0);end,disp('NOPE!')


# Matlab (R2016b), 53 51 bytes

This version prints the same numbers and the NOPE!, but with a different formatting:

a=1,for i=1:17,a=2*a+max(2*i-4,0),end,disp('NOPE!')

• I think max(2*(i-2),0) is equivalent to max(2*i-4,0) which will save a byte or two – Giuseppe Dec 27 '17 at 20:44

# 05AB1E, 18 17 bytes

X17LDoα·»"NOPE!"»


Try it online!

Explanation

X                  # push 1
17L               # push range [1 ... 17]
D              # duplicate
o             # raise 2 to the power of each
α            # absolute difference
·           # times 2
»          # join list on newlines
"NOPE!"   # push this string
»  # join stack on newlines


# MATL, 19 bytes

l17:tWw-E"@]'NOPE!'


Try it online!

# Japt, 23 bytes

18Çn2pZ¹*2Ãh1 ·+"
NOPE!


Try it online!

# 24 bytes

17õ!²i½ í- m*2 ·+"
NOPE!


Try it online!

# Javascript (ES2016), 5855 54 bytes

Saved 1 byte thanks to @l4m2

Saved 1 byte thanks to @user71546

for(i=0;i<18;l(2**i-i<<!!i++))l=console.log;l("NOPE!")

Uses the formula 2(2n-n) for all n ≠ 0 and 2n-n for n = 0, based on @MrXcoders Python 2 answer

## If returning an array of lines is allowed, 54 52 bytes

_=>[...""+1e19].map((_,i)=>i>18?"NOPE!":2**i-i<<!!i)

• l(i=1);while(i<18) => for(l(i=1);i<18;) – l4m2 Dec 28 '17 at 4:47
• Change (2<<i)-i-i++ to 2**i-i++<<1 for 1 byte less ;) – Shieru Asakoto Dec 28 '17 at 8:16

# Jelly, 19 bytes

1⁷17µ2*_µ€ḤY⁷“NOPE!


A full program printing the result to STDOUT.

Try it online!

### How?

1⁷17µ2*_µ€ḤY⁷“NOPE! - Main link: no arguments
1                   - literal 1 (printed as next byte starts a new leading constant chain)
⁷                  - literal newline (also printed for the same reason)
17                - literal seventeen
µ   µ€          - for €ach n in range -> [1,2,3,...,17]
2              -   literal two
*             -   raise to power n  -> [2,4,8,...,131072]
_            -   subtract n        -> [1,2,5,...,131055]
Ḥ         - double (vectorises) -> [2,4,10,...,262110]
Y        - join with newlines (again this is printed, as above)
⁷       - literal newline (this is also printed for the same reason)
“NOPE! - literal list of characters "NOPE!" (no trailing close quote required
-  at the end of a Jelly program)
- implicit print


Some alternatives exist for 19 bytes, like

‘Ṅ+⁴2*$_$€ḤY⁷“NOPE!


## Batch, 89 bytes

@echo 1
@set/ap=2
@for /l %%i in (0,2,32)do @call echo %%p%%&set/ap+=p+%%i
@echo NOPE!


# Perl 5, 42 bytes

say for 1,(map 2*(2**$_-$_),1..17),"NOPE!"


Try it online

# R, 5651 39 bytes

cat(1,2*(2^(x=1:17)-x),"NOPE!",sep="
")


Try it online!

# Java 10, 94 80 bytes

a->{var r="";for(int i=0;i<18;)r+=(i<1?1:2)*((1<<i)-i++)+"\n";return r+"NOPE!";}


Using the formula from Herman Lauenstein's answer.

Thanks to Kevin Cruijssen for golfing 14 bytes.

Try it online here.

Ungolfed version:

a -> { // lambda taking an unused null parameter
var r = ""; // we build the output as a String
for(int i = 0; i < 18; ) // generate the sequence
r += (i < 1 ? 1 : 2) * ((1 << i) - i++) + "\n"; // append 2*(2^i-i) for n > 0, 2^i-i for n = 0
return r + "NOPE!"; // return the constructed sequence, with NOPE! appended
}

• Oh var o=System.out;. I need to remember that one! In this case it's shorter to return a String though: Try it online 80 bytes. – Kevin Cruijssen Mar 29 '18 at 10:20
• @KevinCruijssen Right. I wasn't sure if this was allowed since the question states "print" and almost all answers print explicitly. – O.O.Balance Mar 29 '18 at 10:58
• Well, it also states program, in which case interface M{static void main(String[]a){...}} is missing. ;p Since program/function, print/return, and flexible I/O are default when undefined explicitly I usually use that. If the challenge would have stated something alone the lines of "Create a program (no function) that prints the following exactly to STDOUT." I would follow that, but since it's only loosely mentions "program" and "print" without any explicit rules I'll just use the default, in which case a lambda function returning a String (or char-array for all I care) is fine. :) – Kevin Cruijssen Mar 29 '18 at 11:19
• In almost all languages (especially golfing languages), full programs or functions are similar / same byte-count, and printing is done implicitly (or with Python print is shorter than return), etc. Which is why most languages indeed print. (PS: With older challenges before these defaults were properly defined you will see a lot of full programs, even for Java, and challenges almost always mention program in the description. I usually answer both a program and function in that case, like this answer I recently posted.) – Kevin Cruijssen Mar 29 '18 at 11:23
• @KevinCruijssen Thanks for your detailed explanation. I will keep this in mind for my answers in the future. – O.O.Balance Mar 29 '18 at 11:30

# Python 2, 61 bytes

i=0
x=1
print 1
exec"x*=2;print x;x+=i;i+=1;"*17
print"NOPE!"


Try it online

Just search OEIS

• That OEIS search reveals a duplicate entry in OEIS. – Jeppe Stig Nielsen Dec 28 '17 at 12:53
• @JeppeStigNielsen They are not the same. One of the entries starts 1 2 4, while the other starts 1 2 2 4. – mbomb007 Dec 29 '17 at 15:58
• You are absolutely right! I even tried editing A132824 to make it a duplicate of A132732, but of course and fortunately that edit was not approved in there. Now I try to just mention in A132824 that a(n) = A132732(n-1) except for initial terms. – Jeppe Stig Nielsen Dec 30 '17 at 0:03

(unlines$show<$>1:[2*(2^n-n)|n<-[1..17]])++"NOPE!"


Try it online!

• unlines( instead of (unlines$ saves a byte. – Laikoni Dec 27 '17 at 21:52 # PHP 5.6+, 65 bytes <?=1,"\n";for($i=0;$i++<17;){echo 2*(2**$i-$i),"\n";}echo"NOPE!";  Try it online! # Clean, 92 65 bytes import StdEnv Start=("1\n",[(2*(2^n-n),' ')\\n<-[1..17]],"NOPE!")  Trivia: The type that is actually being printed is (String, [(Int, Char)], String) Try it online! # Charcoal, 18 bytes Ｅ¹⁸Ｉ⎇ι⊗⁻Ｘ²ιι¹NOPE!  Try it online! Link is to verbose version of code. Explanation:  ¹⁸ Literal 18 Ｅ Map over implicit range ² Literal 2 ι Current value Ｘ Exponentiate ι Current value ⁻ Subtract ⊗ Double ¹ Literal 1 ι Current value ⎇ Ternary Ｉ Cast to string Implicitly print on separate lines NOPE! Literal string Implictly print  # Haskell, 47 bytes unlines[show$2*(2^x-x)-0^x|x<-[0..17]]++"NOPE!"


Try it online!

# Bash, 67 characters

echo 1
for((i=0;i++<17;));do
echo $((2*(2**i-i))) done echo "NOPE!"  Try it online! # Wolfram Language , 82 bytes DifferenceRoot[Function[{y,n},{4-2 n-2 y[n]+y[1+n]==0,y[1]==1,y[2]==2}]]/@Range@18  This is actually a holonomic sequence whose solution was obtained from f = FindSequenceFunction[{1, 2, 4, 10, 24, 54, 116, 242, 496, 1006}]  DifferenceRoot[Function[{y,n},{4 - 2 n - 2 y[n] + y[1 + n] == 0, y[1] == 1, y[2] == 2}]]  I don't know why the NOPE! is needed as the sequence does continue f[19]  524252  • "NOPE" is sill required though. – Jonathan Allan Dec 30 '17 at 16:21 # SNOBOL4 (CSNOBOL4), 97 83 bytes  OUTPUT =1 I X =X + 1 OUTPUT =LT(X,18) 2 * (2 ^ X - X) :S(I) OUTPUT ='NOPE!' END  Try it online! I'm still not really sure why I had two counters going; I only needed one. # AWK, 48 bytes END{for(;i++<17;){print 2*(2**i-i)}print"NOPE!"}  Try it online! # C, 71 70 68 bytes Thanks to @Mr. Xcoder for saving three bytes! f(n){for(n=-1;++n<18;)printf("%d\n",((1<<n)-n)<<!!n);puts("NOPE!");}  Try it online! • 70 bytes using the latest edit of my Python answer – Mr. Xcoder Dec 27 '17 at 22:36 • @Mr.Xcoder Thanks! – Steadybox Dec 27 '17 at 22:42 • <<!!n saves two bytes instead of <<(n>0) – Mr. Xcoder Dec 28 '17 at 13:19 # Recursiva, 23 bytes E++A1mB17"D~^2a"A"NOPE!  Try it online! E++A1mB17"D~^2a"A"NOPE! - Implicitly print the evaluated value E - Join with newline + - Concatenate +A1mB17"D~^2a" - [1, 2, 6, 14... 262142] + - Concatenate A1 - Listify 1 [1] mB17"D~^2a" - [2,6,14... 262142] m - map with B17 - [1,2...17] "D~^2a" - Function 2(2^n - 1) A"NOPE! - Listify ["NOPE!"]  # Perl 6, 35 bytes {1,{2*(2**++$-++$)}.../21/,'NOPE!'}  Try it { # bare block lambda 1, # start the sequence with 1 { # bare block used to generate values 2*( 2 ** ++$ # 2 to the power of an incrementing state variable
-
++\$      # incrementing anonymous state variable
)
}

...          # keep generating values until

/21/,        # it generates a value that contains '21'

'NOPE!'      # continue sequence with string 'NOPE!'
}


# Bubblegum, 57 bytes

00000000: 04c1 4101 4331 0042 b1fb 5303 94f2 3bff  ..A.C1.B..S...;.
00000010: c696 9850 2c52 6eb1 471a fa1b 9646 9447  ...P,Rn.G....F.G
00000020: f595 e73d bc73 1f27 5fc5 eed5 f0b1 2ab2  ...=.s.'_.....*.
00000030: d8e2 3f3f ff00 5745 00                   ..??..WE.


Try it online!

# Ruby, 43 bytes

->{[1]+(1..17).map{|i|2*(2**i-i)}<<"NOPE!"}


Try it online!

A lambda returning an array of integers (and one string). Breaking out 1 into a special case was pretty cheap, and didn't hurt my brain at all!