| Bytes | Lang | Time | Link |
|---|---|---|---|
| 007 | Pip | 250826T210448Z | DLosc |
| 032 | tinylisp 2 | 230112T041936Z | DLosc |
| 003 | Thunno 2 J | 230610T161342Z | The Thon |
| nan | Fig | 230119T211623Z | Seggan |
| 010 | Pip | 230118T174817Z | Baby_Boy |
| 022 | Julia 1.0 | 230112T201853Z | Ashlin H |
| 018 | J | 230112T215614Z | Jonah |
| nan | 230112T171415Z | The Thon | |
| 090 | Go | 230112T160411Z | bigyihsu |
| 012 | Ly | 230112T093020Z | cnamejj |
| 036 | Arturo | 230112T055150Z | chunes |
| 005 | Pyt | 230112T010606Z | Kip the |
| 004 | Vyxal | 221012T061443Z | DialFros |
| 018 | Braingolf v0.7 | 170530T123902Z | Mayube |
| 009 | MATL | 170530T113541Z | Suever |
| 032 | Zsh | 190403T013340Z | GammaFun |
| 052 | Java 8 | 190308T225749Z | Benjamin |
| 005 | Stax | 190315T210844Z | recursiv |
| 047 | Ink | 190315T192715Z | Sara J |
| 030 | Mouse2002 | 190315T041933Z | MooseOnT |
| 026 | APLNARS | 190315T175924Z | user5898 |
| 017 | dc | 190315T171854Z | Sophia L |
| 010 | APL Dyalog Unicode | 190309T201228Z | voidhawk |
| 044 | Kotlin | 190309T202943Z | snail_ |
| 054 | Common Lisp | 181106T181811Z | Renzo |
| 050 | Kotlin | 190307T133815Z | J00LZ |
| 005 | 05AB1E | 170530T103415Z | Emigna |
| 041 | Forth gforth | 181107T162344Z | reffu |
| 005 | MathGolf | 181107T001604Z | Jo King |
| 008 | Japt P | 170530T131315Z | Oliver |
| 006 | Japt mP | 181106T174715Z | Shaggy |
| 053 | C# .NET Core | 181106T184809Z | Meerkat |
| 016 | K ngn/k | 181106T182639Z | Thaufeki |
| 009 | braingasm | 170610T162535Z | daniero |
| 048 | LOGO | 170610T154340Z | user2027 |
| 051 | Python 3 | 170610T145036Z | Leaky Nu |
| 019 | Röda | 170530T112754Z | user4180 |
| 043 | C gcc | 170610T144311Z | Leaky Nu |
| 037 | Powershell | 170530T135208Z | Danko Du |
| 015 | ><> | 170531T151716Z | Sok |
| 035 | R | 170530T112827Z | user2390 |
| 022 | Perl 5 | 170601T033831Z | Chris |
| 052 | Mathematica | 170530T172427Z | Michael |
| 047 | Haskell | 170530T143137Z | Dan Ambr |
| 015 | Hexagony | 170531T145639Z | Sok |
| 071 | Whitespace | 170531T134730Z | Ephphath |
| 025 | Bash | 170530T120915Z | marcosm |
| 067 | Python 2 | 170530T224608Z | Mikhail |
| 046 | Python 2 | 170530T104311Z | user4594 |
| 017 | Cubix | 170530T201227Z | Giuseppe |
| 037 | R | 170530T195133Z | shadowta |
| 018 | QBIC | 170530T105107Z | steenber |
| 005 | Jelly | 170530T164331Z | Dennis |
| 020 | Retina | 170530T161414Z | Neil |
| 020 | V | 170530T125945Z | nmjcman1 |
| 061 | Java | 170530T152929Z | cheemche |
| nan | 170530T150930Z | Brad Gil | |
| 009 | Pyke | 170530T150433Z | Blue |
| 043 | Scala | 170530T144752Z | Phoenix |
| 030 | JavaScript ES6 | 170530T104059Z | Arnauld |
| 039 | Python 2.7 | 170530T141221Z | Dat |
| 006 | Jelly | 170530T140335Z | steenber |
| 029 | Octave | 170530T140440Z | rahnema1 |
| 030 | AWK | 170530T111104Z | jmriego |
| 052 | Clojure | 170530T134358Z | NikoNyrh |
| 029 | PHP | 170530T105301Z | user6395 |
| nan | 170530T112607Z | bartavel | |
| 007 | Pyth | 170530T115150Z | Jakube |
| 028 | Perl 5 | 170530T113814Z | Dom Hast |
| 012 | CJam | 170530T105352Z | Luis Men |
| 009 | Brachylog | 170530T111059Z | Fatalize |
| 041 | R | 170530T112138Z | JAD |
| 029 | Ruby | 170530T110309Z | G B |
| 022 | Aceto | 170530T111016Z | L3viatha |
| 032 | Mathematica | 170530T105327Z | ZaMoC |
| 010 | CJam | 170530T110116Z | Martin E |
| 061 | Clojure | 170530T104501Z | cliffroo |
| 009 | Actually | 170530T103846Z | user4594 |
Pip, 7 bytes
UEN R,a
Explanation
UEN R,a
,a Range(a) (numbers from 0 up through a-1)
R Reverse
EN Enumerate, replacing each value with an [index; value] pair (zero-based)
U Increment all values
Concatenate together and autoprint (implicit)
This is only the second time I've used the EN operator, despite the fact that it's been around since 2015.
tinylisp 2, 46 32 bytes
(\(N)(} ,(m u({ ,(z(1to N)(to1 N
An anonymous function that takes an integer and returns a string. Try It Online!
Explanation
(\(N)(} ,(m u({ ,(z(1to N)(to1 N))))))
(\ ) ; Lambda function
(N) ; that takes an integer N:
(z ) ; Zip together these two lists:
(1to N) ; Numbers from 1 to N
(to1 N) ; Numbers from N to 1
({ , ) ; Right fold on list/string concatenation
(m u ) ; Map unparse (convert to string) to each number
(} , ) ; Left fold on list/string concatenation
The reason for the different folds is that right fold is more efficient, but by default it starts with an empty list, which when concatenating strings would make the result a list of charcodes instead of a string. Left-folding strings, by contrast, results in a string.
Thunno 2 J, 3 bytes
RḲI
Explanation
RḲI # Implicit input -> 4
R # Range: push [1..n] -> [1,2,3,4]
Ḳ # Bifurcate this list -> [1,2,3,4] [4,3,2,1]
I # Interleave -> [1,4,2,3,3,2,4,1]
# Join and output -> "14233241"
Fig, \$6\log_{256}(96)\approx\$ 4.939 bytes
OYax$a
OYax$a
Y # Interleave
ax # [1, n]
$a # With [1, n] reversed
O # Join
Pip, 10 bytes
-2 bytes thanks to DLosc!
Y\,ayWVRVy
Pip, 12 bytes
(Y++,a)WVRVy
How?
(Y++,a)WVRVy : One arg(integer n)
a : First arg
, : Inclusive range from 1
++ : Increment
Y : Yank
RV : Alias for unary reverse
y : Yanked range
WV : Weave two iterables together, alternating their items
Julia 1.0, 33 22 bytes
~x=join([1:x x:-1:1]')
- The forward and reverse sequences are collected from ranges.
- This method of interleaving arrays in Julia can be adapted for code golf.
Theprintcommand is vectorized with the "dot" operator so that no delimiters are shown.
- -9 bytes thanks to MarcMush: avoid reshaping the array
- -2 bytes thanks to MarcMush: replace
print.withjoin
Thunno J, \$ 10 \log_{256}(96) \approx \$ 8.23 bytes
R1+DrsZZ.J
Explanation
R1+DrsZZ.J # Implicit input STACK (example for n=10)
R1+ # range(0, n) + 1 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Dr # Duplicate and reverse [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
sZZ # Swap and zip together [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]
.J # Join each inner list ['110', '29', '38', '47', '56', '65', '74', '83', '92', '101']
# J flag joins the final list '1102938475665748392101'
# Implicit output
Screenshot
Go, 90 bytes
import."fmt"
func f(n int)(o string){for i:=1;i<=n;i++{o+=Sprintf("%d%d",i,n-i+1)};return}
Ly, 12 bytes
Rsrp[ul,s`u]
This one generates the 1..N series on the stack, and it generates the N..1 numbers by manipulating an accumulator on the backup cell.
R - Generate range of 0..N (where N is from STDIN)
s - Save the upper limit to the backup cell
rp - Reverse the stack, delete the "0"
[ ] - While the stack isn't empty
u - Print next number in the range
l,s - Load backup cell, decrement and save
`u - Increment and print
Arturo, 36 bytes
$[n][""loop 1..n'x->~"|n-x-1||x|"++]
$[n][ ; a function taking an argument n
"" ; place an empty string on the stack
loop 1..n'x-> ; foreach x in 1 to n...
~"|n-x-1||x|" ; interpolate x and n-x-1 into a string
++ ; append it to the string on the stack
] ; end function
Pyt, 5 bytes
řĐ↔Žǰ
ř implicit input (n); push [1,2,...,n]
Đ duplicate top of stack
↔ flip the array at the top of the stack
Ž interleave the two arrays
ǰ join the contents of the array to create a string; implicit print
Vyxal, 5 4 bytes
ɾḂYṅ
Explained
ɾḂYṅ
ɾ # range of [1,input+1]
Ḃ # dupe and reverse
Y # interleave
ṅ # join with no spaces
Braingolf v0.7, 18 bytes
VR.MUvU&,R{vMR}>&_
Explanation:
VR.MUvU&,R{vMR}>&_ Implicit input of n to stack
VR Create new stack then return to main
.M Duplicate n and move duplicate to new stack
U Replace stack with 1-n, where n is last item on stack
vU Replace 2nd stack with 1-n
&, Reverse second stack
R Return to main
{ } Map loop, runs for each item in the stack
vMR Move to next stack, move last item to main stack
> Cleanup after loop
&_ Print all items in stack with no delimiter
MATL, 13 11 9 bytes
2 bytes saved thanks to @Luis
:tPv1eVXz
Try it at MATL Online
Explanation
% Implicitly grab input as a number, N
: % Create an array from 1..N
tP % Create a reversed copy
v % Vertically concatenate the two
1e % Reshape it into a row vector
V % Convert to a string
Xz % Remove whitespace and implicitly display
Zsh, 32 bytes
repeat $1 printf $[++i]$[$1+1-i]
I like trying to beat Bash+coreutils with pure zsh, but sadly that is not the case here.
Cooler, but one byte longer (33 bytes):
a=({$1..1})
<<<${(j::)${(n)a}:^a}
Java 8, 53 52 bytes
n->{for(int i=1;n>0;System.out.print(n--+""+i++));};
Try it online!
-1 bytes thanks to Sara J!
Mouse-2002, 32 30 bytes
-2 moved conditional to start of loop (z.^ ... ) instead of (... z.0>^)
?n:n.z:(z.^a.1+a:a.!z.!z.1-z:)
Explanation:
?n: ~ get input and store in n
n.z: ~ copy n into z
(z.^ ~ stop if z equals 0
a.1+a: ~ add 1 to a
a.! ~ print a
z.! ~ print z
z.1-z:) ~ substract 1 from z
APL(NARS), 13 chars, 26 bytes
{∊k,¨⌽k←⍕¨⍳⍵}
How to use & test:
f←{∊k,¨⌽k←⍕¨⍳⍵}
f 1
11
f 26
12622532442352262172081991810171116121513141413151216111710189198207216225234243252261
APL (Dyalog Unicode), 10 bytesSBCS
(∊⍪,⌽)⍕¨∘⍳
Explanation:
(∊⍪,⌽)⍕¨∘⍳ ⍝ Monadic function train
⍕¨∘⍳ ⍝ Generate integers from 1 to input, convert each to string
⍝ Call this vector "X"
⍪ ⍝ "Table" X, making a single-column matrix
,⌽ ⍝ Reverse X and concatenate it with the above table
⍝ This results in a two-column matrix with integers from
⍝ 1 to N and N to 1 side-by-side
∊ ⍝ "Enlist" the above - left-to-right, top-to-bottom,
⍝ recursively concatenate all items in the matrix
Kotlin, 44 bytes
{n->(1..n).joinToString(""){"$it${n-it+1}"}}
{n-> // n is Int input
(1..n) // range from 1 to end
.joinToString("") // join items with no separator
{ // transform by
"$it${n-it+1}" // current number and number from end of range
}}
Lambda that takes an Int and returns a String.
Kotlin, 52 50 bytes
fun g(e:Int)=(1..e).forEach{print("$it${e-it+1}")}
Older version, the one above also prints it, the one below produces a string.
fun y(n:Int)=(1..n).joinToString(""){"$it${n-it+1}"}
05AB1E, 6 5 bytes
Saved a byte using the new interleave built-in as suggested by rev
LÂ.ιJ
Explanation
L # range [1 ... input]
 # create a reversed copy
.ι # interleave the lists
J # join
Forth (gforth), 41 bytes
: f 1+ dup 1 do i 1 .r 1- dup 1 .r loop ;
Explanation
Loops from 1 to n and outputs the index as well as n-index in a right-aligned space of size 1 (forces no space after output)
Code Explanation
: f \ start new word definition
1+ dup 1 \ set up arguments to loop from 1 to n
do \ start loop
i 1 .r \ output the index in a right-aligned space of size 1
1- dup \ subtract 1 from current value of n and duplicate
1 .r \ output new n in right-aligned space of size 1
loop \ end loop
; \ end word definition
MathGolf, 5 bytes
{îkï-
Explanation:
{ Run a for loop over implicit input
î Push 1 based index of loop
k Push inputted number
ï- Subtract 0 based index of loop
Implicitly output all this joined together
Japt -P, 11 8 bytes
Saved 2 byte thanks to @Shaggy
õ í1õU)c
Explanation:
õ í1õU)c
õ Range [1...Input]
í Pair with:
1õU Range [Input...1]
)c Flatten
-P Join into a string
Japt -mP, 8 6 bytes
°Us+N´
:For each U in the range [0,input)
°U : Prefix increment U
s : Convert to a string
+ : Append
N´ : Postfix decrement the (singleton) array of inputs
:Implicitly join and output
C# (.NET Core), 53 bytes
a=>{for(int i=0;++i<=a;)Console.Write(i+""+(a-i+1));}
Uses an Action delegate to pull in the input and not require a return.
Ungolfed:
a => {
for(int i = 0; ++i <= a;) // initialize i and increment until a
Console.Write(i + "" + (a - i + 1)); // output i and "inverse" of i
// empty string required to set as string
// parentheses required because C# is dumb and can't figure out what a minus sign is supposed to do without them
}
braingasm, 9 bytes
;[>+:<:-]
Simple: Read a number from stdin to the current cell; While the current cell is not zero, go to next cell (initially 0), increase it, output its value, go back, output that value and decrease it.
LOGO, 48 bytes
to f :n
for[i 1 :n][(type :i :n+1-:i)]show "
end
Define a function f that when invoke with parameter = number n, print the result string.
Python 3, 51 bytes
lambda n:''.join("%d%d"%(x+1,n-x)for x in range(n))
Port of Mego's Python 2 answer.
Röda, 21 19 bytes
{seq 1,_<>seq _1,1}
This is an anonymous function that takes input from the stream.
Explanation
{seq 1,_<>seq _1,1} Anonymous function, takes integer n from the stream
<> Interleave
seq 1,_ the range 1 .. n with
seq _1,1 the range n .. 1
Powershell, 37 bytes
param($n)-join(1..$n|%{$_,($n-$_+1)})
><>, 16 12+3 = 19 15 bytes
l:n}:n1-:?!;
Input is expected on the stack, so +3 bytes for the -v flag.
Thanks to @TealPelican for pointing out a very clever way to save 4 bytes by using the size of the stack itself - on the first iteration it'll be 1, then 2, then 3... That way, the first number in each pair manages itself, no manual incrementing required!
Previous version:
1:n1+$:n1-:?!;$!
R, 35 bytes
n=scan();cat(rbind(1:n,n:1),sep="")
rbind(1:n,n:1) creates a 2 row matrix with 1 to n in the first row and n to 1 in the second. The cat function collapses this matrix, reading down each column.
Perl 5, 25 21 + 1 = 26 22 bytes
Takes input from stdin, without a trailing newline.
Runs with the -n flag:
print++$x.$_--while$_
4 bytes saved thanks to Dada.
Mathematica, 52 bytes
As a traditional function:
f[x_] := StringJoin[ToString /@ Riffle[Range[x], Reverse[Range[x]]]]
As an anonymous function
(x = Range[#]; StringJoin[ToString /@ Riffle[x, Reverse[x]]]) &
As a code block that accepts the input in the variable n
x = Range[n]; StringJoin[ToString /@ Riffle[x, Reverse[x]]]
The code is pretty simple -- generate the list of integers with Range[], interleave this list (using Riffle[]) with a copy of the list that has been reversed, then convert all the integers to strings and concatenate them with StringJoin[].
Could have done it in 30 bytes if we were allowed to leave the answer in the form of a list (thus, {1,4,2,3,3,2,4,1} rather than "14233241"). Also, in the hypothetical Mthmtca with short command names it would have been something like 21 bytes.
Performance is tolerable for n <= 1,000,000. I didn't test past that.
Haskell, 65 48 47 bytes
1 byte saved thanks to Laikoni:
f n=show=<<(\(l,r)->[l,r])=<<zip[1..][n,n-1..1]
6 bytes saved thanks to nimi:
f n=show=<<(\(l,r)->[l,r])=<<zip[1..n][n,n-1..1]
Previous answer and explanation:
f n=concatMap show$concatMap(\(l,r)->[l,r])(zip[1..n][n,n-1..1])
There's already a better Haskell answer here, but I'm new to both Haskell and code golfing, so I may as well post it :)
This function zips the list [1..n] with its reverse, resulting in a list of tuples.
[(1,n),(2,n-1),(3,n-2)..(n,1)]
Then it uses concatMap to map a lambda to this list of tuples that results in a list of lists...
[[1,n],[2,n-1],[3,n-2]..[n,1]]
...and concatenates it.
[1,n,2,n-1,3,n-2..n,1]
Then a final concatMap maps show to the list and concatenates it into a single string.
f 26
"12622532442352262172081991810171116121513141413151216111710189198207216225234243252261"
Whitespace, 71 bytes
Explanation
sssn ; push 0 - seed the stack with 0 (this will be our 1->n counter, a)
sns ; dup
tntt ; getnum - read n (stored on the heap)
sns ; dup
ttt ; retr - pull n onto the stack (this will be our n->1 counter, b)
nssn ; label 'loop'
snt ; swap - bring a to the top
ssstn ; push 1
tsss ; add - increment a
sns ; dup
tnst ; putnum - output a as a number
snt ; swap - bring b to the top
sns ; dup
tnst ; putnum - output b as a number
ssstn ; push 1
tsst ; sub - decrement b
sns ; dup
ntstn ; jez 'exit' if b is 0
nsnn ; jmp 'loop'
The first couple of instructions are needed to set up the stack correctly, Whitespace's input commands write to the heap so we need to copy b (the input value) back onto the stack. We start with a = 0 since it is shorter to declare 0 instead of 1 (saves a byte) and we only need to reorder the increment instruction to cope. After that we just loop and increment a, output a, output b, decrement b, until b reaches 0 (checked after the decrement).
Bash, 25 bytes
printf %s`seq $1 -1 1|nl`
Prints decreasing sequence, number lines increasing and printf joins lines
Space delimited, 20 bytes :
seq $1 -1 1|nl|xargs
Python 2, 67 bytes
A simple one, just for the collection :)
n=input()+1
i=1
s=""
while i<n:
s+=`i`+`n-i`
i+=1
print s
Python 2, 46 bytes
lambda n:''.join(`x+1`+`n-x`for x in range(n))
Thanks to ovs for 4 bytes
Explanation:
lambda n:''.join(`x+1`+`n-x`for x in range(n))
lambda n: # anonymous lambda taking one parameter n
`x+1`+`n-x` # `x` is repr(x) which is equivalent to str(x) for integers less than INT_MAX
for x in range(n) # integers x in [0, n)
Cubix, 17 bytes
....1I>sO)su.@?(O
cubified:
. .
. .
1 I > s O ) s u
. @ ? ( O . . .
. .
. .
Pushes 1, reads in the input (I), then enters the loop which swaps the top of the stack, outputs it, increments, swaps, outputs the top of the stack, decrements, and stops if the top of the stack is 0.
R, 43 39 37 bytes
This is an anonymous function.
function(n)cat(rbind(1:n,n:1),sep="")
It's 35 bytes if I use pryr::f() like in the other answer:
pryr::f(cat(rbind(1:n,n:1),sep=""))
but needs to be installed (Enter install.packages("pryr") in the R console).
QBIC, 18 bytes
[:|Z=Z+!a$+!b-a+1$
Explanation
[:| FOR a = 1 to n
Z=Z+ Add to Z$
!b$+ a cast of the loop counter as string
!b-a+1$ and a cast of (n+1) minus the loop counter to string
Z$ is printed implicitly at the end of QBIC
Jelly, 5 bytes
RṚĖVV
How it works
RṚĖVV Main link. Argument: n
R Range; yield [1, ..., n].
Ṛ Reverse; yield [n, ..., 1].
Ė Enumerate; yield [[1, n], ..., [n, 1]].
V Eval; convert each flat array to a string, interpret it as a Jelly program,
and yield the output. This concatenates the integers in each pair, yielding
a flat array of integers
V Repeat the previous step, concatenating the intgegers from before.
Retina, 20 bytes
.+
$*__
\B
$.`$.'
_
Try it online! Includes test cases. Explanation: Each pair of numbers sums to n+1, so we convert n to unary and add 1. Then, we match between each pair of _s, counting the number of _s to the left and right. This generates the pairs of numbers. Finally we delete the _s now that they've served their purpose.
V, 20 bytes
ywo1@"ñykPjñkògJ
Explain:
yw ' Copy the input number (for looping later)
o1 ' Insert a 1 under the input (on a newline)
@" ' [Copy register] number of times
ñ ñ ' Do the thing inside of this loop
ykP ' Copy the current line and line above it, and paste above both
j ' decrement the current (top) number, and increment the one below
k ' Go to the top line
ògJ ' recursively join all of the lines
Java 61 bytes
(int n)->{for(int i=0;i<n;System.out.print(i+1+""+(n-i++)));}
Perl 6, 20 bytes
{[~] 1..*Z~($_...1)}
With an input of 100000 this takes roughly 10 seconds, including compilation and printing the output.
Expanded:
{ # bare block lambda with implicit parameter 「$_」
[~] # reduce using concatenation operator 「&infix:«~»」
# (shorter than 「join '',」)
1 .. * # Range from 1 to infinity
Z~ # zip using concatenation operator
( $_ ... 1 ) # deduced sequence starting at the input
# going down to 1
}
The Z~ needs the ~ because otherwise it generates a list of lists which will stringify with spaces.
There is no need to limit the Range starting at 1, because Z stops when any of the input lists run out.
This saves two bytes (a space would be needed after $_)
Scala, 43 bytes
It's not the best but it's my first code golf.
n=>1.to(n).foldLeft("")((s,x)=>s+x+(n-x+1))
JavaScript (ES6), 30 bytes
f=(n,k=1)=>n?f(n-1,k+1)+n+k:''
How?
This is pretty straightforward but it's worth noting that the string is built from tail to head. An empty string at the beginning is appended last and allows the coercion of the final result to a string to happen.
Below is the detail of the recursion for f(4):
f(4) = // initial call
f(4, 1) = // applying the default value to k
f(3, 2) + 4 + 1 = // recursive call #1
(f(2, 3) + 3 + 2) + 4 + 1 = // recursive call #2
((f(1, 4) + 2 + 3) + 3 + 2) + 4 + 1 = // recursive call #3
(((f(0, 5) + 1 + 4) + 2 + 3) + 3 + 2) + 4 + 1 = // recursive call #4
((('' + 1 + 4) + 2 + 3) + 3 + 2) + 4 + 1 = // n = 0 --> end of recursion
'' + 1 + 4 + 2 + 3 + 3 + 2 + 4 + 1 = // final sum
'14233241' // final result
Test cases
f=(n,k=1)=>n?f(n-1,k+1)+n+k:''
console.log(f(1))
console.log(f(4))
console.log(f(26))
console.log(f(100))
Python 2.7, 39 bytes
x=''.join(`i+1`+`n-i`for i in range(n))
Jelly, 6 bytes
RżU$FV
Explanation:
Example: n = 6
R Create a range from 1 to n [1, 2, 3, 4, 5, 6]
U$ and a reversed copy of that same range [6, 5, 4, 3, 2, 1]
ż and interleave them [ [1, 6], [2, 5, ... ]
F Flatten the list [1, 6, 2, 5, 3, 4 ...]
V And Eval: Jelly code consisting of only numbers would simply print those numbers,
Clojure, 52 bytes
#(apply str(mapcat(fn[i][(inc i)(- % i)])(range %)))
Concatenates pair-wise integers (head and tail of the seq).
PHP, 36 35 29 bytes
for(;$argn;)echo++$i,$argn--;
Saved one byte thanks to Jörg Hülsermann.
Saved six bytes thanks to Christoph.
Pyth, 7 bytes
jksC_BS
Try it online: Demonstration
Explanation:
jksC_BSQ implicit Q (=input number) at the end
SQ create the range [1, ..., Q]
_B bifurcate by inversion, this gives [[1, ..., Q], [Q, ..., 1]]
sC zip and flatten result
jk join to a string
CJam, 13 12 bytes
1 byte removed thanks to Martin Ender
ri:X{_)X@-}%
Explanation
ri e# Read integer n
:X e# Copy n into variable X
{ }% e# Map over the array [0 1 2 ... n-1]
_ e# Duplicate
) e# Add 1
X e# Push n
@ e# Rotate
- e# Subtract
Brachylog, 10 9 bytes
⟦₁g↔ᶻczcc
Explanation
⟦₁ [1, …, Input]
g↔ᶻc [[1, …, Input],[Input, …, 1]]
z Zip
cc Concatenate twice
R, 41 bytes
pryr::f(for(i in 1:x){cat(i);cat(x-i+1)})
pryr::f() creates a function that takes one input. Loops over 1:x and prints each element of 1:x along with each element of x:1. Prints to STDOUT.
Ruby, 29 bytes
->n{n.times{|x|$><<x+1<<n-x}}
Explanation:
->n{n.times{|x| # x in range [0..n-1]
$><< # output on console
x+1<<n-x}} # x+1, then n-x
Aceto, 25 22 bytes
)&
pX`=
(pl0
id@z
r}Z)
Explanation:
We read an integer and put it on two stacks.
id
r}
On one, we call range_up (Z), on the other range_down (z), then we set a catch mark to be able to return to this place later:
@z
Z)
We then check if the current stack is empty and exit if so:
X`=
l0
Otherwise, we print from both stacks and jump back to the catch mark:
)&
p
(p
Mathematica, 36 32 bytes
Row@Riffle[x=Range@#,Reverse@x]&
thanks Martin
CJam, 10 bytes
ri,:)_W%]z
Explanation
ri e# Read input and convert to integer N.
, e# Turn into range [0 1 ... N-1].
:) e# Increment to get [1 2 ... N].
_W% e# Duplicate and reverse the copy.
] e# Wrap both in an array to get [[1 2 ... N] [N ... 2 1]]
z e# Transpose to get [[1 N] [2 N-1] ... [N-1 2] [N 1]]
e# This list is printed implicitly at the end of the program,
e# but without any of the array structure (so it's essentially flattened,
e# each number is converted to a string and then all the strings
e# are joined together and printed).
Clojure, 61 bytes
#(let[a(range 1(+ 1 %))](apply str(interleave a(reverse a))))
Literally does what is asked. I believe it can be outgolfed by a less trivial solution.
Actually, 9 bytes
R;R@Z♂iεj
Try it online!, or run all test cases
Explanation:
R;R@Z♂iεj
R range(1, n+1)
;R duplicate and reverse
@Z swap and zip
♂i make 1D
εj join with empty string
