| Bytes | Lang | Time | Link |
|---|---|---|---|
| 017 | Juby | 250510T023532Z | Jordan |
| 031 | Arturo | 230811T152333Z | chunes |
| 004 | Thunno 2 s | 230811T133200Z | The Thon |
| 079 | Python 3 | 210512T180041Z | drmosley |
| 059 | Factor | 210512T054633Z | chunes |
| 005 | Vyxal s | 210511T063524Z | hyperneu |
| 010 | Pushy | 170203T175216Z | FlipTack |
| 024 | QBIC | 170203T163928Z | steenber |
| 005 | 05AB1E | 170203T111252Z | Okx |
| 017 | Dyalog APL | 160222T233032Z | Adá |
| 048 | Haskell | 160521T034523Z | Ryan McC |
| 013 | MATL | 160222T224839Z | Luis Men |
| 036 | Perl | 160309T173233Z | Ton Hosp |
| 025 | Perl 6 | 160309T200858Z | Hotkeys |
| 009 | Jelly | 160224T200739Z | lynn |
| 037 | Perl 5 | 160223T080057Z | msh210 |
| 112 | Groovy | 160223T190116Z | Xgongive |
| 064 | JavaScript ES6 | 160222T214033Z | Mwr247 |
| 039 | Groovy | 160223T133329Z | manatwor |
| 014 | CJam | 160222T213226Z | GamrCorp |
| 126 | C# | 160223T122715Z | LegionMa |
| 040 | Ruby | 160223T105803Z | manatwor |
| 024 | Brachylog | 160223T101457Z | Fatalize |
| 099 | JavaScript ES6 | 160222T222716Z | edc65 |
| 066 | JavaScript ES6 | 160222T225724Z | Neil |
| 053 | Lua | 160223T073742Z | Katenkyo |
| 057 | Lua | 160223T073958Z | Moop |
| 1215 | 𝔼𝕊𝕄𝕚𝕟 | 160223T033015Z | Mama Fun |
| 064 | R | 160222T214212Z | mnel |
| 009 | Jolf | 160223T015344Z | Conor O& |
| 071 | Retina | 160222T223101Z | Digital |
| 008 | Pyth | 160222T225442Z | Maltysen |
| 025 | Perl 6 | 160222T225416Z | Brad Gil |
| nan | Retina | 160222T224115Z | daavko |
| 064 | Mathematica | 160222T223016Z | Calculat |
| 035 | PowerShell | 160222T213431Z | AdmBorkB |
| 007 | 05AB1E | 160222T212332Z | a spaghe |
| 074 | Python 3 | 160222T212426Z | Morgan T |
| 039 | Bash + coreutils | 160222T214347Z | Digital |
| 010 | Pyth | 160222T211602Z | Doorknob |
| 012 | Seriously | 160222T211250Z | user4594 |
J-uby, 17 bytes
:+|:join|Z**:+%:~
Attempt This Online! (Uses the ** operator from an older version of J-uby.)
Arturo, 31 bytes
$->n[+do join@n..1do join@1..n]
$->n[ ; a function taking an argument n
1..n ; the range [1..n]
@ ; reify to block of integers
join ; convert [1 2 3] to "123", for instance
do ; eval -- convert numeric string to integer
n..1 ; the range [n..1]
@ ; reify to block of integers
join ; convert [1 2 3] to "123", for instance
do ; eval -- convert numeric string to integer
+ ; add
] ; end function
Thunno 2 s, 4 bytes
RJNḲ
Explanation
RJNḲ # Implicit input
R # Push [1..input]
J # Join into a string
N # Convert to integer
Ḳ # Duplicate and reverse
# Sum the stack
# Implicit output
Python 3, 79 bytes
a=''.join([str(i+1) for i in range(int(input()))])
print(int(a)+(int(a[::-1])))
Factor, 59 bytes
[ [1,b] dup reverse [ [ present ] map concat dec> ] bi@ + ]
[1,b]Create a range from 1 to the input, inclusive.dup reverseMake a copy and reverse it.[ [ present ] map concat dec> ] bi@Convert them both to numbers of concatenated numbers.+Add.
Vyxal s, 5 bytes
ɾḂWvṅ
ɾ range: [1 .. x]
Ḃ pop x, push x, reversed(x) [bifurcate]
W wrap the stack
v for each
ṅ join on ""
s (flag) sum
-2 bytes thanks to Razetime
Pushy, 10 bytes
RV@KjOjv+#
RV \ Push the range to both stacks.
@Kj \ Reverse and join the first stack
Oj \ Join the second stack
v+ \ Sum the two resulting integers
# \ Print result
QBIC, 24 bytes, nc
:[a|B=B+!b$]_FB|?!A!+!B!
Explanation
: Read command line argument as 'a'
Generate the sequence 1 ... a
[a| For b = 1 to a step 1
B=B+!b$ Add b cast to string to the end of B$ (starts out empty)
] Ends the FOR loop
_FB| Reverse (Flip) B$ and assign the result to A$
? Show on screen
!A!+!B! A$ cast to num + B$ cast to num
Non-competing, the _F was implemented way after this challenge was posted.
05AB1E, 5 bytes
LJDR+
Explanation:
L # Pushes an array containing 1 .. [implicit] input
J # Join the array to a string (eg. [1, 2, 3] -> 123)
D # Duplicate the array
R # Reverse the duplicate
+ # Add them together
Dyalog APL, 17 bytes
+/⍎¨∊¨⍕¨¨x(⌽x←⍳⎕)
⎕ prompt for input
⍳' enumerate until input
x← store list in x
⌽ reverse x
x(…) prepend reversed list with original list
⍕¨¨ convert each number of each list into character string
∊¨ make each list of character strings into single character strings
⍎¨ convert each character string into a number
+/ sum the two numbers.
Haskell, 57 56 48 bytes
This could probably be golfed a bit more, but here it goes:
f x=read y+(read.reverse$y)where y=[1..x]>>=show
Edit: shaved off a space before the where.
MATL, 13 bytes
:tP2:"wVXvU]+
EDIT (May 20, 2016) The code in the link uses Xz instead of Xv, owing to recent changes in the language.
: % range [1,2,...,n], where n is input
tP % duplicate and flip
2:" ] % do this twice
w % swap
V % convert array of numbers to string with numbers and spaces
Xv % remove spaces
U % convert to number
+ % add the two numbers
Perl, 36 bytes
Includes +1 for -p
Run with on STDIN
perl -p reverse.pl <<< 6
reverse.pl
$_=eval join"",map{abs||"+"}-$_..$_
Perl 6, 25 bytes
Either one works
{([~] 1..$^n)+[R~] 1..$n}
{([~] 1..$^n)+[~] $n...1}
Perl 5, 37 bytes
25 bytes, plus 1 for -p and 11 for -MList::Gen
$_=<[.]1..$_>+<[R.]1..$_>
Previous solution, 40 bytes: 39, plus one for -p
@a=reverse@_=1..$_;$"=$\;$_="@a"+"@_"
Groovy, 112 characters
def r(n){if(n==1){return n;};return n+''+r(n-1)};n=6;s=r(args[0].toLong());print s.toLong()+s.reverse().toLong()
run with:
groovy filename.groovy *input*
JavaScript (ES6), 70 67 64 bytes
a=>(z=[...Array(a)].map((b,c)=>c+1)).join``- -z.reverse().join``
Fixed to meet requirement, as old code was made under misunderstanding of the input.
Groovy, 42 39 characters
{[1..it,it..1]*.join()*.toLong().sum()}
Sample run:
groovy:000> ({[1..it,it..1]*.join()*.toLong().sum()})(11)
===> 2345555545332
groovy:000> ({[1..it,it..1]*.join()*.toLong().sum()})(6)
===> 777777
C#, 126 bytes
using System.Linq;a=>{var b=Enumerable.Range(1,a);return long.Parse(string.Concat(b))+long.Parse(string.Concat(b.Reverse()));}
Could possibly be golfed further. Not really sure.
Ruby, 40 characters
->n{eval (l=[*1..n])*''+?++l.reverse*''}
Sample run:
irb(main):001:0> ->n{eval (l=[*1..n])*''+?++l.reverse*''}[11]
=> 2345555545332
irb(main):002:0> ->n{eval (l=[*1..n])*''+?++l.reverse*''}[6]
=> 777777
Brachylog, 24 bytes
:1fLrcC,Lc+C=.,{,.:1re?}
JavaScript (ES6), 99
This adds digit by digit, so it can handle numbers well above the 53 bits of precision of javascript
n=>eval("for(a=b=c=r='';n;a+=n--)b=n+b;for(i=a.length;i--;r=c%10+r)c=(c>9)-(-a[i]-b[i]);c>9?1+r:r")
Test
f=n=>eval("for(a=b=c=r='';n;a+=n--)b=n+b;for(i=a.length;i--;r=c%10+r)c=(c>9)-(-a[i]-b[i]);c>9?1+r:r")
// Less golfed
U=n=>{
for(a=b=c=r=''; n; --n)
b=n+b, a+=n;
for(i=a.length; i--; r = c%10+r)
c=(c>9)-(-a[i]-b[i]);
return c>9? 1+r : r;
}
function test() {
var n=+I.value
R.textContent=f(n)
}
test()
N: <input id=I value=11 oninput="test()"> -> <span id=R></span>
JavaScript (ES6), 67 66 bytes
n=>(a=[...Array(n+1).keys()].slice(1)).join``- -a.reverse().join``
Yes, that's a space. Ugh. At least @Downgoat helped me save a byte.
Lua, 53 Bytes
This program takes n as a command-line argument.
s=""r=s for i=1,arg[1]do r,s=i..r,s..i end print(s+r)
I assumed that outputing a number with a decimal part of 0 was okay (in the form 777777.0 because this is the default way to output a number in lua (there's no distinction between integer and float)
Lua, 57
a=''b=''for i=1,...do a=a..i b=b.. ...-i+1 end return a+b
𝔼𝕊𝕄𝕚𝕟, 12 chars / 15 bytes
⨭⟮⩤⁽1ï⟯⨝,Ⅰᴚ⨝
Meh.
Explanation
Takes a range [1,input], joins it; takes that same range, reverses it, then joins it; the sum of both ranges is the result.
R, 34 60 64 bytes
f=pryr::f;g=f(as.numeric(paste(x,collapse='')));f(g(1:n)+g(n:1))
Assumes pryr package is installed. this gives f as a shorthand for creating functions.
Edit added 26 bytes but returns a function that works, not something entirely wrong.
Edit added another 4 bytes to handle cases above n=10 where strtoi (previously used) was returning NA
Jolf, 9 bytes
Try it here! Replace ► with \x10.
+P►γzjP_γ
zj range 1...j
γ γ = ^
► ^ .join("")
P as a number
+ P_γ and γ reversed
I may be able to golf it by moving around the type casting.
Retina, 71
- 7 bytes saved thanks to @daavko.
- 3 bytes saved thanks to version 0.7.3 features
Because its blatantly the wrong tool for the job.
.+
$*a:$&$*
+`^(a+)a\b(.*)\b1(1+)$
$1 $& $3
?(\w)+ ?
$#1
\d+:?
$&$*c
c
Works for inputs up to 6, but the online interpreter times out after that.
Perl 6, 25 bytes
{([~] @_=1..$^n)+[R~] @_}
{
(
[~] # reduce with the string concatenation infix op:
@_ = 1 .. $^n # the range 1 to input ( also stored in @_ )
)
+ # add that to
[R~] @_ # @_ reduced in reverse
}
Usage:
for 6, 11, 12 -> $n {
say {([~] @_=1..$^n)+[R~] @_}( $n )
}
777777
2345555545332
244567776755433
Retina, 80 bytes (ISO 8859-1 encoding)
'+
$0¶$0
+`^(('+)')
$2 $1
+`('('+))$
$1 $2
(')+( |$)?
$#1
(\d+)¶(\d+)
$1$*'$2$*'
IO is in unary with ' as the counting character. In theory supports any integer you throw at it, in practice...online interpreter refuses to process anything larger than 6 (unary '''''').
Mathematica, 64 bytes
Plus@@FromDigits/@#&[""<>ToString/@#&/@{#,Reverse@#}&[Range@#]]&
PowerShell, 35 bytes
param($a)+-join(1..$a)+-join($a..1)
Converts the input to ranges with .., then -joins them together, and adds 'em up.
Will work for input numbers up to 138, while 139 will give Infinity, and 140 and above will barf out an awesomely verbose casting error:
Cannot convert value "12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413
5136137138139140" to type "System.Int32". Error: "Value was either too large or too small for an Int32."
05AB1E, 7 bytes
LDRJsJ+
Explanation
LDRJsJ+
L range from 1 .. input
D duplicate
R reverse
JsJ convert both arrays to strings
+ add (coerces both strings to ints)
Python 3, 74
Saved 6 bytes thanks to DSM.
Nothing too exciting, join the ranges and then convert to ints and add them.
lambda x:sum(int(''.join(list(map(str,range(1,x+1)))[::i]))for i in(1,-1))
Bash + coreutils, 39
eval echo {1..$1} + {$1..1}|tr -d \ |bc
Or:
bc<<<`eval printf %s {1..$1} + {$1..1}`
Pyth, 12 10 bytes
ssMjLk_BSQ
Thanks to @FryAmTheEggman for 2 bytes!
Q is the input, S turns it into [1, 2, ..., input()], _B bifurcates it over _ (reverse) to create [rng, rev(rng)], jLk maps it over join by k (which is the "empty string" variable), sM maps int over this resulting array, and s finally calculates the sum.
Seriously, 12 bytes
,R;Rεj≈@εj≈+
Explanation:
,R;Rεj≈@εj≈+
,R; push two copies of range(1, input()+1)
R reverse one copy
εj≈@εj≈ concatenate both and cast both to ints
+ add
