| Bytes | Lang | Time | Link |
|---|---|---|---|
| 078 | Go | 250309T051457Z | bigyihsu |
| 033 | Tcl | 180418T095114Z | sergiol |
| 004 | Thunno 2 Ṡ | 230822T142420Z | The Thon |
| 012 | Cubix | 180803T015051Z | MickyT |
| 059 | Julia 0.6 | 180802T224330Z | Sundar R |
| 005 | MATL | 180802T221845Z | Sundar R |
| 060 | QBasic | 180802T182641Z | DLosc |
| 020 | Bash and shell utils | 180802T162037Z | whofferb |
| 057 | R | 180417T164910Z | Giuseppe |
| 015 | J | 180802T002422Z | Bubbler |
| 509 | Taxi | 180801T230652Z | The Fift |
| 007 | Chicken | 180426T115435Z | jimmy230 |
| 003 | Japt | 180417T104046Z | Shaggy |
| 060 | C gcc | 180417T122513Z | gastropn |
| 068 | Ruby | 180417T171319Z | histocra |
| 049 | Ruby | 180417T164925Z | Asone Tu |
| 022 | Ruby | 180416T120435Z | user7985 |
| 022 | Haskell | 180416T221009Z | user7946 |
| 061 | JavaScript Node.js | 180416T113452Z | Muhammad |
| 009 | ><> | 180416T120600Z | Jo King |
| 002 | 05AB1E | 180417T144457Z | Magic Oc |
| nan | Unary | 180416T191945Z | l4m2 |
| 120 | BrainFlak | 180416T123220Z | Jo King |
| 052 | Charm | 180417T013929Z | Aearnus |
| 118 | BrainFlak | 180416T191405Z | DJMcMayh |
| 024 | Perl 5 lp | 180416T190059Z | Ton Hosp |
| 025 | Python 2 | 180416T134259Z | Jonathan |
| 062 | C# .NET | 180416T123940Z | Kevin Cr |
| 072 | Java 10 | 180416T122905Z | Kevin Cr |
| 016 | Charcoal | 180416T134957Z | Kevin Cr |
| 003 | Jelly | 180416T133610Z | Jonathan |
| 004 | Pyth | 180416T134040Z | Leaky Nu |
| 084 | Whitespace | 180416T131411Z | Kevin Cr |
| 064 | Python 2 | 180416T112639Z | Dead Pos |
| 009 | APL Dyalog Unicode | 180416T113350Z | Adá |
Go, 78 bytes
import."go/token"
func f(n int){for i:=range Token(n){print((i+GO).String())}}
(Ab)uses the go/token.Token type (whose intended use is to implement the Go compiler) to get up to 10 keywords in the set go goto if import interface map package range return select. This uses a trick with the for-range-int loop construction: since token.Token is a newtype of an int, it is a valid type for a for-range-int loop. (Though, moving the cast into the loop body uses the same number of bytes.)
go was chosen as the starting keyword because it was the first shortest keyword available (see here for the ordering of keywords in the token.Token enum. Alternatively, moving the cast into the loop body and doing Token(i+41) also works and has the same byte count, since 41 is the offset of the first keyword break in the token.Token enum).
Outputs to STDERR, with no spaces between keywords.
Go, 103 bytes
import."strings"
func f(n int)[]string{return Fields("go if map for var func case chan else goto")[:n]}
Returns the first n keywords of the set go if map for var func case chan else goto.
The string could probably be compressed (e.g. go and goto), but would also probably need more bytes to decode it.
Thunno 2 Ṡ, 4 bytes
ıkCɼ
Explanation
ıkCɼ # Implicit input
ı # Input no. times:
ɼ # Random character from
kC # Thunno 2 Codepage
# Join on spaces
# Implicit output
Cubix, 12 bytes
Based on some of the other answers I think this should qualify for reserved words. I avoided using the numeric literals as I thought that might be stretching the definition a bit far.
SoI;W(>!@+/$
This wraps onto the cube as follows
S o
I ;
W ( > ! @ + / $
. . . . . . . .
. .
. .
WSIchange lane, push 32 and get input. This sets up the stack with 32 and the input value.>!@redirect, test for 0 and halt if true.+/o;add stack items, reflect onto top face, output character and pop the sum.!/$W(redundant test, reflect, skip the lane change, decrement the input and back into the main loop.
Output for 10
*)('&%$#"!
* multiply the top two items on the stack
) increment the TOS value
( decrement the TOS value
' push the next character's value to the stack
& pop top two items (integers) of the stack, concatenate and push the int result
% take modulo of top two stack items
$ Skip the next command
# push the stack length
" start and end of string literal. Character codes of string are pushed to the stack
! test for truthy and skip next command if true
Julia 0.6, 59 bytes
n->split("if do for try let end type else true macro")[1:n]
Using the list of reserved keywords from julia-parser.scm.
An operators-included version gets quickly confusing, as to what is an operator and what is a syntactic indicator (like @ for a macro). Going by julia-parser.scm again, a bunch of operators are termed "syntactic operators" and can't be assigned to or overloaded by the user (so fit the definition of "reserved"). Some of these are:
Julia 0.6, 45 bytes
n->split("= : :: && || ... >: <: -> .=")[1:n]
MATL, 5 bytes
:96+c
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.
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 a 30-byte answer using operators:
INPUT n
?LEFT$("+-*/\^=><?",n)
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
R, 76 62 60 57 bytes
12 bytes saved thanks to MickyT
5 bytes saved thanks to snoram
cat(c("if","in",1:0/0,"for",F,T,"NULL","else")[1:scan()])
There aren't many Reserved words in R but these are among the shortest to encode. There are only 9 here, but if an input of 10 is given, a missing value NA is appended to the end of the list and printed.
J, 15 bytes
[:u:46,"0~65+i.
Gives an array of strings A. to J..
Dotted words in J act as built-ins (such as a. or A.) or control structures (such as if. or do.), or simply throw spelling error. None of them can be used as identifiers.
Less interesting, 15 bytes
{.&'!#$%^*-+=|'
Gives some of the 10 one-byte verbs.
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:
[and], the characters used to declare a planaused in the "Pickup a passenger ..." syntax.- The space character, which is required to separate pieces of syntax
landr, short for "left" and "right", used to tell the driver which way to turn.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".
Japt, 3 bytes
Returns a string, with each individual character being a method name in Japt.
;îC
;C is the lowercase alphabet and î repeats it until its length equals the input.
C (gcc), 62 60 bytes
-2 thanks to GPS
f(n){puts("autocasecharelseenumgotolongvoidint do"+40-4*n);}
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);}
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.
Ruby, 50 49 bytes
->n{%w[do if or in end not for def nil and][0,n]}
Not using any operators (+, |, etc.).
Haskell, 22 bytes
(`take`"';,=\"@\\`|~")
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")
JavaScript (Node.js), 79 61 bytes
n=>'true int var for in if new try of do'.split` `.slice(0,n)
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)
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.
><>, 11 10 9 bytes
1-:n:0=?;
Turned out the simplest solution was the best. This outputs the first n numbers, starting from 0.
Old 10 byte solutions
"'r{$[>o<3
Some 10 byte alternatives:
"':1+{[>o<"r:n[~>o<a"'a{[>o<bc
05AB1E, 2 bytes
A£
Every letter of the alphabet is a command in 05AB1E.
All this does is prints the first N letters of the alphabet.
Unary, 6072204020736072426436 378380483266268 bytes
+[>+<+++++]>---. (0o12602122222703334)
Thank Jo King for 99.999993768646738908474177860631% reducing
Brain-Flak, 122 120 bytes
({}<((((((((((((((()()){}()){}){}){})())[][]){}())()())[(([][]){}){}()])()())){}())[()()])>){({}<{({}<>)(<>)}{}>[()])}<>
Just doing my part to fill out the example languages. Outputs ()[]<>}{, popping off the front for numbers less than 8.
Charm, 52 bytes
This outputs all 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
Brain-Flak, 118 bytes
({}<(((((((((((()()()()()){}){}){})())(([][][])){}{}())()())([][][])[]{})()())[][][][][])()())>){({}<({}<>)<>>[()])}<>
# Push stuffs under the counter
({}<(((((((((((()()()()()){}){}){})())(([][][])){}{}())()())([][][])[]{})()())[][][][][])()())>)
# While True
{
# Decrement the counter
({}<
# Toggle a character
({}<>)<>
>[()])
}
# Display alternate stack
<>
Perl 5 -lp, 24 bytes
#!/usr/bin/perl -lp
$_=(grep!eval,a..zz)[$_]
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 with dump, eval, exit,getc etc..
Of course just outputting operators and sigils is boring but shorter at 11 bytes:
#!/usr/bin/perl -lp
$_=chr$_+35
(I skipped # since it's unclear how I should classify it in the context of this challenge)
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.
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.
The code should be quite straightforward - it defines a function taking one argument, n, using lambda n:... which returns the first n (...[:n]) of the known keywords using the standard library's keywords.kwlist (along with the standard golfing technique of import*).
C# .NET, 76 62 bytes (keywords)
n=>"as do if in is for int new out ref ".Substring(0,n*4)
Old 76 bytes answer:
using System.Linq;n=>"as do if in is for int new out ref".Split(' ').Take(n)
Explanation:
using System.Linq; // Required import for Take
n=> // 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)
Java 10, 83 72 bytes (keywords)
n->"do if for int new try var byte case char ".substring(0,n*5)
Old 83 bytes answer:
n->java.util.Arrays.copyOf("do if for int new try var byte case char".split(" "),n)
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 keyword var in addition to these.
Java 8+, 30 bytes (operators)
n->"+-/*&|^~<>".substring(0,n)
Charcoal, 16 bytes
✂”yPBG¤T⎚M↶↷J”⁰N
Too bad there isn't a preset variable for its own code-page in Charcoal.
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”
Jelly, 3 bytes
ØAḣ
A monadic link accepting an integer and returning a list of characters.
The resulting characters are all monadic atoms in Jelly's code-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
Pyth, 4 bytes
>QPG
Unfortunately, many of the letters are variables (GHJKNQTYZbdkz).
p <any> Print A, with no trailing newline. Return A.
q <any> <any> A == B
r <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.
Whitespace, 84 bytes
[S S S T S S S S S N
_Push_32][S N
S _Duplicate][T N
S S _Print_as_character][S N
S _Duplicate][T N
T T _Read_STDIN_as_integer][T T T _Retrieve][S S S T N
_Push_1][T S S T _Subtract][S N
S _Duplicate][N
T S N
_If_0_Jump_to_Label_EXIT][S S S T S S T N
_Push_9][T N
S S Print_as_character][S S S T N
_Push_1][T S S T _Subtract][N
T S N
_If_0_Jump_to_Label_EXIT][S S S T S T S N
_Push_10][T N
S S _Print_as_character][N
S S N
_Create_Label_EXIT]
Letters S (space), T (tab), and N (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 space
Integer i = STDIN as integer - 1
If i is 0:
Exit program
Else:
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 STDERR
SSSTSSSSSN 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} 1
TTT 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 STDERR
SSSTSSSSSN 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} 2
TTT 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} \t
SSSTN 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 STDERR
SSSTSSSSSN 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} 3
TTT 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} \t
SSSTN 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} \n
NSSN 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.
Python 2, 64 bytes
lambda n:'as if def del for try elif else from pass'.split()[:n]
Python 2, 57 bytes (with operators)
lambda n:'as if in is or and def del for not'.split()[:n]
APL (Dyalog Unicode), 9 bytesSBCS
Full program. Prompts stdin for n (actually works for the range 0–29). APL keywords are single character symbols, so this prints n symbols to stdout.
⎕↑156↓⎕AV
⎕AV the Atomic Vector (i.e. the character set)
156↓ drop the first 156 elements
⎕↑ prompt for n and take that many elements from the above