2
\$\begingroup\$

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.

\$\endgroup\$
12
  • 3
    \$\begingroup\$ How did you come up with this sequence and why does it end where it does? \$\endgroup\$
    – dylnan
    Commented Dec 27, 2017 at 20:25
  • 1
    \$\begingroup\$ @dylnan It's your task to find the rule :) \$\endgroup\$
    – Mr. Xcoder
    Commented Dec 27, 2017 at 20:25
  • 12
    \$\begingroup\$ @Mr.Xcoder that's silly. As soon as anyone finds the rule it will be obvious in their code. \$\endgroup\$
    – Sparr
    Commented Dec 27, 2017 at 21:04
  • 3
    \$\begingroup\$ Why are you printing NOPE!? Once you have the sequence you can continue it. \$\endgroup\$
    – Edmund
    Commented Dec 27, 2017 at 21:09
  • 16
    \$\begingroup\$ 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. \$\endgroup\$
    – Mr. Xcoder
    Commented Dec 27, 2017 at 21:15

31 Answers 31

8
\$\begingroup\$

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!

\$\endgroup\$
6
  • \$\begingroup\$ 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 :) \$\endgroup\$
    – Steadybox
    Commented Dec 27, 2017 at 20:38
  • \$\begingroup\$ 51 \$\endgroup\$
    – Wheat Wizard
    Commented Dec 27, 2017 at 21:40
  • \$\begingroup\$ @WheatWizard Thanks! That was the cleverish trick I was looking for! \$\endgroup\$
    – Mr. Xcoder
    Commented Dec 27, 2017 at 21:41
  • \$\begingroup\$ Don't know if it helps but, f(n)=2*(f(n-1)+n) for all n except 0 \$\endgroup\$
    – Wheat Wizard
    Commented Dec 27, 2017 at 21:46
  • 1
    \$\begingroup\$ 54 using the OP's method, but probably can't be golfed to be shorter than yours \$\endgroup\$
    – FlipTack
    Commented Dec 28, 2017 at 12:17
6
\$\begingroup\$

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

Longest answer! Not anymore! YAY!

\$\endgroup\$
5
\$\begingroup\$

Emojicode, 96 bytes

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

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ +1 for the 😀 icon, will look forward to this language \$\endgroup\$
    – WORNG ALL
    Commented Dec 28, 2017 at 17:57
3
\$\begingroup\$

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]
   µ                  new monadic link
    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!

\$\endgroup\$
2
  • \$\begingroup\$ @JonathanAllan In this case it can't. Since is a monad Jelly applies it to the right argument of _. \$\endgroup\$
    – dylnan
    Commented Dec 27, 2017 at 20:54
  • 1
    \$\begingroup\$ Yeah I noticed :) -- you can use but no save there either \$\endgroup\$ Commented Dec 27, 2017 at 20:55
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

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!')
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think max(2*(i-2),0) is equivalent to max(2*i-4,0) which will save a byte or two \$\endgroup\$
    – Giuseppe
    Commented Dec 27, 2017 at 20:44
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

MATL, 19 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Japt, 23 bytes

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

Try it online!


24 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Javascript (ES2016), 58 55 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)
\$\endgroup\$
2
  • \$\begingroup\$ l(i=1);while(i<18) => for(l(i=1);i<18;) \$\endgroup\$
    – l4m2
    Commented Dec 28, 2017 at 4:47
  • \$\begingroup\$ Change (2<<i)-i-i++ to 2**i-i++<<1 for 1 byte less ;) \$\endgroup\$ Commented Dec 28, 2017 at 8:16
1
\$\begingroup\$

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!
\$\endgroup\$
1
\$\begingroup\$

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!
\$\endgroup\$
1
\$\begingroup\$

Perl 5, 42 bytes

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

Try it online

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

R, 56 51 39 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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
}
\$\endgroup\$
5
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Mar 29, 2018 at 10:20
  • \$\begingroup\$ @KevinCruijssen Right. I wasn't sure if this was allowed since the question states "print" and almost all answers print explicitly. \$\endgroup\$ Commented Mar 29, 2018 at 10:58
  • 1
    \$\begingroup\$ 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. :) \$\endgroup\$ Commented Mar 29, 2018 at 11:19
  • 1
    \$\begingroup\$ 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.) \$\endgroup\$ Commented Mar 29, 2018 at 11:23
  • 1
    \$\begingroup\$ @KevinCruijssen Thanks for your detailed explanation. I will keep this in mind for my answers in the future. \$\endgroup\$ Commented Mar 29, 2018 at 11:30
0
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ That OEIS search reveals a duplicate entry in OEIS. \$\endgroup\$ Commented Dec 28, 2017 at 12:53
  • \$\begingroup\$ @JeppeStigNielsen They are not the same. One of the entries starts 1 2 4, while the other starts 1 2 2 4. \$\endgroup\$
    – mbomb007
    Commented Dec 29, 2017 at 15:58
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 30, 2017 at 0:03
0
\$\begingroup\$

Haskell, 50 bytes

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

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ unlines( instead of (unlines$ saves a byte. \$\endgroup\$
    – Laikoni
    Commented Dec 27, 2017 at 21:52
0
\$\begingroup\$

PHP 5.6+, 65 bytes

<?=1,"\n";for($i=0;$i++<17;){echo 2*(2**$i-$i),"\n";}echo"NOPE!";

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

Charcoal, 18 bytes

E¹⁸I⎇ι⊗⁻X²ιι¹NOPE!

Try it online! Link is to verbose version of code. Explanation:

 ¹⁸                 Literal 18
E                   Map over implicit range
         ²          Literal 2
          ι         Current value
        X           Exponentiate
           ι        Current value
       ⁻            Subtract
      ⊗             Double
            ¹       Literal 1
     ι              Current value
    ⎇               Ternary
   I                Cast to string
                    Implicitly print on separate lines
             NOPE!  Literal string
                    Implictly print
\$\endgroup\$
0
\$\begingroup\$

Haskell, 47 bytes

unlines[show$2*(2^x-x)-0^x|x<-[0..17]]++"NOPE!"

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Bash, 67 characters

echo 1
for((i=0;i++<17;));do
echo $((2*(2**i-i)))
done
echo "NOPE!"

Try it online!

\$\endgroup\$
1
0
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\begingroup\$ "NOPE" is sill required though. \$\endgroup\$ Commented Dec 30, 2017 at 16:21
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

AWK, 48 bytes

END{for(;i++<17;){print 2*(2**i-i)}print"NOPE!"}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
2
  • \$\begingroup\$ 70 bytes using the latest edit of my Python answer \$\endgroup\$
    – Mr. Xcoder
    Commented Dec 27, 2017 at 22:36
  • \$\begingroup\$ <<!!n saves two bytes instead of <<(n>0) \$\endgroup\$
    – Mr. Xcoder
    Commented Dec 28, 2017 at 13:19
0
\$\begingroup\$

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!"]
\$\endgroup\$
0
\$\begingroup\$

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!'
}
\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.