34
3
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 code-golf so the shortest submission in bytes in each language wins. Explanations are encouraged.
1Two bytes more in Python 3:
f'{x}{n-~-x}'
– L3viathan – 2017-05-30T11:02:07.2032@L3viathan That's a new feature added in 3.6. – Mego – 2017-05-30T11:03:27.083
1Python 3.6 is not Python 3? – L3viathan – 2017-05-30T11:04:20.520
1@L3viathan It is, but it's a specific version. Python 3.5 and below don't have that string interpolation feature. – Mego – 2017-05-30T11:04:59.910
It is the most recent version. Generator comprehensions, which you use, were added in Python 2.4, Python 2.3 and below don't have that feature, but you still categorize your answer as "Python 2". – L3viathan – 2017-05-30T11:06:51.590
1@L3viathan That's because Python 2.7 is in wide use. The same cannot be said for 3.6 yet. For example, the Ubuntu Main repo only has 3.5. 2.4 was released in 2004; 3.6 was released 5 months ago. There's a stark difference. – Mego – 2017-05-30T11:10:32.663
6
lambda n:''.join('x+1'+'n-x'for x in range(n))
for 46 bytes .(replace the'
in the list comprehension with backticks) – ovs – 2017-05-30T11:53:59.8576@ovs hey, you can escape the backtick ->
\
\`x+1\``` renders to\
x+1`` – Rod – 2017-05-30T12:29:19.373