34
\$\begingroup\$

A simple one:

Take a positive integer n less than 1000, and output the integers from 1 to n interleaved with the integers from n to 1. You must concatenate the numbers so that they appear without any delimiters between them.

Test cases:

n = 1
11

n = 4
14233241

n = 26
12622532442352262172081991810171116121513141413151216111710189198207216225234243252261

n = 100
110029939849759669579489399210911190128913881487158616851784188319822081218022792378247725762675277428732972307131703269336834673566366537643863396240614160425943584457455646554754485349525051515052495348544755465645574458435942604161406239633864376536663567346833693270317130722973287427752676257724782379228021812082198318841785168615871488138912901191109299389479569659749839921001

This is so the shortest submission in bytes in each language wins. Explanations are encouraged.

\$\endgroup\$

65 Answers 65

0
\$\begingroup\$

APL(NARS), 13 chars, 26 bytes

{∊k,¨⌽k←⍕¨⍳⍵}

How to use & test:

  f←{∊k,¨⌽k←⍕¨⍳⍵}
  f 1
11
  f 26
12622532442352262172081991810171116121513141413151216111710189198207216225234243252261
\$\endgroup\$
0
\$\begingroup\$

Ink, 47 bytes

=f(n)
~temp i=n
-(l)
~i--
{n-i}{1+i}{i:->l}->->

Try it online!

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

Stax, 5 bytes

çK^↑Ñ

Run and debug it

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

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!

\$\endgroup\$
  • \$\begingroup\$ 52 bytes \$\endgroup\$ – Sara J Apr 2 '19 at 21:57
  • \$\begingroup\$ @SaraJ thanks, I forgot about the for-loop trick \$\endgroup\$ – Benjamin Urquhart Apr 2 '19 at 23:57
0
\$\begingroup\$

Zsh, 32 bytes

repeat $1 printf $[++i]$[$1+1-i]

Try it online!

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}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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