11
\$\begingroup\$

For a computer language, a reserved word is a word that cannot be used as an identifier, such as the name of a variable, function, or label. For other computer languages, keywords can be considered as the set of the language instructions.

Challenge

Using your language of choice, write a code in the chosen language that given a number between one and ten,1<=n<=10, outputs anyn reserved words (keywords) of the chosen language.

Specifics

  • If the chosen language is case sensitive the outputted keywords must be also.
  • If the chosen language is not case sensitive the outputted keywords can be in any case.
  • If the chosen language has less than 10 keywords sayingp, the code must output all the reserved words for anyn betweenp and10.
  • If possible specify in the answer whether you consider operators as keywords or not.

Possible samples for Java (JDK10)

  • n=1 --> true
  • n=3 --> try new interface
  • n=4 --> continue this long break

Possible samples for ><>

  • n=1 --> >
  • n=3 --> > < ^
  • n=4 --> > < \ /

Possible samples for Brain-Flak

  • n=1 --> (
  • n=3 --> ( ) [ ]
  • n=9 --> ( ) [ ] { } < >

Rules

  • The input and output can be givenin any convenient format.
  • No need to handleinvalid input values, valid inputs are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
  • Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
  • If possible, please include a link to an on-line testing environment so other people can try out your code!
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
askedApr 16, 2018 at 11:16
mdahmoune's user avatar
\$\endgroup\$
3
  • \$\begingroup\$Comments are not for extended discussion; this conversation has beenmoved to chat.\$\endgroup\$CommentedApr 19, 2018 at 2:29
  • 5
    \$\begingroup\$continue this long break I wish! That's why I'm on SE!\$\endgroup\$CommentedApr 24, 2018 at 18:09
  • \$\begingroup\$the integers are reserved but I guess that would be a loophole.\$\endgroup\$CommentedAug 2, 2018 at 13:56

34 Answers34

7
\$\begingroup\$

APL (Dyalog Unicode), 9bytesSBCS

Full program. Prompts stdin forn (actually works for the range 0–29). APL keywords are single character symbols, so this printsn symbols to stdout.

⎕↑156↓⎕AV

Try it online!

⎕AV the Atomic Vector (i.e. the character set)

156↓ drop the first 156 elements

⎕↑ prompt forn and take that many elements from the above

answeredApr 16, 2018 at 11:33
Adám's user avatar
\$\endgroup\$
5
\$\begingroup\$

Python 2, 25 bytes

lambda n:'=+*/%&^|<>'[:n]

An unnamed function accepting an integer in [1,10] which returns a string of single-byte binary operators.

Try it online!

The operators:

=  Assign+  Addition*  Multiplication/  Division%  Modulo&  Bitwise-AND^  Bitwise-XOR|  Bitwise-OR<  Less Than?>  Greater Than?

If only actual keywords are allowed: 40 bytes

from keyword import*lambda n:kwlist[:n]

An unnamed function accepting an integer in [1,10] which returns a list of strings.

Try it online!

The code should be quite straightforward - it defines a function taking one argument,n, usinglambda n:... which returns the firstn (...[:n]) of the known keywords using the standard library'skeywords.kwlist (along with the standard golfing technique ofimport*).

answeredApr 16, 2018 at 13:42
Jonathan Allan's user avatar
\$\endgroup\$
4
  • \$\begingroup\$very minor point but surely= is "Assignment" as== is "Test for equality"\$\endgroup\$CommentedApr 16, 2018 at 15:42
  • \$\begingroup\$Oops, good catch, thanks @Noodle9\$\endgroup\$CommentedApr 16, 2018 at 16:08
  • \$\begingroup\$Weird down-vote! Edit: Someone decided all the answers here deserve a down-vote. LOL\$\endgroup\$CommentedApr 16, 2018 at 20:39
  • \$\begingroup\$Certainly wasn't me - I liked your answer and upvoted it! :)\$\endgroup\$CommentedApr 16, 2018 at 20:44
4
\$\begingroup\$

Java 10,83 72 bytes (keywords)

n->"do   if   for  int  new  try  var  byte case char ".substring(0,n*5)

Try it online.

Old 83 bytes answer:

n->java.util.Arrays.copyOf("do if for int new try var byte case char".split(" "),n)

Try it online.

Explanation:

n->                         // Method with integer parameter and String-array return-type  java.util.Arrays.copyOf(  //  Create a copy of the given array:    "do if for int new try var byte case char".split(" ")                             //   The keywords as String-array,    ,n)                     //   up to and including the given `n`'th array-item

List of available keywords for Java 8. Java 10 has the keywordvar in addition to these.


Java 8+, 30 bytes (operators)

n->"+-/*&|^~<>".substring(0,n)

Try it online.

answeredApr 16, 2018 at 12:29
Kevin Cruijssen's user avatar
\$\endgroup\$
3
\$\begingroup\$

Jelly, 3bytes

ØAḣ

A monadic link accepting an integer and returning a list of characters.

Try it online!

The resulting characters are all monadicatoms in Jelly'scode-page:

A   Absolute value.B   Convert from integer to binary.C   Complement; compute 1 − z.D   Convert from integer to decimal.E   Check if all elements of z are equal.F   Flatten list.G   Attempt to format z as a grid.H   Halve; compute z ÷ 2.I   Increments; compute the differences of consecutive elements of z.J   Returns [1 … len(z)].

How?

ØAḣ - Link: integer n (in [1,10])ØA  - yield uppercase alphabet = ['A','B','C',...,'Z']  ḣ - head to index n
answeredApr 16, 2018 at 13:36
Jonathan Allan's user avatar
\$\endgroup\$
2
  • \$\begingroup\$Oh - I see someone decided to down-vote ALL the answers; how sporting!\$\endgroup\$CommentedApr 16, 2018 at 20:40
  • \$\begingroup\$Think this answer deserves an upvoted too! :)\$\endgroup\$CommentedApr 16, 2018 at 20:58
3
\$\begingroup\$

Charcoal, 16bytes

✂”yPBG¤T⎚M↶↷J”⁰N

Too bad there isn'ta preset variable for its own code-page in Charcoal.

Try it online.

Explanation:

Get a substring from index 0 to the input-number:

Slice("...",0,InputNumber)✂”y...”⁰N

The string with 10 keywords:

”yPBG¤T⎚M↶↷J”
answeredApr 16, 2018 at 13:49
Kevin Cruijssen's user avatar
\$\endgroup\$
4
  • \$\begingroup\$I assume the fullwidth letters have consecutive character codes so you can just print the firstn of those, which I can do in 8 bytes.\$\endgroup\$CommentedJan 27, 2019 at 12:41
  • \$\begingroup\$@Neil But are ten of those consecutive characters used as commands/operators? The for example isn't used at all right now, is it? (Except in combination withKA or⌕A.)\$\endgroup\$CommentedJan 28, 2019 at 7:48
  • \$\begingroup\$Actually is a command and operator, but not a good one, as it can cause confusion betweenFind andFindAll, but you then get stuck again at and, which only get used as modifiers, and then isn't used at all, which limits you. Greek letters, then?\$\endgroup\$CommentedJan 28, 2019 at 10:03
  • \$\begingroup\$Never mind, those are variables, not commands, I guess.\$\endgroup\$CommentedJan 28, 2019 at 10:55
3
\$\begingroup\$

Perl 5-lp, 24 bytes

#!/usr/bin/perl -lp$_=(grep!eval,a..zz)[$_]

Try it online!

Easy to extend to more and longer keywords, but you will need to do special casing starting at 4 letters because you will run into problems withdump,eval,exit,getc etc..

Of course just outputting operators and sigils is boring but shorter at 11 bytes:

#!/usr/bin/perl -lp$_=chr$_+35

Try it online!

(I skipped# since it's unclear how I should classify it in the context of this challenge)

answeredApr 16, 2018 at 19:00
Ton Hospel's user avatar
\$\endgroup\$
3
\$\begingroup\$

Brain-Flak,122 120 bytes

({}<((((((((((((((()()){}()){}){}){})())[][]){}())()())[(([][]){}){}()])()())){}())[()()])>){({}<{({}<>)(<>)}{}>[()])}<>

Try it online!

Just doing my part to fill out the example languages. Outputs()[]<>}{, popping off the front for numbers less than 8.

answeredApr 16, 2018 at 12:32
Jo King's user avatar
\$\endgroup\$
3
\$\begingroup\$

JavaScript (Node.js),79 61 bytes

n=>'true int var for in if new try of do'.split` `.slice(0,n)

Try it online!

How :

n =>         // the input (will be an integer) between 1 and 10 (both inclusive)    '        // beginning our string         true int var for in if new try of do'. // space separated reserved words    split` `.        // turn it into an array every time there is a space we add to array    slice(0,n)      // return elements of array starting from 0 and upto n

If using operators is allowed (most likely will be since they are reserved words) then :

JavaScript (Node.js),26 25 bytes

n=>'|/^%+<&*-='.slice(-n)

Try it online!

Saved 8 bytes thanks to@Adam and 1 more byte thanks to@l4m2

How :

n =>     // input (integer from 0-9 inclusive)    '|/^%+<&*-='.    // operators make a shorter string         slice(-n)   // outputs string chars from last upto n             // this works since all operators are single chars and not multi chars.
answeredApr 16, 2018 at 11:34
Muhammad Salman's user avatar
\$\endgroup\$
6
  • \$\begingroup\$n=>'|/^%+<&*-='.substr(-n)\$\endgroup\$CommentedApr 16, 2018 at 11:45
  • \$\begingroup\$Oh yeah , Lol still golfing. Thanks @Adám. Appreciate it.\$\endgroup\$CommentedApr 16, 2018 at 11:46
  • 3
    \$\begingroup\$I don't thinkint is a "reserved word" as per the definition in the challenge. You can certainly name a variableint in JavaScript.\$\endgroup\$CommentedApr 16, 2018 at 22:54
  • 1
    \$\begingroup\$If I remember well,int is reserved as a possible future keyword by the ECMAScript specification.\$\endgroup\$CommentedApr 17, 2018 at 12:36
  • \$\begingroup\$Whysubstr instead ofslice?\$\endgroup\$CommentedApr 17, 2018 at 16:21
3
\$\begingroup\$

Ruby, 22 bytes

->n{'+-*/%&|^<>'[0,n]}

Try it online!

-2 bytes thanks to@benj2240

answeredApr 16, 2018 at 12:04
\$\endgroup\$
5
  • \$\begingroup\$Ok. Will update my answer.\$\endgroup\$CommentedApr 16, 2018 at 12:17
  • \$\begingroup\$String#[] has a two-argument overload you can use for -2 bytes:[0,n]\$\endgroup\$CommentedApr 16, 2018 at 21:29
  • \$\begingroup\$p is not a reserved word,& should work\$\endgroup\$CommentedApr 17, 2018 at 16:40
  • \$\begingroup\$@AsoneTuhid : p is used for printing as well , but You are right I can probably replace it. Thanks\$\endgroup\$CommentedApr 17, 2018 at 18:24
  • \$\begingroup\$@I'mnoone Yes but it's a method, you can redefine it and you can create a variable namedp which will be accessed instead of calling the method with no variables (p = 1; p p #=> 1)\$\endgroup\$CommentedApr 17, 2018 at 18:27
2
\$\begingroup\$

Whitespace, 84 bytes

[S S S T    S S S S S N_Push_32][S NS _Duplicate][T NS S _Print_as_character][S NS _Duplicate][T NT   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][S S S T  N_Push_1][T  S S T   _Subtract][S NS _Duplicate][NT   S N_If_0_Jump_to_Label_EXIT][S S S T   S S T   N_Push_9][T  NS S Print_as_character][S S S T N_Push_1][T  S S T   _Subtract][NT   S N_If_0_Jump_to_Label_EXIT][S S S T   S T S N_Push_10][T NS S _Print_as_character][NS S N_Create_Label_EXIT]

LettersS (space),T (tab), andN (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Whitespace only contains three valid 'keywords': spaces, tabs and new-lines.

Explanation in pseudo-code:

Print spaceInteger i = STDIN as integer - 1If i is 0:  Exit programElse:  Print tab  i = i - 1  If i is 0:    Exit program  Else:    Print new-line    Exit program

Example runs:

Input:1

Command       Explanation                 Stack      Heap      STDIN    STDOUT   STDERRSSSTSSSSSN    Push 32                     [32]SNS           Duplicate top (32)          [32,32]TNSS          Print as character          [32]                          <space>SNS           Duplicate top (32)          [32,32]TNTT          Read STDIN as integer       [32]       {32:1}    1TTT           Retrieve                    [1]        {32:1}SSSTN         Push 1                      [1,1]      {32:1}TSST          Subtract top two (1-1)      [0]        {32:1}SNS           Duplicate top (0)           [0,0]      {32:1}NTSN          If 0: Jump to Label_EXIT    [0]        {32:1}NSSN          Create Label_EXIT           [0]        {32:1}                                                                                 error

Program stops with an error: No exit defined.
Try it online (with raw spaces, tabs and new-lines only).
Outputs a single space.

Input:2

Command       Explanation                 Stack      Heap      STDIN    STDOUT   STDERRSSSTSSSSSN    Push 32                     [32]SNS           Duplicate top (32)          [32,32]TNSS          Print as character          [32]                         <space>SNS           Duplicate top (32)          [32,32]TNTT          Read STDIN as integer       [32]       {32:2}    2TTT           Retrieve                    [2]        {32:2}SSSTN         Push 1                      [2,1]      {32:2}TSST          Subtract top two (2-1)      [1]        {32:2}SNS           Duplicate top (1)           [1,1]      {32:2}NTSN          If 0: Jump to Label_EXIT    [1]        {32:2}SSSTSSTN      Push 9                      [1,9]      {32:2}TNSS          Print as character          [1]        {32:2}             \tSSSTN         Push 1                      [1,1]      {32:2}TSST          Subtract top two (1-1)      [0]        {32:2}NTSN          If 0: Jump to Label_EXIT    []         {32:2}NSSN          Create Label_EXIT           []         {32:2}                                                                                 error

Program stops with an error: No exit defined.
Try it online (with raw spaces, tabs and new-lines only).
Outputs a space, followed by a tab.

Input:3 (or higher)

Command       Explanation                 Stack      Heap      STDIN    STDOUT   STDERRSSSTSSSSSN    Push 32                     [32]SNS           Duplicate top (32)          [32,32]TNSS          Print as character          [32]                          <space>SNS           Duplicate top (32)          [32,32]TNTT          Read STDIN as integer       [32]       {32:3}    3TTT           Retrieve                    [3]        {32:3}SSSTN         Push 1                      [3,1]      {32:3}TSST          Subtract top two (3-1)      [2]        {32:3}SNS           Duplicate top (2)           [2,2]      {32:3}NTSN          If 0: Jump to Label_EXIT    [2]        {32:3}SSSTSSTN      Push 9                      [2,9]      {32:3}TNSS          Print as character          [2]        {32:3}             \tSSSTN         Push 1                      [2,1]      {32:3}TSST          Subtract top two (2-1)      [1]        {32:3}SSSTSTSN      Push 10                     [1,10]     {32:3}TNSS          Print as character          [1]        {32:3}             \nNSSN          Create Label_EXIT           []         {32:3}                                                                                 error

Program stops with an error: No exit defined.
Try it online (with raw spaces, tabs and new-lines only).
Outputs a space, followed by a tab, followed by a new-line.

answeredApr 16, 2018 at 13:14
Kevin Cruijssen's user avatar
\$\endgroup\$
2
\$\begingroup\$

Pyth, 4 bytes

>QPG

Try it online!

Unfortunately, many of the letters are variables (GHJKNQTYZbdkz).

p  <any>                  Print A, with no trailing newline. Return A.q  <any> <any>            A == Br  <str> 0                A.lower()r  <str> 1                A.upper()r  <str> 2                A.swapcase()r  <str> 3                A.title()r  <str> 4                A.capitalize()r  <str> 5                string.capwords(A)r  <str> 6                A.strip() - Remove whitespace on both sides of A.r  <str> 7                Split A, eval each part.r  <seq> 8                Run length encode A. Output format [[3, 'a'], [2, 'b'], [1, 'c'], [1, 'd']].r  <str> 9                Run length decode A. Input format '3a2bcd' -> 'aaabbcd'r  <seq> 9                Run length decode A. Input format [[3, 'a'], [2, 'b'], [1, 'c'], [1, 'd']].r  <int> <int>            Range, half inclusive. range(A, B) in Python, or range(A, B, -1).r  <str> <str>            String range. r(C(A), C(B)), then convert each int to string using C.r  <int> <seq>            r(B, A)s  <col(str)>             Concatenate. ''.join(A)s  <col>                  reduce on +, base case []. (Pyth +)s  <cmp>                  Real part. A.real in Python.s  <num>                  Floor to int. int(A) in Python.s  <str>                  Parse as int. "" parses to 0. int(A) in Python.t  <num>                  A - 1.t  <seq>                  Tail. A[1:] in Python.u  <l:GH> <seq/num> <any> Reduce B from left to right, with function A(_, _) and C as starting value. G, H -> N, T ->. A takes current value, next element of B as inputs. Note that A can ignore either input.u  <l:GH> <any> <none>    Apply A(_, _) until a result that has occurred before is found. Starting value B. A takes current value, iteration number as inputs.v  <str>                  Eval. eval(A) without -s, ast.literal_eval(A) with -s (online). literal_eval only allows numeric, string, list, etc. literals, no variables or functions.w                         Take input. Reads up to newline. input() in Python 3.x  <int> <int>            Bitwise XOR. A ^ B in Python.x  <lst> <any>            First occurrence. Return the index of the first element of A equal to B, or -1 if none exists.x  <str> <str>            First occurrence. Return the index of the first substring of A equal to B, or -1 if none exists.x  <non-lst> <lst>        All occurrences. Returns a list of the indexes of elements of B that equal A.x  <str> <non-lst>        First occurence. Return the index of the first substring of A equal to str(B), or -1 if none exists.y  <seq>                  Powerset. All subsets of A, ordered by length.y  <num>                  A * 2.
answeredApr 16, 2018 at 13:40
Leaky Nun's user avatar
\$\endgroup\$
2
\$\begingroup\$

C# .NET,76 62 bytes (keywords)

n=>"as  do  if  in  is  for int new out ref ".Substring(0,n*4)

Try it online.

Old 76 bytes answer:

using System.Linq;n=>"as do if in is for int new out ref".Split(' ').Take(n)

Try it online.

Explanation:

using System.Linq;  // Required import for Taken=>                 // Method with integer parameter and IEnumerable<string> return-type  "as do if in is for int new out ref".Split(' ')                     //  The keywords as string-array,  .Take(n)          //  and return the first `n` items

List of available keywords in C# .NET.


C# .NET, 30 bytes (operators)

n=>"+-/*&|^~<>".Substring(0,n)

Try it online.

answeredApr 16, 2018 at 12:39
Kevin Cruijssen's user avatar
\$\endgroup\$
2
\$\begingroup\$

Charm, 52 bytes

This outputsall of the reserved words in Charm.

" [  := :: \"   " 0 2 copyfrom 3 * substring pstring

Since all non-recursive code in Charm is inline-able, this is an anonymous function. Call like this:

4 " [  := :: \"   " 0 2 copyfrom 3 * substring pstring

(outputs[ := :: ", the only four reserved words.)


Giving this function a name adds 5 bytes:

f := " [  := :: \"   " 0 2 copyfrom 3 * substring pstring
answeredApr 17, 2018 at 1:39
Aearnus's user avatar
\$\endgroup\$
2
\$\begingroup\$

Unary,6072204020736072426436 378380483266268 bytes

+[>+<+++++]>---. (0o12602122222703334)

Thank Jo King for 99.999993768646738908474177860631% reducing

answeredApr 16, 2018 at 19:19
l4m2's user avatar
\$\endgroup\$
5
  • 1
    \$\begingroup\$Is the bytes number correct?\$\endgroup\$CommentedApr 16, 2018 at 19:28
  • \$\begingroup\$@mdahmoune I think so\$\endgroup\$CommentedApr 16, 2018 at 19:31
  • \$\begingroup\$!!It’s very big\$\endgroup\$CommentedApr 16, 2018 at 21:06
  • \$\begingroup\$@mdahmoune It's actually pretty 'small' for Unary. ;) If you search for other Unary or Lenguage answers here on PPCG there are some much, much larger than this.\$\endgroup\$CommentedApr 17, 2018 at 6:50
  • \$\begingroup\$Does,[.-] in Lenguage fits the requirement?\$\endgroup\$CommentedApr 17, 2018 at 13:14
2
\$\begingroup\$

Ruby,50 49 bytes

->n{%w[do if or in end not for def nil and][0,n]}

Try it online!

Not using any operators (+,|, etc.).

answeredApr 17, 2018 at 16:49
Asone Tuhid's user avatar
\$\endgroup\$
2
\$\begingroup\$

Ruby,71 68 bytes

->n{(?a..'zzz').reject{|x|begin;eval x+'=n';rescue Object;end}[0,n]}

Okay, not the shortest approach, but too fun not to post. Programmatically finds all strings of up to three lowercase letters that can't be assigned to. There happen to be exactly 10:["do", "if", "in", "or", "and", "def", "end", "for", "nil", "not"].

Edit: Saved 3 bytes thanks to Asone Tuhid.

answeredApr 17, 2018 at 17:13
histocrat's user avatar
\$\endgroup\$
1
  • 1
    \$\begingroup\$Nice,you can save 3 bytes by rescuingObject since it's a superclass ofException\$\endgroup\$CommentedApr 17, 2018 at 18:46
2
\$\begingroup\$

C (gcc),62 60 bytes

-2 thanks to GPS

f(n){puts("autocasecharelseenumgotolongvoidint do"+40-4*n);}

Try it online!

I mean... there was never any requirement to actually separate the keywords.

In case I misread - or you're more interested in something more in the spirit of the question - here's an alternate version with separating spaces:

C (gcc), 69 bytes

f(n){puts("auto case char else enum goto long void int  do"+50-5*n);}

Try it online!

answeredApr 17, 2018 at 12:25
gastropner's user avatar
\$\endgroup\$
3
  • \$\begingroup\$Do you need the two spaces afterdo?\$\endgroup\$CommentedApr 17, 2018 at 13:05
  • \$\begingroup\$@JoKing Yeah, otherwise garbage characters could be written.\$\endgroup\$CommentedApr 17, 2018 at 14:56
  • \$\begingroup\$You could trim spaces afterdo if you use string output functions. 69 bytes:Tio\$\endgroup\$CommentedApr 17, 2018 at 22:04
2
\$\begingroup\$

Japt, 3 bytes

Returns a string, with each individual character being a method name in Japt.

;îC

Try it

;C is the lowercase alphabet andî repeats it until its length equals the input.

answeredApr 17, 2018 at 10:40
Shaggy's user avatar
\$\endgroup\$
2
  • \$\begingroup\$@Downvoter, you forgot to leave a comment! :\\$\endgroup\$CommentedApr 17, 2018 at 16:20
  • \$\begingroup\$It seems that someone has down-voted all answers :/\$\endgroup\$CommentedApr 18, 2018 at 7:06
2
\$\begingroup\$

Chicken, 7 bytes

chicken

Not a serious answer. But it has to be here.

answeredApr 26, 2018 at 11:54
jimmy23013's user avatar
\$\endgroup\$
2
\$\begingroup\$

R,766260 57 bytes

12 bytes saved thanks toMickyT

5 bytes saved thanks tosnoram

cat(c("if","in",1:0/0,"for",F,T,"NULL","else")[1:scan()])

Try it online!

There aren't manyReserved words in R but these are among the shortest to encode. There are only 9 here, but if an input of10 is given, a missing valueNA is appended to the end of the list and printed.

answeredApr 17, 2018 at 16:49
Giuseppe's user avatar
\$\endgroup\$
6
  • \$\begingroup\$Some quick little savings\$\endgroup\$CommentedAug 1, 2018 at 23:30
  • \$\begingroup\$@MickyT thanks! Realized I could store"NaN" as0/0 orNaN as well for another couple bytes.\$\endgroup\$CommentedAug 2, 2018 at 13:22
  • \$\begingroup\$replace1/0,0/0 with1:0/0.\$\endgroup\$CommentedAug 2, 2018 at 13:59
  • 2
    \$\begingroup\$@snoram ah, excellent! And welcome to PPCG! I'm looking forward to your first answer here! Have a look attips for golfing in R and feel free to ping me in chat! :-)\$\endgroup\$CommentedAug 2, 2018 at 14:01
  • \$\begingroup\$Thanks! @Giuseppe btw.1[1:2] returns[1] 1 NA => you can skipNAin the original vector... if user input is 10 it will get appended at the end.\$\endgroup\$CommentedAug 2, 2018 at 14:08
1
\$\begingroup\$

Python 2, 64 bytes

lambda n:'as if def del for try elif else from pass'.split()[:n]

Try it online!


Python 2, 57 bytes (with operators)

lambda n:'as if in is or and def del for not'.split()[:n]

Try it online!


keywords
operators

answeredApr 16, 2018 at 11:26
Dead Possum's user avatar
\$\endgroup\$
1
  • 1
    \$\begingroup\$a function is2 bytes shorter\$\endgroup\$CommentedApr 16, 2018 at 12:01
1
\$\begingroup\$

Brain-Flak, 118 bytes

({}<(((((((((((()()()()()){}){}){})())(([][][])){}{}())()())([][][])[]{})()())[][][][][])()())>){({}<({}<>)<>>[()])}<>

Try it online!

# Push stuffs under the counter({}<(((((((((((()()()()()){}){}){})())(([][][])){}{}())()())([][][])[]{})()())[][][][][])()())>)# While True{    # Decrement the counter    ({}<        # Toggle a character        ({}<>)<>    >[()])}# Display alternate stack<>
answeredApr 16, 2018 at 19:14
DJMcMayhem's user avatar
\$\endgroup\$
1
  • \$\begingroup\$This prints extra null bytes for 9 and 10\$\endgroup\$CommentedApr 16, 2018 at 22:51
1
\$\begingroup\$

05AB1E, 2 bytes

Try it online!


Every letter of the alphabet is a command in 05AB1E.

All this does is prints the firstN letters of the alphabet.

answeredApr 17, 2018 at 14:44
Magic Octopus Urn's user avatar
\$\endgroup\$
1
\$\begingroup\$

><>,11 10 9 bytes

1-:n:0=?;

Try it online!

Turned out the simplest solution was the best. This outputs the first n numbers, starting from 0.

Old 10 byte solutions

"'r{$[>o<3

Try it online!

Some 10 byte alternatives:

  • "':1+{[>o<
  • "r:n[~>o<a
  • "'a{[>o<bc
answeredApr 16, 2018 at 12:06
Jo King's user avatar
\$\endgroup\$
1
\$\begingroup\$

Haskell, 22 bytes

(`take`"';,=\"@\\`|~")

Try it online!

Thanks to @Angs for catching keyword errors.

I felt like this could be shorter by generating the string instead of explicitly defining it, but I couldn't find a range of 10 consecutive ASCII characters that are Haskell keywords (I found some that are close, if you count language extension keywords). If there is one, you could reduce it to 15 bytes with this, replacing% with the starting character:

(`take`['%'..])

Without symbolic keywords:

Haskell, 58 bytes

(`take`words"of in do let then else case data type class")

Try it online!

answeredApr 16, 2018 at 22:10
\$\endgroup\$
3
  • \$\begingroup\$! isn't reserved, e.g.let a!b=a+b is fine\$\endgroup\$CommentedApr 17, 2018 at 16:15
  • \$\begingroup\$Oops, you're right. Fixed both parts, sinceas is also a valid identifier.\$\endgroup\$CommentedApr 17, 2018 at 16:30
  • \$\begingroup\$. isn't reserved either - none of the other operators in prelude like+ etc are -see this\$\endgroup\$CommentedApr 17, 2018 at 16:41
1
\$\begingroup\$

Taxi, 509 bytes

"[]a lrnsew" is waiting at Writer's Depot. Go to Post Office: w 1 l 1 r 1 l. Pickup a passenger going to The Babelfishery. Go to The Babelfishery: s 1 l 1 r.Pickup a passenger going to The Underground.Go to Writer's Depot: n 1 l, 1 l, 2 l.Pickup a passenger going to Chop Suey.Go to Chop Suey: n, 3 r, 3 r.[a]Pickup a passenger going to Post Office.Go to Post Office: s 1 r 1 l 2 r 1 l.Go to The Underground: n 1 r 1 l.Pickup a passenger going to The Underground.Go to Chop Suey: n 2 r 1 l.Switch to plan "a".

This takes a hardcoded string at the top, and prints "n" characters from it, and then errors with "error: no outgoing passengers found".

The string contains:

  1. [ and], the characters used to declare a plan
  2. a used in the "Pickup a passenger ..." syntax.
  3. The space character, which is required to separate pieces of syntax
  4. l andr, short for "left" and "right", used to tell the driver which way to turn.
  5. n,s,e, andw, the four directions.

I believe all of those count as one character keywords. Ungolfed:

"[]a lrnsew" is waiting at Writer's Depot.Go to Post Office: west, 1st left, 1st right, 1st left.Pickup a passenger going to The Babelfishery.Go to The Babelfishery: south, 1st left, 1st right.Pickup a passenger going to The Underground.Go to Writer's Depot: north, 1st left, 1st left, 2nd left.Pickup a passenger going to Chop Suey.Go to Chop Suey: north, 3rd right, 3rd right.[print character]Pickup a passenger going to Post Office.Go to Post Office: south, 1st right, 1st left, 2nd right, 1st left.Go to The Underground: north, 1st right, 1st left.Pickup a passenger going to The Underground.Go to Chop Suey: north, 2nd right, 1st left.Switch to plan "print character".
answeredAug 1, 2018 at 23:06
The Fifth Marshal's user avatar
\$\endgroup\$
1
\$\begingroup\$

J, 15 bytes

[:u:46,"0~65+i.

Try it online!

Gives an array of stringsA. toJ..

Dotted words in J act as built-ins (such asa. orA.) or control structures (such asif. ordo.), or simply throw spelling error. None of them can be used as identifiers.

Less interesting, 15 bytes

{.&'!#$%^*-+=|'

Try it online!

Gives some of the 10 one-byte verbs.

answeredAug 2, 2018 at 0:24
Bubbler's user avatar
\$\endgroup\$
1
\$\begingroup\$

Bash and shell utils 20 bytes

compgen -b|head -$1

You can save that in a file with execute permissions (builtins) and run it under bash like this:

$ ./builtins 5 . :  [ alias  bg

Outputs the first N bash built ins.

If you are running some shell other than bash, you will need the shebang #!/bin/bash line at the start of the file, for +12b

answeredAug 2, 2018 at 16:20
whofferbert's user avatar
\$\endgroup\$
1
\$\begingroup\$

QBasic, 60 bytes

INPUT n?LEFT$("CLS FOR DEF RUN DIM PUT GET SUB END IF",n*4)

This answer fits the spirit of the question best, I believe: outputting alphabetic reserved keywords with spaces in between. I don't think symbolic operators really count as "words" in QBasic, but for completeness, here's a30-byte answer using operators:

INPUT n?LEFT$("+-*/\^=><?",n)
answeredAug 2, 2018 at 18:26
DLosc's user avatar
\$\endgroup\$
1
\$\begingroup\$

MATL, 5 bytes

:96+c

Try it online!

The lowercase alphabets all correspond to builtins in MATL, so this outputs the first n lowercase letters.

For a version with a smile, there's:

2Y2i:)

at 6 bytes.

answeredAug 2, 2018 at 22:18
Sundar R's user avatar
\$\endgroup\$

Your Answer

More generally…

  • …Please make sure to answer the question and provide sufficient detail.

  • …Avoid asking for help, clarification or responding to other answers (use comments instead).

Draft saved
Draft discarded

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.