| Bytes | Lang | Time | Link |
|---|---|---|---|
| 042 | Swift 6 | 250425T214713Z | macOSist |
| 186 | Bespoke | 250423T051234Z | Josiah W |
| 023 | Raku | 250415T170215Z | xrs |
| 085 | SAKO | 250415T163939Z | Acrimori |
| 036 | Lua | 250415T134523Z | bluswimm |
| 032 | Ruby n | 250414T132022Z | Jordan |
| 052 | Tcl | 180704T004104Z | sergiol |
| 028 | AWK | 250304T174516Z | xrs |
| 170 | jbasher2 | 250225T153622Z | madeforl |
| 009 | Uiua 0.15.0dev.2 | 250224T204839Z | Tbw |
| 004 | Japt m | 180704T150306Z | Shaggy |
| 016 | YASEPL | 250224T155020Z | madeforl |
| 006 | cQuents | 180704T004950Z | Stephen |
| 041 | Desmos | 250223T214843Z | DesmosEn |
| 028 | Julia | 230602T194851Z | MarcMush |
| 3625 | Vyxal | 230523T043741Z | lyxal |
| nan | 230523T150537Z | Bartosz | |
| 107 | Scratch | 230523T122232Z | Rhaixer |
| 076 | Rockstar | 230523T084741Z | Shaggy |
| nan | 221010T151653Z | bigyihsu | |
| 046 | Nim | 221010T144254Z | Michael |
| 005 | Vyxal | 221010T132543Z | DialFros |
| 025 | Juby | 221009T153401Z | Jordan |
| 012 | Ly | 221010T000909Z | cnamejj |
| 042 | Gema | 221009T232059Z | manatwor |
| 027 | jq | 181015T101217Z | manatwor |
| 004 | Vyxal | 221009T141833Z | naffetS |
| 070 | Nim | 221009T194003Z | naffetS |
| nan | Fig | 221009T182048Z | Seggan |
| 029 | Knight | 221009T190409Z | naffetS |
| 041 | Kotlin | 180923T025905Z | snail_ |
| 088 | Blossom | 180705T202300Z | IMP1 |
| 045 | Dart | 181019T093904Z | Elcan |
| 013 | ><> | 181015T103205Z | Teal pel |
| 094 | MBASIC | 180923T232444Z | wooshiny |
| 013 | K ngn/k | 180704T000440Z | ngn |
| 011 | Gol><> | 181006T092706Z | Gegell |
| 004 | MathGolf | 180922T222521Z | Jo King |
| 033 | Runic Enchantments | 180923T195418Z | Draco18s |
| 016 | Microscript II | 180923T220655Z | SuperJed |
| 006 | Pyth | 180706T043605Z | u-ndefin |
| 310 | Shakespeare Programming Language | 180922T162355Z | JosiahRy |
| 068 | Pepe | 180731T133238Z | u-ndefin |
| 042 | Python 2 | 180731T140839Z | mbomb007 |
| 031 | VBA Excel | 180731T095526Z | remoel |
| 015 | Noether | 180731T091710Z | Beta Dec |
| 043 | Swift 4 | 180731T084844Z | buttercr |
| 033 | Ruby | 180711T180512Z | Asone Tu |
| 062 | Lua | 180729T051717Z | Visckmar |
| 056 | Bash | 180723T010825Z | Aneesh D |
| 022 | TIBasic | 180722T234511Z | Oki |
| 035 | Haskell | 180721T211930Z | ბიმო |
| 044 | Python 3 | 180709T040531Z | JathOsh |
| 048 | Kotlin | 180713T222124Z | Roland S |
| 053 | QBasic | 180710T154529Z | DLosc |
| 072 | Twig | 180712T100818Z | Ismael M |
| 052 | Python 2.7 | 180712T074928Z | Stealthy |
| 020 | ARBLE | 180710T152858Z | ATaco |
| 039 | C | 180708T195652Z | Geo |
| 072 | RAD | 180711T025243Z | Adalynn |
| 033 | DC | 180710T205348Z | FlexEast |
| 043 | Python 3 | 180704T012456Z | Jo King |
| 063 | MATLAB | 180708T015907Z | aaaaa sa |
| 043 | C gcc | 180704T042345Z | ErikF |
| 093 | D | 180708T025512Z | Conor O& |
| 108 | Rutger | 180708T151933Z | user8153 |
| 048 | yup | 180708T024320Z | Conor O& |
| 015 | Attache | 180708T021553Z | Conor O& |
| 009 | Husk | 180704T082056Z | Esolangi |
| 036 | Momema | 180704T063003Z | Esolangi |
| 029 | dc | 180705T191238Z | Sophia L |
| 051 | C Sharp | 180706T141151Z | IEatBage |
| 012 | K oK | 180706T134248Z | mkst |
| 043 | Javascript | 180706T130329Z | IEatBage |
| 034 | dc | 180706T130203Z | brhfl |
| 032 | PHP | 180706T071423Z | Crypto |
| 037 | Yabasic | 180705T160248Z | Taylor R |
| 029 | Excel VBA | 180705T160738Z | Taylor R |
| 041 | Python 2 | 180706T083802Z | TFeld |
| 029 | R | 180705T212743Z | MickyT |
| 032 | R | 180704T015425Z | Giuseppe |
| 054 | Clojure | 180705T201631Z | Carcigen |
| 021 | Perl 5 | 180704T043830Z | Xcali |
| 033 | Forth gforth | 180705T154824Z | reffu |
| 026 | Powershell | 180704T073927Z | mazzy |
| 035 | Groovy | 180705T135406Z | blblu |
| 703 | Shakespeare | 180705T115201Z | Al R |
| 101 | ABAP | 180705T081236Z | Noir Ant |
| 014 | J | 180705T012752Z | dram |
| 003 | Jelly | 180704T191722Z | Jonathan |
| 020 | J | 180704T164731Z | ljeabmre |
| 006 | Panacea | 180704T145151Z | Okx |
| 034 | Haskell | 180704T144334Z | Laikoni |
| 046 | C# Visual C# Compiler | 180704T143323Z | Jeppe St |
| nan | 180704T094726Z | auhmaan | |
| 039 | Python 3 | 180704T133959Z | Dennis |
| 054 | C# Visual C# Compiler | 180704T132705Z | raznagul |
| 041 | Python 2 | 180704T022639Z | Jo King |
| 027 | RAD | 180704T011654Z | Adalynn |
| 009 | MATL | 180704T132025Z | Giuseppe |
| 005 | Japt m | 180704T024649Z | Bubbler |
| 029 | Perl 5 | 180704T111610Z | Denis Ib |
| 048 | Java | 180704T103153Z | O.O.Bala |
| 037 | Haskell | 180704T101615Z | user2866 |
| 056 | Rust | 180704T095343Z | null |
| 043 | Python 2 | 180704T081240Z | ElPedro |
| 018 | Perl 6 | 180704T011839Z | Jo King |
| 009 | APL Dyalog Classic | 180704T070246Z | ngn |
| 006 | Brachylog | 180704T070020Z | Fatalize |
| 056 | Red | 180704T063704Z | Galen Iv |
| 006 | 05AB1E | 180704T063536Z | Emigna |
| 011 | CJam | 180704T054409Z | Esolangi |
| 055 | Haskell | 180704T005719Z | Amphibol |
| 025 | JavaScript Node.js | 180704T025434Z | tsh |
| 044 | Python 2 | 180704T021002Z | Uriel |
| 012 | APL Dyalog | 180704T005420Z | Uriel |
| 004 | Jelly | 180704T014205Z | Dennis |
| 019 | Cubix | 180704T014155Z | MickyT |
| 006 | Canvas | 180704T002700Z | dzaima |
| 037 | Haskell | 180704T005912Z | Doorknob |
| 013 | APL Dyalog Classic | 180704T005835Z | Adalynn |
| 006 | Jelly | 180704T002106Z | dylnan |
Swift 6, 42 bytes
let p={(0...$0).map{Int("\($0)\($0+1)")!}}
Bespoke, 186 bytes
find N&N+I,given N
program counter is stored as zero
display it if that equals a nonzero sum
increase
display it once always
I put in chr to border by it:spaces
continue counting in loop
Raku, 23 bytes
{say +($!++~$!)for ^$_}
{say # print
+( # coerce int
$! # special var ($! = 0)
++ # post inc
~ # concat
$! # new $x
)for ^$_} # until N iterations
SAKO, 85 bytes
PODPROGRAM:F(N)
*)DRUKUJ(9,0):(I-1)×10*ENT(((LN(I))/LN(10))+1)+I
POWTORZ:I=1(1)N
WROC
I use here a quite simple approach:
We take a number I, multiply it by 10*(length of I+1), add I+1 to it, and print the result. It's repeated until I+1 = N.
I just use here I-1 and I instead for some byte saving.
Full programme version, 87 bytes
CZYTAJ:N
*1)DRUKUJ(9,0):(I-1)×10*ENT(((LN(I))/LN(10))+1)+I
POWTORZ:I=1(1)N
STOP1
KONIEC
Ruby -n, 32 bytes
Takes input on stdin.
puts 1,(?1...$_).map{_1+_1.succ}
We could save two bytes by using -p but it prints a mixed, ragged array and I hate it:
$_=1,(?1...$_).map{_1+_1.succ}
Tcl, 52 bytes
proc C n {puts 1;time {puts [incr i][expr $i+1]} $n}
proc C {n i\ 0} {time {puts [expr $i?$i:""][incr i]} $n}
PS: I will golf it more later!
jbasher2, 170 bytes
create a with type number
create b with type number
ask for input
set that to a
set 1 to b
output 1
while b < a
output inline b
add 1 by b
set that to b
output b
endwhile
lol
Uiua 0.15.0-dev.2, 9 bytes SBCS
⧈⍜∩°⋕⊂⇡+1
I love the leniency of under both.
Explanation
⧈⍜∩°⋕⊂⇡+1
⇡+1 # range 0,...,n
⧈ # for each pair...
∩°⋕ # un-parse (stringify) both
⊂ # join together
⍜∩°⋕ # then un-un-parse the string
YASEPL, 16 bytes
=a'=b+<`1~+<}2,a
explanation:
=a'=b+<`1~+<}2,a packed
=a' get amount of numbers to print (A)
=b+< initialize, increment, and output the incrementer (B)
`1 }2,a while B < A....
~ print B inline
+ increment
< print B with newline
cQuents, 11 6 bytes
&$-1~$
Explanation
& Mode & for input n, output first n terms in sequence
each term is
$ current index
-1 - 1
~ concat
$ current index
Desmos, 41 bytes
f(k)=10^{ceil(log(n+2))}n+n+1
n=[0...k-1]
This works by shifting n over a number of place values determined by how many digits n+1 is. This shifted n is then simply added to n+1 to get the final result.
Vyxal, 29 bitsv2, 3.625 bytes
ʀzṅ⌊
Explained
ɾzṅ
ɾ # range [1, input]
z # overlapping pairs (equivalent to 2l)
ṅ # concatenate each pair into a single string
SAS
Input is passed by:
%let n=123;
4GL - 38
data;
do i=1to &n;x=cats(i-1,i)+0;put x;end;
run;
The data; and run; are obligatory for every 4GL data step, so the code effectively doing the job is in line 2.
Macrolanguage - 44
%macro
m(n,x);%do i=1%to&n;%put&x&i;%let x=&i;%end;
%mend;
The %macro and %mend; are obligatory for every Macroprogram, so the code effectively doing the job is in line 2.
To run macro execute:
%m(&n)
Scratch, 107 bytes
define(y
delete all of[x v
set[i v]to(0
repeat(y
add((join(i)((i)+(1)))-())to[x v
change[i v]by(1
end
say(x
I would've used for each, but scratchblocks doesn't support it.
Rockstar, 76 bytes
listen to N
X's 0
while N-X
let S be X
let X be+1
let S be+""+X
cast S
say S
Try it here (Code will need to be pasted in)
listen to N :Read input string into variable N
X's 0 :Initialise X as 0
while N-X :While X is less than N
let S be X : Assign X to S
let X be+1 : Increment X
let S be+""+X : Append X to S
cast S : Cast S to an integer
say S : Output S
Go, 122 bytes, using string operations
import(."strconv";."fmt")
func f(n int)(o[]int){for i:=0;i<n;i++{k,_:=Atoi(Sprintf("%d%d",i,i+1))
o=append(o,k)}
return o}
Go, 125 bytes, using formula
import."math"
func f(n int)(o[]int){for i:=0;i<n;i++{o=append(o,i*int(Pow10(1+int(Floor(Log10(float64(i)+1)))))+i+1)}
return}
Uses the formula \$a(n) = n\cdot10^{1 + \lfloor\log_{10}(n+1))\rfloor} + n + 1\$ for \$n \ge 0\$.
Vyxal, 5 bytes
ʀ¨pJ⌊
Explained
ʀ¨pJ⌊
ʀ # Inclusive zero range
¨p # each overlapping pair
J # merge
⌊ # floor
J-uby, 26 25 bytes
-1 byte thanks to Razetime
:*|:*&(-[I,:+&1]|:join|Z)
Explanation
:* | # Range 0..n-1, then
:* & ( # map with ...
-[I, :+ & 1] | # [m, m+1] (I is identity), then
:join | # join, then
Z # convert to int (for special case "01")
)
Ly, 12 bytes
Rrp[:u`u' o]
This is pretty brute force, but short enough to warrant a post I think...
R - generate an inclusive rangefrom "0" to the STDIN number
rp - reverse the stack, delete the "0"
[ ] - for each number on the stack...
:u - duplicate number, print it
`u - increment the number, print it
' o - print a space
AWK, 26 bytes
a=$1{for(;a;a--)$a=a a+1}1
Turns out that a version in AWK is pretty short too, so here's that one...
a=$1 - stash the number we want
{ } - code always runs if STDIN>0
for(;a;a--) - loop for N, N-1, N-2, ... 1
$a=a a+1 - set positional var to N appended w/ N+1
1 - print all the positional vars we just set
This really just abuses the fact that AWK will reset the positional variable count if you set them to a value. And it uses a "truthy" condition with no associated code block to print them all.
Gema, 42 characters
*=@repeat{*;${n;}@set{n;@add{${n;};1}}$n }
Sample run:
bash-5.1$ gema '*=@repeat{*;${n;}@set{n;@add{${n;};1}}$n }' <<< 5
1 12 23 34 45
jq, 30 27 characters
1,(range(1;.)|"\(.)\(.+1)")
Sample run:
bash-5.1$ jq -r '1,(range(1;.)|"\(.)\(.+1)")' <<< 5
1
12
23
34
45
Nim, 70 bytes
import sugar,sequtils,math
s(x=>toSeq(1..x).map y=>(y-1)*10^len($y)+y)
Fig, \$8\log_{256}(96)\approx\$ 6.585 bytes
Mrx'_Jx}
Mrx'_Jx}
Mrx' # For every number in the range [0, input)
} # Input + 1
Jx # Prepend the input to that
_ # Parse as number to remove leading 0s
Blossom, 88 bytes
rule e<int x>[1(x)]=>[1(x-1),2(str(x)+str(x+1))];rule c[1(0)]=>[];e!c
Blossom is a graph programming language I'm working on. It can only take graphs as inputs, so this programme expects a graph comprising a single node with its label an integer. It returns a graph of connected edges to form the closest to an array I can get, and the resultant graph is printed to output.
An unminified version of the code is this:
rule expand <int x>
[ 1 (x) ]
=> [ 1 (x-1), 2(str(x)+str(x+1)) ]
where x > 0;
rule clean
[ 1 (0) ]
=> [];
expand! clean
It defines two rules: one called expand, which (while there is a node with an integer-valued label in the current graph) creates another node with its increment concatenated, and lowers the value.
This rule also has the condition that x is greater than 0.
The ! executes this rule for as long as it can be applied on the graph, so in this case it will execute until x is 0. And then the clean rule removes this 0 node.
Blossom was not made for golfing, but it doesn't do too badly, I don't think., considering what it is. There currently isn't really an easy way for people to test blossom code (and the interpreter I'm working on at the moment is not quite finished and a little buggy), but this isn't exactly a competing entry!
><>, 15 13 bytes
ln1-:?!;aoln:
We take in the input as a command line argument.
Thanks to @jo king for 2 byte loss (noticing the input loop value could be used as stack length.
Explanation (simple):
ln1-:?!;aoln:
ln : Add the length of the stack to the stack and print.
1-:?!; : Take 1 off the input loop and check if zero, if 0, end.
ao : Print new line
ln: : Add the length of the stack to the stack, print and duplicate the input loop.
MBASIC, 102 94 bytes
1 INPUT N:FOR I=0 TO N-1:IF I>0 THEN PRINT MID$(STR$(I),2);
2 PRINT MID$(STR$(I+1),2);" ";:NEXT
Output:
? 3
1 12 23
? 10
1 12 23 34 45 56 67 78 89 910
? 16
1 12 23 34 45 56 67 78 89 910 1011 1112 1213 1314 1415 1516
Could have been much cleaner, but the STR$(n) number-to-string conversion function returns with a leading space that had to be dealt with.
Turns out the variable for NEXT and the trailing PRINT are not needed, saving 8 bytes.
K (ngn/k), 13 bytes
{.,/$x+!2}'!:
! generate the list 0 1 ... n-1
{ } is a function with argument x
' applied to each
!2 is 0 1
x+!2 is x, x+1
$ format as strings
,/ concatenate
. evaluate (convert to number)
Gol><>, 11 bytes
IFLL?nLPN|;
Explanation:
IFLL?nLPN|;
I //Take a number as input
F //Loop as many times as the input specified
LL // Push the loop counter twice to the stack (same as L:)
?n // Check wether the count is zero, if not print the counter as the first digit
LP // Push the loop counter and add 1
N // Output the next digits of the number with nl
|; //Exit code
MathGolf, 8 6 5 4 bytes
{└§p
Outputs a newline separated series.
Explanation:
{└§p
{ Start a loop over the range(0, input)
└ Push the top of stack (implicitly the index of the loop) + 1
§ Concatenate the two (this removes leading 0s)
p And print the value
Runic Enchantments, 33 bytes
/01iR1-:0)?;{1+:
\$1<\}$q}:+1{$ '
Uncompressing the entry sequence and moving the reflectors to the other side:
>1$01iR1-:0)?;{1+:\
\}$q}:+1{$ '/
Entry sequence (>1$01i) is fairly straight forward. Push and print 1, push 0, push 1, read input and push it to the top of the stack.
At R we enter the program's main loop (unrolled with directional control characters removed):
1-:0)?;{1+:' ${1+:}q$}
At this point the stack is [0,1,i] where i is the input value.
The loop subtracts 1 from the input value (1-), compares it to greater than 0 (if true, skip terminator, else terminate; :0)?;).
Then a series of stack manipulations ({1+:{1+:}) and increments to result in [2,(i-1),1,1,2] as well as printing a space (' $). q then concats the top two items on the stack, which is then printed (giving 12 in the output stream).
Finally the stack is rotated once more, leaving [1,2,(i-1)] as the input to the next loop iteration.
Bonus challenge: using two IPs? 40 bytes
>1$0iR1-:0)?;1{+:' \
> F1iU }$~?=am$?=9m/
As there's no way to clone the input to a second instruction pointer (I have thought about stack cloning, so this may be possible in the future, but the spec for it would be difficult to implement), we have to read it from the input stream twice.
Flow results in the second pointer being a step behind the first (avoiding merging) and the Fizzle lets us distinguish the two IPs, letting one print a space and the other discards it. I can't figure out a shorter way of performing this check.
However if it allowable to print two spaces as a separator it can be reduced to this (30 bytes):
>1$0iR1-:0)?;1\
> F1iU}$:+{$ '/
input: 4 4
output: 1 12 23 34
But this is an admittedly dubious answer due to how it has to take input, but 3 bytes shorter than the single IP answer, which is interesting.
Update: Stack transfer
Getting the two pointers to enter the T command in the right execution order is a huge pain. The remaining two spaces in this program can't be removed, as it messes with the timing, but it avoids having to supply the input value twice. Prints 2 spaces between each entry in the sequence (35 bytes).
>1$0y TR1-:0)?;1\
>1i:1/U}$:+{$ '/
Pyth, 9 8 6 bytes
ms+`dh
Explanation:
- implicit output
m - map function with argument d:
+ - concatenate
d - argument d
` - to string
h - into implicit d + 1
- into Q (implicit input)
Shakespeare Programming Language, 310 bytes
,.Ajax,.Ford,.Page,.Act I:.Scene I:.[Enter Ajax and Ford]Ford:Listen tothy.Ajax:You cat.Open heart.[Exit Ajax][Enter Page]Scene V:.Ford:Am I worse Ajax?If notlet usScene X.You be twice the sum ofa cat a big big cat.Speak thy.Page:Open heart.You be the sum ofyou a cat.Open heart.Let usScene V.Scene X:.[Exeunt]
Pepe, 68 bytes
RrEEEEEREeErREEREEEEEREErEEEEEeEErEEEereEEreeErEEEEEeeEReerREEREeRee
Previous code has errors when giving input 0, so this is fixed!
Explanation:
# Preparation
RrEEEEE # Stack r: [0, 1]
REeE # Stack R: [input]
# Loop
rREE # create label input (r flag: skip until REe)
REEEEE # increment input (loop preparation)
REE # create label input
rEEEEEeEE # join all
rEEEe # move r pointer to last
reEE # output as int
reeE # output newline "\n"
rEEEEEeeE # increment all
Ree # repeat if input != last content of stack
rREE # create label input + 1 (r flag: skip until REe)
REe # stop skipping commands
Ree # if not 0, go to loop
Python 2, 42 bytes
I know there are plenty of shorter answers already.
a=0
exec"print`a`[:a]+`a+1`;a+=1;"*input()
VBA (Excel), 31 bytes
using immediate window and Cell [A1] as input
for x=1to[a1]:?int(x-1 &x):next
Noether, 15 bytes
I(iWi1+W+WP?!i)
Explanation
I( ) - Loop until the top of the stack equals the input
iW - Push i and convert it to a string
i1+W - Add one to i and convert to string
+ - Concatenate two strings
WP - Convert string to a number and print it
? - Print a newline
!i - Increment i
Ruby, 34 33 bytes
->n{$><<i||=p(1);p(i+=1)<n&&redo}
Pseudocode:
loop
if i is undefined
set i to 1
print 1
print newline
end if
print i
increment i by 1
print i
print newline
if i >= n
break and return
end if
end loop
Lua, 62 bytes
loadstring't={1}for i=2,(...)do t[#t+1]=(i-1)..i end return t'
Explanation
This is an anonymous function.
t={1} -- initializes the return table, with the number 1 already in it
for i = 2, (...) do -- loop from 2 to the number of the input
-- (this is actual code, ... gets the arguments of the program/function
t[#t+1] = (i-1)..i -- append to the table i-1 concatenated with i
end
return t -- returns the table
Bash, 56 bytes
echo 1;for i in $(seq $(($1-1)));do echo $i$((i+1));done
A pretty naive approach.
TI-Basic, 22 bytes
:seq(A,A,1,Ans
:Ans+(Ans-1)10^(1+int(log(Ans
Haskell, 35 bytes
f n="1":map(show.(-1+)<>show)[2..n]
Explanation / Ungolfed
The operator (<>) is the addition of Semigroups, in case of the Semigroup a -> b (where b needs to be a Semigroup) it is defined as:
(f <> g) = \x-> f x <> g x
And in case of the Semigroup String it is the same as concatenation, so the code becomes:
f n = "1" : map (\x-> show (x-1) ++ show x) [2..n]
1 (imports (<>) since it's not part of the Prelude in GHC 8.2.2)
Kotlin, 48 bytes
{"1, "+(2..it).map{"$it${it+1}"}.joinToString()}
Yes I know, I could save 1 more byte by removing the blank behind the first comma, but it looks nicer with it :-)
QBasic, 60 53 bytes
INPUT n
?1
FOR i=2TO n
?STR$(i-1)MID$(STR$(i),2)
NEXT
A math-based solution, because converting numbers to strings in QBasic is a lot more complicated than it ought to be. Nope, strings are still shorter, you just have to special-case the first item. The problem with STR$(i) is that it adds a space to the start of positive numbers, so we take all but the first character by using MID$. Other than that, it's pretty straightforward.
Twig, 72 bytes
Twig is very verbose, causing some issues when trying to reduce the length.
{%macro f(a)%}{%for i in 1..a%}{{o~i}}
{%set o=i%}{%endfor%}{%endmacro%}
This requires that "strict variables" is disabled (default).
How to use?
Simply import the macro and call it:
{% import "fn.twig" as fn %}
{{ fn.f(<number>) }}
You can test it on https://twigfiddle.com/lah1a5
Python 2.7, 52 bytes
I tried my best. Not yet familiar with this golfing thing.
def a(n):
for e in range(n):
print int(`e`+`e+1`)
The int() removes the leading zero in the first output, as specified in the rules.
C, 39 bytes
x(n){n&&x(n-1);printf("%d%d, ",n,n+1);}
eliminated the ternary conditional and shaved off 3 bytes.
RAD, 72 bytes
0,(⊢+10×⊣)⍁¨∊¨(⌽∘⌊(⊢|⍨10*(⍳(1+∘⌊10⍟⊢)))÷10*1-⍨(⍳(1+∘⌊10⍟⊢)))¨¨(⊢,1+⊢)¨⍳⎕
I wanted to try to see if I could do it in a "non-mathematical" way by splitting a number up into its digits.
DC, 33 bytes
si[lidZAr^spd1-dsilp*+li0<d]dsdxf
Explanation
si[lidZAr^spd1-dsilp*+li0<d]dsdxf Whole program.
si Save the value on the stack to the i register.
[ ]dsdx Create a macro, duplicate it, store it in the d register, and execute it.
li Put the value from the i register on the stack.
dZ Duplicate the top value, and change it to the number of digits it has.
Ar Push 10 on the stack, and reverse the top two values.
^sp Do 10^x, and store it in the p register.
d1- Duplicate the top value, and subtract 1 from it.
dsi Duplicate the top value, and store it in the i register.
lp*+ Put the value from the p register on the stack, and multiply it by the the value we just put in the i register. Then, add the top two values together.
li0<d Put the value from the i register and then 0 on the stack. If 0 < li, then we run the d macro again.
f Print the stack.
Input is the number of numbers to be generated, on the stack.
Output is printed.
Python 3, 55 48 47 43 bytes
f=lambda n:n-1and f(n-1)+[f"{n-1}{n}"]or[1]
Recursive function that takes an integer and returns a mixed list of strings and numbers.
MATLAB 45 63 bytes
@(j)eval('for a=0:j-1;disp([num2str(a)*a/a,num2str(a+1)]);end')
Somewhat ugly *a/a in order to avoid printing leading zero for the first element
Fixed by wrapping into disp and anonymous function
D, 93 bytes
import std.math;_[]f(_)(_ n){_[]k;foreach(i;0..n)k~=++i+10^^(cast(_)i--.log10+1)*i;return k;}
I couldn't find a nice (short) solution that evades an import, and this was the shortest of the bunch.
Rutger, 108 bytes
x=$Input;
f=For[$x];
f=f[@i];
f=f[{p=Subtract[$i];r=Concat[Str[p[1]]];Print[Integer[r[Str[$i]]]];}];
Do[$f];
Ungolfed
input = $Input;
for = For[$input];
for = for[@index];
for = for[{
dec = Subtract[$index];
ret = Concat[Str[dec[1]]];
Print[Integer[ret[Str[$index]]]];
}];
Do[$for];
The basic concept of Rutger is the lack of multi-adic commands: every command takes a single argument, and if the command needs multiple argument, each new call returns a curried function.
First, we take evaluated input and store it in \$x\$. We then create a For object, a tri-adic command. The first two calls create a variable \$f\$, that will loop \$x\$ times, using the iteration variable \$i\$, starting at \$i := 1\$. The third call indicates the code to be run:
{p=Subtract[$i];r=Concat[Str[p[1]]];Print[Integer[r[Str[$i]]]];}
This creates a block of code containing 3 statements. Our first two are variable assignments. First, we create a curried function Subtract[$i], which prepares to subtract a value from \$i\$. This curried function is saved in the \$p\$ variable. Next, we create a second curried variable, \$r\$, which starts by calling p[1], subtracting \$1\$ from \$i\$. We then convert \$i-1\$ to a string and pass it as the first argument to the Concat function. Finally, we convert \$i\$ to a string, concatenate it to \$str(i - 1)\$ and convert it to an integer to reomve the leading \$0\$ when \$i = 1\$. This is then printed.
The last line, Do[$f];, runs the for loop.
yup, 48 bytes
0eee0ee-0ee-*:0e#[:@]0e-{]:[:]-:#0e0~--#]:@]0e-}
Explanation
yup only knows of a few commands. To modify data, I'll be using 0 (nilad pushing that number), e (natural exponentiation), and - (subtraction).
For example, the snippet 0e is equal to 1, since \$e^0=1\$.
This program is divided into two parts: initialization and iteration.
Initialization
0eee0ee-0ee-*:0e#[:@]0e-
0eee pushes \$e^e\approx15.1543\$ and 0ee pushes \$e\approx2.7183\$. Thus, the expression 0eee0ee-0ee- pushes:
$$e^e-e-e\approx9.7177$$
This encodes 0x10 (the linefeed), since numbers are rounded to the nearest integer before being outputted. This is our numeric separator.
The next part is to initialize the stack with data. *: pushes the input twice, and 0e# outputs a 1. [:@] outputs a linefeed without popping it from the stack, and 0e- decrements the input. This handles the edge case of outputting 1 instead of 01. Rather than handle this with a conditional, hardcoding the first entry is shorter.
Iteration
{]:[:]-:#0e0~--#]:@]0e-}
{...} loops while the TOS is defined and positive. In this case, it will stop when it hits zero. Each iteration starts off with a stack like this:
[9.7177, input, iterator]
iterator starts at input - 1. ]:[:]- calculates input - iterator and gives us our true iterator value. Then, :#0e0~--# first outputs the true iterator then the same number plus 1, where 0e0~-- encodes \$-(-n-e^0)=-(-n-1)=n+1\$. Then, ]:@] restores the stack to its initial shape and 0e- subtracts 1 from the iterator, continuing our loop. This repeats until iterator reaches 0, at which point the loop stops and the program terminates.
Attache, 15 bytes
{N!_'-~_}=>Iota
Explanation
{N!_'-~_}=>Iota
{ }=> map the inside function:
Iota (over each number k from 0 to n-1)
' array concatenate:
_ k
-~_ k+1
N! convert [k, k + 1] to an integer (concatenates and returns a number)
Husk, 11 9 bytes
-2 thanks to @BMO!
mSöd+d←dḣ
Explanation
m map( )
S <*>
ö ( .). . .
d fromDecimal
+ (++)
d toDecimal
← (+1)
d toDecimal
.
ḣ (\n->[1..n])
mSöd+d←dḣ map((fromDecimal.).(++).toDecimal.(+1)<*>toDecimal).(\n->[1..n])
Momema, 36 bytes
z0w+1=*0-8*0w00+1*0-8*0-9 10z=+_M-*0
Try it online! Requires the -i interpreter flag.
Explanation
# i = 0
d 0 # d0: nop # do {
i (+ 1 =*0) # i0: jump to i(![0]) # if i {
-8 *0 # print [0] # print i
i 0 # i1: nop # }
0 (+ 1 *0) # [0] = [0] + 1 # i += 1
-8 *0 # print [0] # print i
-9 10 # print chr(10) # print \n
d =(+ _M -*0) # d1: jump to d(!!(input - [0])) # } while (input - i != 0)
The Momema reference interpreter provides an "interactive mode", enabled by -i, which is intended to be used on the command line.
One of the features it allows is the ability to add holes, denoted by _, which effectively allow one to substitute an integer read from STDIN into an expression. This is already shorter than *-8 (read from memory-mapped I/O location -8), which does the same thing without interactive mode and without displaying a prompt to STDERR.
Crucially, holes can also be named with a sequence of capital letters after the _. Evaluation of named holes is memoized. Input will be read the first time a named hole is evaluated but subsequent evaluations of a hole with the same name will reuse the input number. This means that we can use _M to stand in for "the input", but input will only be read on the first iteration of the loop.
dc, 29 bytes
[d1-d0<F]dsFx+p[npz1<G]sGz1<G
This is a good showing for dc because its printing capabilities are so limited, but line up perfectly with the challenge spec. Input is from the stack (and must be the only thing on the stack), output is to stdout. There's some duplication near the end I can't figure out how to get rid of without breaking the case n=1
Explanation
F will be the macro [d1-d0<F]
d copy the top of the stack
1- decrement
d0<F repeat (tail recursion) until a 0 is on top
G will be the macro [npz1<G]
n print the top (pop, but no newline)
p print the new top (newline, but no pop)
z1<G repeat (tail recursion) until only one number is on the stack
Full program (example input: 4)
[d1-d0<F]dsFx Store F and run it: new stack is 0 1 2 3 4
+ Drop the zero (can't just recurse to 1, or n=1 breaks)
p Print (no pop) the '1': stack is 1 2 3 4
[npz1<G]sG Store G
z1<G Run G if there's more than one number on the stack
C Sharp 51 bytes
n=>new int[n].Select((_,o)=>int.Parse($"{o}{o+1}"))
K (oK), 12 bytes
Solution:
,/'$1,2':1+!
Examples:
,/'$1,2':1+!1
,,"1"
,/'$1,2':1+!2
(,"1"
"12")
,/'$1,2':1+!3
(,"1"
"12"
"23")
,/'$1,2':1+!10
(,"1"
"12"
"23"
"34"
"45"
"56"
"67"
"78"
"89"
"910")
Explanation:
,/'$1,2':1+! / the solution
! / range 0..n
1+ / add 1
2': / sliding window of 2
1, / prepend 1
$ / convert to strings
,/' / flatten each
Javascript, 43 44,46,49,53 bytes
n=>[...Array(n)].map((_,a)=>~~(a+(a+1+"")))
Previous versions :
n=>[...Array(n)].map((_,a)=>~~(a+(""+ ++a)))
n=>[...Array(n)].map((_,a)=>0- -(a+(""+ ++a)))
n=>[...Array(n).keys()].map(a=>0- -(a+(""+ ++a)))
n=>[...Array(n).keys()].map(a=>parseInt(a+(""+ ++a)))
Saved 3 bytes thanks to @Shaggy's solution (which is better than mine) to remove .keys()
dc, 34 bytes
sj1psi[lid1+dsiZAr^*li+pzlj>M]dsMx
Completely different (and less golfy, unfortunately) approach than Sophia's dc answer. I juggle a lot of register activity here that I wish I could cut down, seems the likeliest way to golf a couple of bytes. Expects input as the sole stack entry.
sj1psi stores the input into register j, prints the initial 1, and stores 1 in register i. Macro M duplicates i, increments it, and then multiplies it by 10 to the power of however many digits the incremented value has (ZAr^*). Fetches the newly incremented version, and adds the two together. Compares register j to the number of entries on the stack, and runs until they match.
PHP, 33 32 bytes
while($argv[1]--)echo" $i".++$i;
Old version
for(;$i<$argv[1];)echo" $i".++$i; // 33 bytes
Yabasic, 37 bytes
An anonymous function that takes input from STDIN and outputs to STDOUT.
Input""n
?1
For i=2TO n?i-1,"",i
Next
-14 bytes thanks to @ErikF
Excel VBA, 29 bytes
An anonymous VBE immediate window function that takes input from cell [A1] and outputs to the console.
?1:For i=2To[A1]:?i-1 &i:Next
R, 30 29 bytes
An extra byte thanks to @Giuseppe
10^nchar(n<-1:scan())*(n-1)+n
A mostly mathematical solution, except for using nchar() rather than floor(log10()). I was really surprised that it came in shorter than the string version.
Clojure, 54 bytes
#(reduce(fn[a n](conj a(str n(inc n))))[1](range 1 %))
Just a reduction over a range between 1 (inclusive) and n (exclusive).
(defn concat-n-n+1 [n]
(reduce (fn [acc m]
(conj acc (str m (inc m))))
[1]
(range 1 n)))
The first element of the list is a number, the rest are strings. This seems to be allowed by the spec.
Forth (gforth), 33 bytes
: f dup 1 ?do i . i 1 .r loop . ;
Explanation
Loops through all numbers in range and outputs the number twice, the first with a space appended, and the second without.
This results in the first output being appended to the previous output. To fix the last case, the input is outputted so that it can be appended to the last number in the loop.
Code Explanation
: f \ start a new word definition
dup 1 \ duplicate the input and put a 1 on the stack
?do \ begin counted loop from 1 to n (does nothing if 1 == n)
i . \ output loop index with a space appended
i 1 .r \ output loop index right-aligned with minimum 1 character length
loop \ end the loop
. \ output the input we duplicated earlier
; \ end the word definition
Powershell, 27 26 bytes
1.."$args"|%{"$p$_";$p=$_}
-1 byte: thanks AdmBorkBork
Test script:
$f = {
1.."$args"|%{"$p$_";$p=$_}
}
&$f 1
""
&$f 2
""
&$f 3
""
&$f 10
""
&$f 46
Groovy, 35 bytes
{(0..<it)*.with{""+it+++it as int}}
I came up last minute with the idea of using *.with instead of .collect. I have no idea what it+++it parses to but whether it's it++ + it or it + ++it they both do the same thing. I tried to think of a way of getting rid of the < in ..< by turning it into 1..it and decrementing but I don't think it would get any shorter.
Shakespeare, 703 bytes
Q.Ajax,.Ford,.Act I:.Scene I:.[enter Ajax and Ford]Ford:Open mind!Scene V:.Ajax:You is the sum of thyself the sum of myself the sum of a big bad fat old red pig a big bad fat old lie!Ford:Open mind!Is you nicer zero?Ajax:If so, you is twice the sum of the sum of twice thyself twice thyself thyself!If so,Let us Scene V!Ford:You a cat!Open heart!Scene X:.Ajax:You is the sum of thyself a pig!Is you worse than a cat?If so,let us Scene C.Remember thyself.You is the sum of the sum of a big old red cute rich cat a big old red cute joy a big old pig!Speak mind!You is a big old red cute rich cat!Speak mind!Recall!Ford:Open heart!You is the sum of thyself a joy!Open heart!Let us Scene X.Scene C:.[exeunt]
ungolfed version
127421th Night.
Ajax, likes to read the stars.
Ford, someone Ajax can always count on.
Act I:.
Scene I: Ajax reads a star.
[enter Ajax and Ford]
Ford: Open your mind!
Scene V: Ford counts what ajax has learned.
Ajax: you are the sum of thyself and the sum of myself and the sum of a big bad fat old red pig and a big bad fat old lie!
Ford: Open Your mind! Are you nicer than zero?
Ajax: If so, you are twice the sum of the sum of twice thyself and twice thyself and thyself!
If so, Let us Scene V!
Ford: You are a cat! Open your heart!
Scene X: Ajax and Ford recall the nights.
Ajax: You are the sum of thyself and a pig! Are you worse than a cat? If so, Let us Scene C.
Remember thyself.
You are the sum of the sum of a big old red cute rich cat and a big old red cute joy and a big old pig!
Speak you mind!
You are a big old red cute rich cat! Speak your mind! Recall your finest hour!
Ford: Open your heart! You are the sum of thyself and a joy! Open your heart! Let us Scene X.
Scene C: Fin.
[exeunt]
ABAP, 101 bytes
Not really a golfing language, but I'm having a lot of fun with it
WHILE x<w.
CLEAR z.
IF x=1.
WRITE x.
ELSE.
CONCATENATE y x INTO z.
WRITE z.
ENDIF.
y=x.
x=x+1.
ENDDO.
W is the input term, X is the counter from 1, Y is X-1 from the second pass onward, Z is concatenated string.
Jelly, 3 bytes
ŻVƝ
A monadic link accepting an integer which yields a list of integers
How?
ŻVƝ - Link: integer e.g. 59
Ż - zero-range [0,1,2,3,4,5,6, ... ,58,59]
Ɲ - apply to each pair: i.e: [0,1] or [5,6] or [58,59]
V - evaluate* jelly code 1 or 56 or 5859
- -> [1,12,23,45,56, ... 5859]
* When given a list V actually joins the Python string values and evaluates that
...so e.g.: [58,59] -> ['58','59'] -> '5859' -> 5859
Panacea, 6 bytes
re
D>j
Explanation:
r Range [0.. input]
e Map each element with the following line
D Duplicate
> Increment
j Join digits; multiply by ten and add
Since this works with integers, it removes the preceding 0.
C# (Visual C# Compiler), 46 bytes
If you are allowed to have some using static directives in the top whose bytes do not count:
n=>1+Concat(Range(1,n-1).Select(x=>","+x+++x))
Will explode if input n is 0.
It is interesting that, while the C# rules say ","+x+++x means ( "," + (x++) ) + x, if it had meant ( "," + x ) + (++x) instead, the program would still work!
C# (Visual C# Interactive Compiler), 103 71 64 56 bytes
Golfed Try it online!
i=>{for(int x=0;x<i;)Write($"{(x>0?$",{x}":"")}{++x}");}
Ungolfed
i => {
for( int x = 0; x < i; )
Write( $"{( x > 0 ? $",{x}" : "")}{ ++x }" );
}
Full code
Action<Int32> a = i => {
for( int x = 0; x < i; )
Write( $"{( x > 0 ? $",{x}" : "")}{ ++x }" );
};
Int32[]
testCases = new Int32[] {
1,
2,
3,
10,
};
foreach( Int32[] testCase in testCases ) {
WriteLine( $" Input: {testCase}\nOutput:" );
a(testCase);
WriteLine("\n");
}
Older versions:
v1.2, 64 bytes
i=>{for(int x=0;x<i;)Write($"{(x>0?$",{x}":"")}{++x}");}v1.1, 71 bytes
i=>{for(int x=0;x<i;)System.Console.Write($"{(x>0?$",{x}":"")}{++x}");}v1.0, 103 bytes
i=>{for(int x=0;x<i;)System.Console.Write($"{(x>0?",":"")}{x++*System.Math.Pow(10,$"{x}".Length)+x}");}
Releases
- v1.3 -
- 8 bytes- RemovedConsolethanks again to raznagul - v1.2 -
- 7 bytes- RemovedSystemthanks to raznagul - v1.1 -
-32 bytes - v1.0 -
103 bytes- Initial solution.
Notes
- None
C# (Visual C# Compiler), 54 bytes
Uses space as seperator character.
n=>{var r="";for(;n-->1;)r=" "+n+(n+1)+r;return"1"+r;}
Ungolfed full code:
class P
{
static void Main()
{
System.Func<int, string> f =
n =>
{
var r = ""; //Declare variable for the result
for (; n--> 1;) //Loop until n is 1
r = //Set the result to:
" " + //Seperator +
n + //Value of n as string
(n + 1) + //Value of n + 1 as string
r; //Previous content of the result
return "1" + r; //Return 1 (first item) + the result.
}
;
System.Console.WriteLine(f(1));
System.Console.WriteLine(f(2));
System.Console.WriteLine(f(3));
System.Console.WriteLine(f(10));
System.Console.WriteLine(f(100));
}
}
Python 2, 42 41 bytes
f=lambda n:n-1and f(n-1)+[`n-1`+`n`]or[1]
Recursive function that returns a mixed list of strings and integers
RAD, 28 27 bytes
(⊢(⊢+⊣×10*1+∘⌊10⍟⊢)1+⊢)¨0,⍳
Must be called like: ((⊢(⊢+⊣×10*1+∘⌊10⍟⊢)1+⊢)¨0,⍳) <value>, as I broke assignment of functions when I implemented shy results.
Note: this should also work in Dyalog APL, and due to that: -1 byte thanks to @Adám!
The ⍳ can either be the APL symbol or the greek one if run in RAD, but must be the APL version ifran in Dyalog APL
MATL, 9 bytes
:"@qV@VhU
% implicit input n
: % range, push 1..n
" % for loop:
@ % push for loop index
q % decrement
V % convert to string (num2str)
@ % push for loop index
V % convert to string (num2str)
h % horizontally concatenate
U % convert to number (str2num)
% implicit end of for loop
% implicit end of program, display stack contents
Japt -m, 6 5 bytes
ó2 ¬n
As always, know the flags.
Unpacked & How it works
-m Convert to range and map...
Uó2 q n
Uó2 Construct [U, U+1]
q Join
n Convert to number
Implicit output (Array is printed as comma-delimited values)
Perl 5, 29 bytes
say"@{[1,map$_-1 .$_,2..<>]}"
Java, 48 bytes
String f(int n){return--n>0?f(n)+","+n+-~n:"1";}
Port of tsh's JavaScript answer. Try it online here.
Ungolfed:
String f(int n) { // recursive function taking an integer as argument and returning a String
return --n > 0 ? f(n) // decrement n and recurse if n is still positive after
+ "," + n // return the result of the recursive call concatenated with n and ...
+ (- ~n) // ... n+1; writing it as -~n gives it precedence over the concatenation
: "1"; // if n is now 0 on the other hand, return "1"
}
Python 2, 43 bytes
lambda i:[1]+[`x`+`x+1`for x in range(1,i)]
First element is an integer, the rest are strings.
Perl 6, 19 18 bytes
{(^$_ Z~1..$_)X+0}
Anonymous code block that zips the range 0 to n-1 with 1 to n using the concatenation operator, then adds 0 to every element to force it to a number and remove leading 0s.
Brachylog, 6 bytes
⟦s₂ᶠcᵐ
Explanation
⟦ Range: [0, …, Input]
s₂ᶠ Find all substrings of length 2
cᵐ Map concatenate
05AB1E, 6 bytes
>GNJ,N
Explanation
>G # for N in [1 ... input]
N # push N
J # join stack
, # print
N # push N (for next iteration)
LεD<ìï would work for same byte count but with list output
Haskell, 57 55 bytes
f n=read<$>zipWith((.show).(++).show)[0..][1..n]::[Int]
A function which takes a number and returns a list.
EDIT: -2 Bytes thanks to Cat Wizard
Jelly, 4 bytes
ḶżRV
How it works
ḶżRV Main link. Argument: n
Ḷ Unlength; yield [0, ..., n-1].
R Range; yield [1, ... n].
ż Zipwith; yield [[0, 1], ..., [n-1, n]].
V Eval; cast each array to string and evaluate, yielding integers.
Cubix, 19 bytes
I.1.W)>OSo;u.uO;@!-
This wraps onto the cube as follows
I .
1 .
W ) > O S o ; u
. u O ; @ ! - .
. .
. .
Got a little room to play with yet, but at the moment
Wredirect to the top face heading downI1>set up the stack with the input and 1 then redirect into the main loopOSo;uoutput the top of stack, add space to stack, output, remove and uturn-!@;Ou)subtract TOS from input, if 0 halt else pop result, output TOS, uturn and increment TOS. Back into the main loop.
Canvas, 6 bytes
ŗ²;+┤]
Explanation:
{ ] map over 1..input
ŗ convert to string (required as `+` needs 1 arg to be a string to not add)
²; place a 0-indexed version of the index below TOS
+ join the two
┤ cast to number
ŗ²×┤] (or even ²×┤]) would work if I didn't try to push the absolute most out of characters and didn't make × - reverse add - do not that when not receiving 2 strings.
Jelly, 8 6 bytes
ṭ’DFḌ)
ṭ’DFḌ) Monadic link with argument n
) For each int in the range 1..n
’ n-1
ṭ [n-1, n]
D Digits of n-1 and n
F Flatten into one list
Ḍ Convert back to an integer.
