text:
Alphabet wings!
Your task is to print this exact text:
az                                               za
abyz                                           zyba
abcxyz                                       zyxcba
abcdwxyz                                   zyxwdcba
abcdevwxyz                               zyxwvedcba
abcdefuvwxyz                           zyxwvufedcba
abcdefgtuvwxyz                       zyxwvutgfedcba
abcdefghstuvwxyz                   zyxwvutshgfedcba
abcdefghirstuvwxyz               zyxwvutsrihgfedcba
abcdefghijqrstuvwxyz           zyxwvutsrqjihgfedcba
abcdefghijkpqrstuvwxyz       zyxwvutsrqpkjihgfedcba
abcdefghijklopqrstuvwxyz   zyxwvutsrqpolkjihgfedcba
abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba
  abcdefghijklopqrstuvwxyzyxwvutsrqpolkjihgfedcba
    abcdefghijkpqrstuvwxyzyxwvutsrqpkjihgfedcba
      abcdefghijqrstuvwxyzyxwvutsrqjihgfedcba
        abcdefghirstuvwxyzyxwvutsrihgfedcba
          abcdefghstuvwxyzyxwvutshgfedcba
            abcdefgtuvwxyzyxwvutgfedcba
              abcdefuvwxyzyxwvufedcba
                abcdevwxyzyxwvedcba
                  abcdwxyzyxwdcba
                    abcxyzyxcba
                      abyzyba
                        aza

The following are allowed:

Leaving out trailing spaces at the end of lines
Doing everything in uppercase instead of lowercase
Trailing newlines

Remember, this is code-golf, so the code with the smallest number of bytes wins.

ANOTHER alphabet challenge?? Please, take a break. We have enough recent [tag:alphabet] challenges. Not that it is bad, though.

05AB1E, 36 bytes
Code:
A13F¦¨DAsKDˆ13N>-·ð×«û,}¯R¦ð2×ì€û.c,

Doesn't work on TIO yet, but it does work with the offline interpreter.

How does 05AB1E always add a feature needed for a challenge only hours before the challenge itself is posted?

@LegionMammal978 Honestly, I haven't got the slightest clue haha.

Vim, 94 91 bytes
This one was tricky.
:se ri|h<_
jjYZZpqqpi  <Esc>@=17-line('.')
 xxYq11@qy2G:g/^/m0
qqD0Pwq12@q"0pdkGqq$y0A<C-r>"<Esc>kq24@q

Here it is in action:

Here's an xxd dump with the unprintable characters:
0000000: 3a73 6520 7269 7c68 3c5f 0a6a 6a59 5a5a  :se ri|h<_.jjYZZ
0000010: 7071 7170 6920 201b 403d 3137 2d6c 696e  pqqpi  .@=17-lin
0000020: 6528 272e 2729 0a20 7878 5971 3131 4071  e('.'). xxYq11@q
0000030: 7932 473a 672f 5e2f 6d30 0a71 7144 3050  y2G:g/^/m0.qqD0P
0000040: 7771 3132 4071 2230 7064 6b47 7171 2479  wq12@q"0pdkGqq$y
0000050: 3041 1222 1b6b 7132 3440 71              0A.".kq24@q

Explanation:
Credit for the first two lines goes to DJMcMayhem and Lynn.
:se ri|       " Turn on reverse-insert mode
h<_<CR>jjYZZ  " Yank the lowercase alphabet from help
p             " Paste it
qq            " Start recording a macro
  pi  <Esc>              " Paste, then insert two spaces before the cursor
  @=17-line('.')<CR> xx  " Delete the middle two letters
  Y                      " Yank the current line
q11@q         " Stop recording, execute 11 times
y2G           " Yank everything except the first (blank) line
:g/^/m0<CR>   " Reverse the order of every line
qq            " Record
  D0P           " Delete until the end of the line (i.e. just the letters)
  w             " Skip to the first letter on the next line
q12@q         " Stop recording, execute 12 times
"0p           " Paste the lines yanked above
dk            " Delete this line and the line above
G             " Go to the last line
qq            " Record
  $y0           " Move to the end of the line, then yank all but the last letter
  A<C-r>"<Esc>  " Append (in insert mode so it's reversed)
  k             " Go up a line
q24@q         " Stop recording, execute 24 times

Batch, 395 391 bytes
@echo off
set q=
set r=
set s=
set t=
for /l %%i in (1,1,51)do call set s= %%s%%
for %%p in (az by cx dw ev fu gt hs ir jq kp lo mn)do call:u %%p
for /l %%i in (1,1,12)do call:l
exit/b
:u
set p=%1
set q=%q%%p:~,1%
set r=%p:~1%%r%
set s=%s:~4%%p:~1%
set t=%p:~,1%%t%
echo %q%%r%%s%%t%
exit/b
:l
set q=  %q:~,-1%
set r=%r:~1%
set s=%s:~,-1%
set t=%t:~1%
echo %q%%r%%s%%t%

PHP, 158 Bytes
for(;$i++<25;)echo($a=str_pad)(($t=($f=substr)($j=join(range(a,z)),0,$x=$i>13?13-$i%13:$i).$f($j,-$x)).$a("",51-$i*4," ").$f(strrev($t),$i>12),51," ",2)."\n";

Pyke, 27 bytes
13FhG'<R>+26{)DFl826^)_+msX

Try it here!
13F          )              -    for i in range(13):
   h                        -       i+1
    G'<R>+                  -      alphabet[:^]+alphabet[-^:]
          26{               -     ^.rpad(26)
              D        +    -   ^ + V
               F     )      -     for i in ^^:
                l8          -       ^.lstrip()
                  26^       -      ^.lpad(26)
                      _     -    reversed(^)
                        ms  -  map(palindromise, ^)
                          X - splat(^)

Oh snap! Not to Jynx you, but you just beat jelly!

J, 52 bytes
(,.}.@|."1)(}:,|.|.~"#:_2*i.@#)(a.{~97+],25-|.)\i.13

Usage
   (,.}.@|."1)(}:,|.|.~"#:_2*i.@#)(a.{~97+],25-|.)\i.13
az                                               za
abyz                                           zyba
abcxyz                                       zyxcba
abcdwxyz                                   zyxwdcba
abcdevwxyz                               zyxwvedcba
abcdefuvwxyz                           zyxwvufedcba
abcdefgtuvwxyz                       zyxwvutgfedcba
abcdefghstuvwxyz                   zyxwvutshgfedcba
abcdefghirstuvwxyz               zyxwvutsrihgfedcba
abcdefghijqrstuvwxyz           zyxwvutsrqjihgfedcba
abcdefghijkpqrstuvwxyz       zyxwvutsrqpkjihgfedcba
abcdefghijklopqrstuvwxyz   zyxwvutsrqpolkjihgfedcba
abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba
  abcdefghijklopqrstuvwxyzyxwvutsrqpolkjihgfedcba
    abcdefghijkpqrstuvwxyzyxwvutsrqpkjihgfedcba
      abcdefghijqrstuvwxyzyxwvutsrqjihgfedcba
        abcdefghirstuvwxyzyxwvutsrihgfedcba
          abcdefghstuvwxyzyxwvutshgfedcba
            abcdefgtuvwxyzyxwvutgfedcba
              abcdefuvwxyzyxwvufedcba
                abcdevwxyzyxwvedcba
                  abcdwxyzyxwdcba
                    abcxyzyxcba
                      abyzyba
                        aza

Jelly, 35 bytes
Ḳṙ-K
CrịØaṙµL26_⁶ẋ;
13RµŒḄÇ€Ñ€⁸¦ŒBY

TryItOnline!
How?
13RµŒḄÇ€Ñ€⁸¦ŒBY - Main link: no arguments
13R             - range(13) -> [1,2,3,...,12,13]
   µ            - monadic chain separation
    ŒḄ          - bounce    -> [1,2,3,...,12,13,12,...,3,2,1]
      Ç€        - call last link (2) as a monad for €ach
           ¦    - apply to indexes
          ⁸     -    left argument (13R)
        Ñ€      -    next link (1) as a monad for €ach
            ŒB  - bounce with vectorisation at depth 1 (creates the right hand side)
              Y - join with line feeds

CrịØaṙµL26_⁶ẋ; - Link 2: make the left side of a row, with spaces at the left: i (e.g. 3)
C              - complement (1-i)       e.g. 1-3=-2
 r             - range(1-i, i)          e.g. [-2,-1,0,1,2,3]
  ị            - index into
   Øa          - lowercase alphabet     e.g. "xyzabc"
      µ        - monadic chain separation
     ṙ         - rotate left by i       e.g. "abcxyz"
        26_    - literal 26 minus
       L       - length                 e.g. 26-6=20
           ⁶   - literal ' '
            ẋ  - repeat 26-length times e.g. "                    "
             ; - concatenate            e.g. "                    abcxyz"

Ḳṙ-K - Link 1, swap spaces to the right: left half of a row
Ḳ    - split on spaces                  e.g. [[],[],...,"abcxyz"]
 ṙ   - rotate left by
  -  - literal -1                       e.g. ["abcxyz",...,[],[]]
   K - join with spaces                 e.g. "abcxyz                    "

Bubblegum, 165 bytes
Hexdump:
00000000: 4aac 5220 0d54 25f2 7201 e896 8b03 86a2  J.R .T%.r.......
00000010: 1806 60ab bcd5 fa99 19a7 2f43 ec3a 77e9  ..`......./C.:w.
00000020: 129d a2f9 e58c 9e29 3e64 d3e5 88df 29d9  .......)>d....).
00000030: a9f9 654f be29 dda8 7965 4b4d ca56 6aba  ..eO.)..yeKM.Vj.
00000040: ac19 a47c 518d ca92 532a 6668 aacc c55f  ...|Q...S*fh..._
00000050: 2a27 6e54 a652 a46a c446 65ac 64aa 0768  *'nT.R.j.Fe.d..h
00000060: 5886 da49 4d8f cd94 be71 53db d966 4ad7  X..IM....qS..fJ.
00000070: 620a c136 2771 8124 0b07 2822 20a7 c07c  b..6'q.$..(" ..|
00000080: 424c 9c30 52c2 4011 1235 1019 c12f 4344  BL.0R.@..5.../CD
00000090: ec8d 9010 7a12 1784 701b a8d4 a884 48e3  ....z...p.....H.
000000a0: 5050 9508 00                             PP...

Just ran the string through Zopfli for many iterations.

JavaScript (ES6), 215 211 bytes
_=>[...Array(25)].map((_,i)=>` `.repeat(++i>13&&i*2-26)+a.slice(0,j=i>13?26-i:i)+a.slice(-j)+` `.repeat(i<13&&51-i*4)+b.slice(i>12,j)+b.slice(-j),a=`abcdefghijklmnopqrstuvwxyz`,b=[...a].reverse().join``).join`\n`

Where \n represents the literal newline character. This just edged out my character building answer at 213 bytes:
_=>[...Array(25)].map((_,i)=>` `.repeat(51).replace(/./g,(b,j)=>(j=i<13?j<i?j+10:j<h?36+j-h:j<51-h?0:j<51-i?86-h-j:60-j:j<h-26?0:j<i?36+j-h:j<26?j+10:j<51-i?60-j:j<77-h?86-h-j:0)?j.toString(36):b,h=++i+i)).join`\n`

Ruby, 109 bytes
Full program that prints a string as required by the question. One byte could be saved by changing to a lambda function that returns an array of strings.
s=[*(?a..?z)]*""
puts (-12..12).map{|i|(t="%#{(i<=>0)*26}s"%(s[0,13-i.abs]+s[13+i.abs..26]))+t[0,25].reverse}

Ungolfed
s=[*(?a..?z)]*""                     #Convert range 'a'..'z' into an array, then a string.
puts (-12..12).map{|i|               #Iterate over -12..12, make an array of lines then print them.
  (t=                                #t= left side of pattern.
    "%#{(i<=>0)*26}s"%               #Compose format string %-26s or %26s to pad to 26 chars and left/right justify depending on sign.
     (s[0,13-i.abs]+s[13+i.abs..26]) #In this format, print the appropriate number of beginning and ending letters of the alphabet.
   )+
     t[0,25].reverse                 #Righthand side of pattern. Remove the rightmost column from t, reverse it, and concatenate to left side.
}

Japt, 49 bytes
;1o14@CjX26-2*XÃê £Y<12?X+S²p12-Y :S²pY-12 +X êÃ·

I mainly wrote this answer to try out the (somewhat) new ê function (bounce; "abc" -> "abcba"). Test it online!
Explanation
;1o14@CjX26-2*X} ê £Y<12?X+S²p12-Y :S²pY-12 +X ê} ·

;                                                    // Set C to "abc...xyz".
 1o14                                                // Create the range [1, 14).
     @         }                                     // Map each item X by this function:
         26-2*X                                      //   Take 26 - 2X.
      CjX                                            //   Remove this many chars from index X in C.
                                                     // We now have ["az", "abyz", ..., "abc...xyz"].
                 ê                                   // Bounce. This gives us ["az", "abyz", ..., "abc...xyz", ..., "abyz", "az"].
                   £                            }    // Map each item X and index Y by this function:
                    Y<12?                            //   If Y is less than 12,
                         X+S²p12-Y                   //   append 12 - Y double-spaces.
                                   :S²pY-12 +X       //   Otherwise, prepend Y - 12 double-spaces.
                                                     //   This gives us the left half of the wings.
                                               ê     //   Bounce. This creates the right half.
                                                  ·  // Join the resulting array with newlines.
                                                     // Implicit: output last expression

C#, 473 Bytes
"Concat", "Reverse", "Substring"... So many big words...
Golfed:
string A(){string a="abcdefghijklmnopqrstuvwxyz",r=string.Concat(a.Reverse()),o="",x="",y="",z="";int i=0;var l=new List<string>();for(i=0;i<13;i++){x=a.Substring(0,i);y=r.Substring(0,i);z=x+string.Concat(y.Reverse())+string.Concat(Enumerable.Repeat(" ",51-i*4))+y+string.Concat(x.Reverse())+"\n";o+=z;l.Add(z.Replace(" ","").Replace("zz","z"));}o+=a+r.Substring(1,r.Length-1)+"\n";l.Reverse();for(i=0;i<12;i++)o+=string.Concat(Enumerable.Repeat(" ",i+i+2))+l[i];return o;}

Ungolfed:
public string A()
{
  string a = "abcdefghijklmnopqrstuvwxyz", r = string.Concat(a.Reverse()), o = "",x="",y="",z="";
  int i=0;
  var l = new List<string>();
  for (i = 0; i < 13; i++)
  {
    x = a.Substring(0, i);
    y = r.Substring(0, i);
    z = x + string.Concat(y.Reverse()) +
      string.Concat(Enumerable.Repeat(" ", 51-i*4)) +
      y + string.Concat(x.Reverse()) + "\n";
    o += z;
    l.Add(z.Replace(" ", "").Replace("zz", "z"));
  }
  o += a + r.Substring(1, r.Length - 1) + "\n";
  l.Reverse();
  for (i = 0; i < 12; i++)
    o += string.Concat(Enumerable.Repeat(" ", i + i + 2)) + l[i];
  return o;
}

Outputs:
az                                               za
abyz                                           zyba
abcxyz                                       zyxcba
abcdwxyz                                   zyxwdcba
abcdevwxyz                               zyxwvedcba
abcdefuvwxyz                           zyxwvufedcba
abcdefgtuvwxyz                       zyxwvutgfedcba
abcdefghstuvwxyz                   zyxwvutshgfedcba
abcdefghirstuvwxyz               zyxwvutsrihgfedcba
abcdefghijqrstuvwxyz           zyxwvutsrqjihgfedcba
abcdefghijkpqrstuvwxyz       zyxwvutsrqpkjihgfedcba
abcdefghijklopqrstuvwxyz   zyxwvutsrqpolkjihgfedcba
abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba
  abcdefghijklopqrstuvwxyzyxwvutsrqpolkjihgfedcba
    abcdefghijkpqrstuvwxyzyxwvutsrqpkjihgfedcba
      abcdefghijqrstuvwxyzyxwvutsrqjihgfedcba
        abcdefghirstuvwxyzyxwvutsrihgfedcba
          abcdefghstuvwxyzyxwvutshgfedcba
            abcdefgtuvwxyzyxwvutgfedcba
              abcdefuvwxyzyxwvufedcba
                abcdevwxyzyxwvedcba
                  abcdwxyzyxwdcba
                    abcxyzyxcba
                      abyzyba
                        aza


text:
Approximate arcsinc
The goal is simple: Output a nonzero real solution x to the equation sin(x) = -mx, given input m, in the fewest number of bytes.
Specifications:

Your answer must be correct to 3 significant figures.
You may output any real solution other than the trivial solution x=0. You can assume m is such that at least one solution exists. You may also assume m!=0.

An obviously suboptimal python solution using gradient descent:
from math import *
from random import *
a=x=0.001
m = 5.
def dE(x):return 2*(sin(x)+m*x+1)*(cos(x)+m)
for i in xrange(1000): x-=dE(x)*a
print x

Test cases
-0.25 -> ±2.4746
-0.1  -> ±2.8523 or ±7.0682 or ±8.4232
 0.2  -> ±4.1046 or ±4.9063

The best approach here is to print a fixed value, though you should specify how many decimal places are required. I'd suggest including an input parameter, like a to solve sin(x)=-ax. Please don't say "you have to actually compute it", since requirements like that are too vague to work.

Also, x=0 is a trivial solution. You should specify which solution you want.

You need some bounds on m to guarantee a nonzero solution.

m=0 has solutions (x=kπ for integer k). The values of m which don't have non-trivial real solutions are those which are too far from 0.

Are you looking for only real-valued solutions or are complex-valued solutions allowed too?

I edited the spec with the intent of reopening. If this isn't what you had in mind, please let me know.

@xnor, are you sure about those test cases? The minimum of sinc is about -0.217, so I don't think 0.25 is a valid input.

@PeterTaylor You're right, I had the sign flipped.

@xnor, IMO it would make more sense to flip the sign and make the question "Approximate arcsinc(m)" rather than "Approximate arcsinc(-m)", although that would have been much easier to do in the sandbox than on a posted question with an answer.

@PeterTaylor I agree it would be cleaner, but that's more functional a change than I'd like to do in editing someone else's question.

This problem came up yesterday and I solved it naively with python. I was wondering what cool solutions people would come up with. I'm new to the site and don't know how best to pose specific problems – you guys are free to improve the question as you see fit.

ised: 32 28 bytes
Using Newton's iteration starting from π:
{:x-{sinx+$1*x}/{cosx+$1}:}:::pi

The argument is passed in $1, which can be taken from a file, like this:
ised --l inputfile.txt 'code'

A bit less stable, but shorter version:
{:{x-tanx}/{1+$1/cosx}:}:::pi

Sometimes it throws iteration limit warnings but the accuracy seems fine considering the conditions.
Unicode version (same bytecount):
{λ{x-tanx}/{1+$1/cosx}}∙π

Starting from 4 cuts another byte and seems to converge to the same values
{λ{x-tanx}/{1+$1/cosx}}∙4

Haskell, 34 bytes
f m=until(\x->sin x< -m*x)(+1e-3)0

Counts x up from 0 by 0.001 until sin(x)< -m*x.
Ouput examples
f -0.2 ->   2.595999999999825
f -0.1 ->   2.852999999999797
f  0.0 ->   3.141999999999765
f  0.1 ->   3.4999999999997256
f  0.2 ->   4.1049999999997056

What about m=-0.1?

@PeterTaylor Note sure if it's required, but it gives 2.853, which looks right.

Of course, they're both odd functions so if there's a solution there's a positive solution. Doh.

Why would you answer a challenge that you know is unclear?

Mathematica, 28 bytes
x/.FindRoot[Sinc@x+#,{x,1}]&

Searches for a numerical root from the initial guess x=1. Test cases:
% /@ {-0.25, -0.1, 0.2}
(* {2.47458, 2.85234, 4.10462} *)

C, 99 bytes
#include<math.h>
float f(float m){float x=1,y;do{x=(y=sin(x)+m*x)+x;}while(fabs(y)>1e-4);return x;}

ungolfed:
#include<math.h>
float f(float m){
 float x=1,y;
 do{x=(y=sin(x)+m*x)+x;}while(fabs(y)>1e-4);
 return x;
}

C++ 11, 92 91 bytes
-1 byte for using #import
#import<cmath>
using F=float;F f(F m,F x=1){F y=sin(x)+m*x;return fabs(y)>1e-4?f(m,x+y):x;}

MATL, 17 bytes
`@2e3/tY,wG_*>}4M

This uses linear search on the positive real axis, so it is slow. All test cases end within 1 minute in the online compiler.
Try it online!
Explanation
`         % Do...while
  @       %   Push iteration index, starting at 1
  2e3/    %   Divide by 2000
  t       %   Duplicate
  Y,      %   Sine
  w       %   Swap
  G_*     %   Multiply by minus the input
  >       %   Does the sine exceed that? If so, next iteration
}         % Finally (execute after last iteration, before exiting loop)
   4M     %   Push input of sine function again
          % Implicit end
          % Implicit display

Python 2, 81 78 bytes
Fixpoint iteration
As recursive lambda
from math import*
f=lambda m,x=1:abs(sin(x)+m*x)>1e-4and f(m,sin(x)+m*x+x)or x

As loop (81 bytes):
from math import*
m=input()
x=1
while abs(sin(x)+m*x)>1e-4:x=sin(x)+m*x+x
print x

Mathematica, 52 bytes
NSolve[Sin@x==-x#,x,Reals][[;;,1,2]]~DeleteCases~0.&

Anonymous function. Takes a number as input, and returns a list of numbers as output. Just uses NSolve to solve the approximate equation.

If you replace Sin@x==-x# with Sinc@x==-# you can do away with ~DeleteCases~0.

Axiom, 364 bytes
bisezione(f,a,b)==(fa:=f(a);fb:=f(b);a>b or fa*fb>0=>"fail";e:=1/(10**(digits()-3));x1:=a;v:=x2:=b;i:=1;y:=f(v);if(abs(y)>e)then repeat(t:=(x2-x1)/2.0;v:=x1+t;y:=f(v);i:=i+1;if i>999 or t<=e or abs(y)<e then break;if fb*y<0 then(x1:=v;fa:=y)else if fa*y<0 then(x2:=v;fb:=y)else break);i>999 or abs(y)>e=>"fail";v)
macro g(m) == bisezione(x+->(sin(x)+m*x), 0.1, 4.3)

ungolf
bisezione(f,a,b)==
    fa:=f(a);fb:=f(b)
    a>b or fa*fb>0=>"fail"
    e:=1/(10**(digits()-3))
    x1:=a;v:=x2:=b;i:=1;y:=f(v)
    if(abs(y)>e) then
      repeat
        t:=(x2-x1)/2.0;v:=x1+t;y:=f(v);i:=i+1
        if i>999 or t<=e or abs(y)<e then break
        if      fb*y<0 then(x1:=v;fa:=y)
        else if fa*y<0 then(x2:=v;fb:=y)
        else break
    i>999 or abs(y)>e=>"fail"
    v

macro g(m) == bisezione(x+->(sin(x)+m*x), 0.1, 4.3)

results
(3) -> g(0.2)
   AXIOM will attempt to step through and interpret the code.
   (3)  4.1046198505 579058527
                                                              Type: Float
(4) -> g(-0.1)
   (4)  2.8523418944 500916556
                                                              Type: Float
(5) -> g(-0.25)
   (5)  2.4745767873 698290098
                                                              Type: Float

Haskell, 50 bytes
I just learned about newton's method in my calc class, so here goes in haskell using newton's method.
f m=foldl(\x _->x-(sin x+m*x)/(cos x+m))0[1..10]

Scala, 68 bytes
Modified from @xnor's Haskell answer.

Golfed version. Try it online!
m=>Stream.iterate(0.0)(_+1e-3).dropWhile(x=>math.sin(x)>= -x*m).head

Ungolfed version. Try it online!
object Main {
  def main(args: Array[String]): Unit = {
    println(f(-0.2))
    println(f(-0.1))
    println(f(0.0))
    println(f(0.1))
    println(f(0.2))
  }

  def f(m: Double): Double = {
    def until(condition: Double => Boolean, action: Double => Double, x: Double): Double = {
      if (condition(x)) x
      else until(condition, action, action(x))
    }

    until(x => Math.sin(x) < -m * x, _ + 1e-3, 0)
  }
}

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
monthconcatenation
The goal is to output the number of the months given as input in a compact concatenated form which is still parsable if one knows the construction rules:
If either:

January is followed by January, February, November or December; or
November is followed by January or February

There must be a separator placed between.
Otherwise there should be no separator.
As such the output may be parsed. For example:

March, April and September -> 349
January, January and February -> 1-1-2
January, January and December -> 1-1-12
January, November and February -> 1-11-2
November, January and February -> 11-1-2
November and December -> 1112

Thus any run of ones is either a run of Novembers, a run of Novembers followed by a December, a run of Novembers followed by an October, or a January followed by an October. This may be parsed by looking to the right of such runs as the resulting string is read from left to right.
Input
A list of months numbers ([1-12]) in any format you want (list, JSON, separated by one or more characters, entered one by one by user, …).
the same month can be present more than once.
Output
The compact concatenated form described above. If a separator is needed, you can freely choose one.
Output examples for January, February and March (1-2-3):

1-23 (chosen for the test cases below)
1 23
1/23
1,23
...

Test cases
[1]       => 1
[1, 2]    => 1-2
[2, 1]    => 21
[12]      => 12
[1, 11]   => 1-11
[11, 1]   => 11-1
[1, 1, 1] => 1-1-1
[2, 11]   => 211
[11, 2]   => 11-2
[1, 2, 3] => 1-23
[11, 11]  => 1111
[1,1,11,1,12,1,11,11,12]     => 1-1-11-1-121-111112
[10,11,12,11,11,10,1,10,1,1] => 1011121111101101-1
[2,12,12,2,1,12,12,1,1,2,12,12,2,11,2,12,1] => 2121221-12121-1-21212211-2121

Rules

As usual, this is code-golf, shortest answer in bytes wins.
Standard loopholes are forbidden.

1111 is extra-ambiguous. Do you mean 1-1-1-1, 1-1-11, 1-11-1, 11-1-1 or 11-11?

I see what you mean, I added a test case. If there are so many 1's, it's hard to know at first, so 1111 should be 11-11 if you mean Nov-Nov. That has been shown in the test case 11-2 (not 112) and added as an extra test case.

This would be so much easier in base 12...

Python 2.7 96 bytes
Try it out here!
Huge thanks to Jonathan Allan for shortening the answer.
golfed:
b,o=input(),""
for a,n in zip(b,b[1:]):o+=`a`+"-"*(a%10==1and a+n in(2,3,12,13))
print o+`b[-1]`

Explanation:
runs through the input, checks if the current item is a special case and if so handles it, otherwise just concatenates the input, prints the output string.
ungolfed:
input = [2,12,12,2,1,12,12,1,1,2,12,12,2,11,2,12,1]
output = ""
for i in range(len(input) - 1):
    next = input[i + 1]
    item = input[i]
    if item == 1 and (next == 1 or next == 2 or next == 11 or next == 12) or item == 11 and (next == 1 or next == 2):
        output += str(item) + "-"
    else:
        output += str(item)

output += str(input[-1])

print output

You need to take input.b,o=input(),"" should do it.

You can use backticks in place of str(). You can use a zip to construct a,n. The if statement can be used to multiply the "-" (reducing the for to a one liner. The if can be replaced with if a%10==1and a+n in(2,3,12,13). This gets you all the way down to 96 bytes.

weren't backticks deprecated or not supported after python 2.6 or something like that?

They were deprecated at 3.0 by PEP 3113, the ideone link I gave is using  2.7.10.

thanks, I was thrown off by the IDE marking it as invalid, runs just fine. what did you mean by using the zip construct? what to create?

If you take a look at my changes, you should see how I used zip(b,b[1:]) to generate the pairs of a,n (item,next).

sorry didn't notice. also, if I take your suggestions (which is great btw) it's more your answer than mine, if you want to post it let me know, otherwise I can give you attribution for practically answering it.

It's fine, take it. I used the same stuff in my Jelly answer.

Jelly, 20 bytes
%⁵=1a+e“£¤€Æ‘⁶ẋ⁸,⁹µ/

TryItOnline! or run all test cases
How?
%⁵=1a+e“£¤€Æ‘⁶ẋ⁸,⁹µ/ - Main link: the list
                   / - reduce
                  µ  - monadic chain separation
%⁵                   - left item mod 10
  =1                 - equal to 1? (Jan or Nov)
    a                - and
     +               - left item plus right item
      e              - is in
       “£¤€Æ‘        - jelly code page index list:  [2,3,12,13]
                           now True (1) for any of:
                               [1,1], [1,2], [1,11], [1,12], [11,1], or [11,2]
             ⁶       - literal space (the separator being used)
              ẋ      - repeated that many times
               ⁸     - left argument
                ,    - pair
                 ⁹   - right argument

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Draw an oblique line
Given the width and height of a line in characters, draw it using ascii characters.
Input
Two integers separated by a space, the first one being the width, the second one being the height.
Example: 5 3
Output
An oblique line formed with the characters /\|_, that has the width and height given in the input. The characters must be as well distributed as possible (eg as close as possible from a perfect line), any "leftover" characters being placed near the end of the line.
Good output for 5 3:
\_
  \_
    \

Bad output for 5 3:
\__
   \
    \

Test cases
1 1:
\

3 4:
\
|
 \
  \

10 3:
\__
   \__
      \___

4 7:
\
|
 \
 |
  \
  |
   \

-3 3:
  /
 /
/

3 8:
\
|
|
 \
 |
 |
  \
  |

-3 -8:
|
 \
 |
 |
  \
  |
  |
  \

6 2:
_
 \_
   \__

0 2:
|
|

2 0:
__

Clarification
The characters _ and | represent lines between "pixels". As it is obvious for _ to reprensent the line below the place we put it, it is not that obvious for | (placed in the center). Therefore, it must be arbitrarly decided that the line is located on the right. This next example thus shows a perfect square:
 __
|  |
|  |
 __

That being, a line that begins with a | is actually 1 character wider, with the first column looking empty and a line beginning with a _ is actualy 1 character higher, with the first row looking empty.
Rules

As usual, this is code-golf, shortest answer in bytes wins.
Standard loopholes are forbidden.

What do you mean by "well distributed"?

It's hard to explain, that's why I put a good and a bad example in "output". (I added "as close as possible from a perfect line")

@SteeveDroz did you see the edits I've made to your monthconcatenation?

Perhaps you mean something like this older challenge, which had the restriction 0 <= y <= x. There it was required that the output is identical to Bresenham's algorithm. There are some general rules for being a well distributed line, but they are indeed hard to explain.

Ugh! I thought I was being clever and I missed this one :-( Oh well, my question is a duplicate.


text:
Print the digital root
This is different from My Word can beat up your Word as it is less complex and only requires you to calculate it, and not compare them.
To find the digital root, take all of the digits of a number, add them, and repeat until you get a one-digit number. For example, if the number was 12345, you would add 1, 2, 3, 4, and 5, getting 15. You would then add 1 and 5, giving you 6.
Your task
Given an integer N (0 <= N <= 10000) through STDIN, print the digital root of N.
Test cases
1 -> 1
45 -> 9
341 -> 8
6801 -> 6
59613 -> 6
495106 -> 7

Remember, this is code-golf, so the code with the smallest number of bytes wins.

Can we take the input as a string?

@Dopapp Yes....

This is called a digital root.

Related.

Related.

Maybe a subtask of this challenge.

Very closely related to this challenge ... maybe close enough for a dupe.

@nimi That's why I had the feeling I had done something like this before..

Please be more precise when saying number. In particular. must input 0 be supported?

@TimmyD I think that this one is the much cleaner challenge without adding letter to integer conversion, computing the function for two values and including the literal STALEMATE. It might be better to close the other one as a dupe of this.

@MartinEnder Perhaps. Points out another reason why using the Sandbox is encouraged.

@MartinEnder I retracted my close vote, I think it's unfair to close a good challenge as a dupe of another more complex challenge.

You should add 10 as a test case. My algorithm was working fine for all your test cases, but was wrong for 10!

Pyke, 1 byte
s

Try it here!
Takes the digital root of the input

Jelly, 7 5 4 3 bytes
ḃ9Ṫ

TryItOnline! or all test cases
How?
The digital root is known to obey the formula (n-1)%9+1.
This is the same as the last digit in bijective base 9
(and due to implementation that 0ḃ9=[] and []Ṫ=0 this handles the edge-case of zero).
ḃ9Ṫ - Main link: n
ḃ9  - convert to bijective base 9 digits (a list)
  Ṫ - tail (get the last digit)

JavaScript (ES6), 16 10 bytes
n=>--n%9+1

Test cases

let f =

n=>--n%9+1

console.log(f(1)); // -> 1
console.log(f(45)); // -> 9
console.log(f(341)); // -> 8
console.log(f(6801)); // -> 6
console.log(f(59613)); // -> 6
console.log(f(495106)); // -> 7

Python, 16 20 bytes
+4 bytes to handle edge case of zero.
lambda n:n and~-n%9+1

repl.it

Wow. This is so easy it can be ported to any language. You can even ~-input()%9+1

Doesn't work for 0 unfortunately.

@KarlNapf Wouldn't that need a print?

@JonathanAllan Ah, possibly. I just tested it in the REPL environment and that did it.

@Emigna indeed it does not, it works for the natural numbers. We all know 0 is not a number. My Jelly solution works for 0. Negative numbers "work" with both - Jelly keeping the (one) sign, this dumping it.

I know the Jelly version works (as it uses the bijective base). I've always counted 0 as a number though. Hopefully the OP can confirm if we need to support it (as I can change back to my shorter code if we can ignore 0)

@JonathanAllan 0 is a number. It is no natural number though. The OP should clarify this.

@KarlNapf Who said numbers are going to be natural? 0 <= N <= 10000, and N is just used as a variable meaning number. I would argue that it would be good to use n instead of N, though.

@ the anonymous user who attempted an edit - it would have actually broken the code (made an input of 0 result in 9 rather than 0, which is what is catered for by the n and part of the code) furthermore it would have counted as 19 bytes not 13 (since the print and the space must be counted).

MATL, 3 bytes
9X\

Try it online!
A lot of (now deleted answers) tried using modulo 9 to get the result. This is a great shortcut, but unfortunately does not work for multiples of 9. MATL has a function for modulo on the interval [1, n]. Using this modulo, we have 1 % 3 == 1, 2 % 3 == 2, 3 % 3 == 3, 4 % 3 == 1, etc. This answer simply takes the input modulo nine using this custom modulo.

Mathematica, 27 11 bytes
Mod[#,9,1]&

Mathematica's Mod takes a third parameter as an offset of the resulting range of the modulo. This avoids decrementing the input and incrementing the output.

Julia, 12 bytes
!n=mod1(n,9)

or
n->mod1(n,9)

mod1 is an alternative to mod which maps to the range [1, n] instead of [0, n).

PHP, 15 Bytes
<?=--$argn%9+1;

Previous version PHP, 55 Bytes

$n=$argn;while($n>9)$n=array_sum(Str_split($n));echo$n;

Exactly how I did it!

@CT14.IT I can delete this post if you wish. Your deleted post ws 1 minute earlier and you have only forgot the while loop

Nah the deleted answer was wrong because I didn't read the question properly to start with, I didnt attempt to sum the generated number

You can add the trick of other answers <?=--$argv[1]%9+1?>

R, 72 67 29 bytes
Edit: Thanks to @rturnbull for shaving off two bytes.
n=scan();`if`(n%%9|!n,n%%9,9)

I recently learned that ifelse can be replaced by \if``, with identical behavior, which saves you a couple of bytes.

@rturnbull I was always wondering how  if  worked. Could you give an example or maybe add it to  Tips for golfing in ?

The simplest way to understand it is that it's a non-vectorized ifelse. In this case, \if`(n%%9|!n,n%%9,9)` provides identical behavior to the code you've posted. As far as I can tell, this behavior is undocumented! I'll add a comment to the tips thread.

Retina, 7 bytes
{`.
*
.

Try it online!
I see lots of mathematical solutions, but in Retina the straightforward approach seems to be the best one.
Explanation
{` makes the whole program run in a loop until the string doesn't change anymore. The loop consists of two stages:
.
*

Convert each digit to unary.
.

Count the number of characters (=convert the unary number to decimal).
This works because converting each digit to unary with no separator between digits creates a single unary number which is equal to the sum of all digits.

Haskell, 35 34 bytes
until(<10)$sum.map(read.pure).show

Try it on Ideone.
Explanation:
until(<10)$sum.map(read.pure).show
                              show  -- convert int to string
               map(         ).      -- turn each char (digit) into
                        pure        --    a string
                   read.            --    and then a number
           sum.                     -- sum up the list of numbers
until(<10)$                         -- repeat until the result is < 10

Perl, 15 bytes
Includes +2 for -lp
Give input on STDIN
root.pl <<< 123

root.pl
#!/usr/bin/perl -lp
$_&&=~-$_%9+1

This is the boring solution that has already been given in many languages, but at least this version supports 0 too
More interesting doing real repeated additions (though in another order) is in fact only 1 byte longer:
#!/usr/bin/perl -p
s%%$_+=chop%reg

Husk, 4 bytes
Recursive method (4 bytes) (Credit to @ovs)
ωoΣd

      # implicit parameter ⁰ (refers to the last parameter)
   d  # list of digits in base 10
  Σd  # sum of list
 oΣd  # compose the two functions
ωoΣd  # repeat until the function returns the same result as the previous one

Try it online!
Modulus method (4 bytes)
→%9←

      # implicit parameter ⁰ (refers to the last parameter)
   ←  # previous number (n - 1)
 %9←  # modulus by 9
→%9←  # next number (n + 1)

Try it online!

ωoΣd works for the recursive version

cool ill change it soon

Java 7, 63 bytes
int f(int n){int s=0;for(;n>0;n/=10)s+=n%10;return s>9?f(s):s;}

Recursive function which just gets digits with mod/div. Nothing fancy.
Cheap port
of Jonathan Allan's would be a measly 28 bytes:
int f(int n){return~-n%9+1;}

Labyrinth, 8 bytes
?(_9%)!@

using the equation (n-1)%9+1:

? reads the input as decimal and pushes it to the stack
( decrements the top of the stack
_ pushes a zero onto the top of the stack
9 push the top of the stack popped times 10 the digit (in this case, 9)
% pops y, pops x, pushes x%y
) increments the top of the stack
! pops the top of the stack and out puts it as a decimal string
@ terminates the program

Hexagony, 19 15 bytes
.?<9{(/>!@!/)%'

More Readable:
  . ? <
 9 { ( /
> ! @ ! /
 ) % ' .
  . . .

Try it online!
-3 bytes by taking a different approach, making the 0 edge case trivial.
-1 byte by fixing 0 edge case bug
Using the formula ((n-1) mod 9) + 1 like a lot of other solutions aswell.

Japt -h, 6 4 bytes
Æ=ìx

Try it
Æ=ìx     :Implicit input of integer U
Æ        :Map the range [0,U)
 =       :  Reassign to U
  ì      :  Convert to digit array
   x     :  Reduce by addition
         :Implicit output of last element

05AB1E, 6 bytes
[SODg#

Try it online!
Explanation
[        # infinite loop
 S       # split into digits
  O      # sum digits
   Dg#   # if length == 1: break

JavaScript (ES6), 41 38 bytes
Saved 3 bytes, thanks to Bassdrop Cumberwubwubwub
Takes and returns a string.
f=s=>s[1]?f(''+eval([...s].join`+`)):s

Test cases

f=s=>s[1]?f(''+eval([...s].join`+`)):s

console.log(f("1")); // -> 1
console.log(f("45")); // -> 9
console.log(f("341")); // -> 8
console.log(f("6801")); // -> 6
console.log(f("59613")); // -> 6
console.log(f("495106")); // -> 7

You can change s.split\`to[...s]`

Brachylog, 9 bytes
#0|@e+:0&

Try it online!
Explanation
#0            Input = Output = a digit
  |           OR
   @e         Split the input into a list of digits
     +        Sum
      :0&     Call this predicate recursively

Alternative approach, 11 bytes
:I:{@e+}i#0
This one uses the meta-predicate i - Iterate to call I times the predicate {@e+} on the input. This will try values of I from 0 to infinity until one makes it so that the output of i is a single digit which makes #0 true.

Ruby, 12 bytes
->n{~-n%9+1}

19 ? Shouldn't that be 9 ?

@TonHospel Yes, stupid error :P

CJam, 19 13 bytes
r{:~:+_s\9>}g

Interpreter
Explanation:
r{:~:+_s\9>}g Code
r             Get token
 {:~:+_s\9>}  Block: :~:+_s\9>
   ~          Eval
  :           Map
     +        Add
    :         Map
      _       Duplicate
       s      Convert to string
        \     Swap
         9    9
          >   Greater than
            g Do while (pop)

Thanks to 8478 (Martin Ender) for -6 bytes.

CJam, 6 bytes
ri(9%)

Suggested by 8478 (Martin Ender). Interpreter
I was thinking about it, but Martin just got it before me. Explanation:
ri(9%) Code
r      Get token
 i     Convert to integer
  (    Decrement
   9   9
    %  Modulo
     ) Increment

Single-command map and reduce can both be written with prefix :, so you can do :~:+. It also doesn't hurt to run the block at least once so you can use a g loop instead of a w loop.

@MartinEnder r{_,1>}{:~:+\}wworks, but I don't know how on earth am I supposed to useg` here.

E.g. like this: r{:~:+_s\9>}g (of course the closed form solution ri(9%) is much shorter.

@MartinEnder Oh gawd, for real now, I'm such a beginner...

The second one doesn't work on multiples of 9

Factor, 24
Smart, mathy answer.
[ neg bitnot 9 mod 1 + ]

63 for dumb iterative solution:
[ [ dup 9 > ] [ number>string >array [ 48 - ] map sum ] while ]

Pyth - 7 4 6 7 bytes
Not the best one, but still beats a decent amount of answers:
|ejQ9 9

Like the previous version, but handling also cases of multiples of 9, using logical or.

This version fails the 45 testcase:
ejQ9

Explanation:
 jQ9  -> converting the input to base 9
e     -> taking the last digit

Try it here
Try the previous version here!

Previous solutions:
&Qh%tQ9

Explanation:
    tQ    -> tail: Q-1
   %tQ9   -> Modulo: (Q-1)%9
  h%tQ9   -> head: (Q-1)%9+1
&Qh%tQ9   -> Logical 'and' - takes the first null value. If Q is 0 - returns zero, otherwise returns the (Q-1)%9+1 expression result

You're invited to try it here!

Your 4-byte version fails test case 45.

Won't this give 0 for multiples of 9?

Yeah, I just noticed it. Will do some fixing there. Apparently,  jQ9 doesn't act like Jelly's ḃ9 :-P

J, 8 bytes
**1+9|<:

Uses the formula d(n) = ((n-1) mod 9) + 1 with the case d(0) = 0.
Usage
   f =: **1+9|<:
   (,.f"0) 0 1 45 341 6801 59613 495106
     0 0
     1 1
    45 9
   341 8
  6801 6
 59613 6
495106 7

Explanation
**1+9|<:  Input: integer n
      <:  Decrement n
    9|    Take it modulo 9
  1+      Add 1 to it
*         Sign(n) = 0 if n = 0, else 1
 *        Multiply and return

APL (Dyalog), 15 9 bytes bytes
××1+9|-∘1

Try it online!

Python 2, 54 51 bytes
i=input()
while~-len(i):i=`sum(map(int,i))`
print i

Thanks to Oliver and Karl Napf for helping me save 3 bytes

You can change while len(i)>1 to while~-len(i) to save one byte.

I think you can omit the ticks around input() and force the input the be enclosed in quotes to save 2 bytes.

@KarlNapf I don't think you can do this when the input is an integer.

@EriktheGolfer, the op said that the input can be taken as a string

C, 64 29 bytes
C port from Jonathan Allan's answer (with special case 0).
f(i){return i>0?~-i%9+1:0;}

Previous 64 byte code:
q(i){return i>9?i%10+q(i/10):i;}
f(i){i=q(i);return i>9?f(i):i;}

q takes the cross sum and f repeats taking the cross sum until a single digit.

Python, 45 bytes
f=lambda x:x[1:]and f(`sum(map(int,x))`)or x

Takes the argument as a string.

Retina, 15 bytes
.+
$*
1{9}\B

1

Try it online! (The first line enables a linefeed-separated test suite.)
Explanation
.+
$*

Convert input to unary.
(1{9})*\B

Take 1-based modulo by removing nines that have at least one more character after them.
1

Count the remaining number of 1s to convert back to decimal.

Perl 6, 29 bytes
{($_,*.comb.sum...10>*)[*-1]}

Expanded:
{ # bare block lambda with implicit parameter ｢$_｣
  ( # generate a sequence

    $_,         # starting with the input
    *.comb.sum  # Whatever lambda that splits into digits, and finds sum
    ...         # keep doing that
    10 > *      # until it is less than 10

  )[ * - 1 ] # get the last value
}

braingolf, 20 13 bytes
[Rdl1-M&+v>]R

Try it online!
Links to the braingolf JS interpreter in TIO
Explanation
[Rdl1-M&+v>]R   Implicit input from command-line args to stack
[..........]R   Loop. Always runs once, will continue to run as long as the bottom value on the active stack is > 0
 R              Return to main stack, does nothing if already on main stack
  d             Pop top of stack, split into digits, push digits
   l            Push length of stack
    1-          Decrement top of stack
      M         Pop top of stack and push to next stack
       &+       Sum entire stack (all digits of input)
         v      Switch active stack to next stack
          >     Move top of stack to bottom

Decrementing the stack length, moving it to the second stack, and switching to the second stack before the end of the loop serves to use the decremented length as the loop counter. ie when the length is 1 (decremented to 0) the loop terminates.

Tcl, 57 bytes
while \$v>9 {set v [expr [join [split $v ""] +]]}
puts $v

Try it online!

dc, 37 bytes
[[A~rdZ1<D]dsDx[+z1<S]dsSxdZ1<M]dsMxp

Try it online!
[A~rdZ1<D]dsDx decompose. Divide by 10 leaving quotient & remainder on stack until the value on the top of the stack is a single digit.
[+z1<S]dsSx sum. Add two topmost stack values until stack depth is one.
Macro M contains both of those, and dZ1<M to keep running itself until the final result is a single digit. p to print.

JavaScript, 37 bytes
Input is taken as a string.
f=n=>n>9?f(eval([...n].join`+`)+""):n

Try it online!

Forth (gforth), 69 bytes
: f begin 0 swap begin 10 /mod >r + r> ?dup 0= until dup 10 < until ;

Try it online!
Explanation

Place sum (starting at 0) on stack
Get remainder of number divided by 10
Add to sum
Replace number with itself divided by 10
Repeat steps 2-4 until number equals 0
Using sum as new starting number, repeat steps 1-5 until result is less than 10

Code Explanation
begin               \ start outer loop
  0 swap            \ place sum variable and move it down the stack
  begin             \ start inner loop
    10 /mod         \ get quotient and remainder of number/10
    >r +            \ temporarily "hide" quotient on return stack and add remainder to sum
    r> ?dup         \ retrieve quotient from return stack and duplicate if != 0
  0= until          \ end inner loop if sum is equal to 0
  dup 10 <          \ duplicate current "root" and check if less than 10
until               \ end outer loop if < 10

K (oK), 9 bytes
Solution:
(+/.:'$)/

Try it online!
Explanation:
Super straightforward. Break number into digits and sum up - do this until the result converges:
(+/.:'$)/ / the solution
(      )/ / do this until result converges
      $   / string, 1234 => "1234"
   .:'    / value each, "1234" => 1 2 3 4
 +/       / sum over, 1 2 3 4 => 10

In my implementation of k I made x\y encode y in base x with as many digits as necessary, so it's slightly shorter: (+/10\)/

Nice. In the newer versions of kdb+ (I think from 3.4 and up) you can do 10\:.. but not in oK - and .:'$ is the same number of bytes - so I went with that :)

oK uses \ and requires a list on the left: (,10)\

Indeed, your implementation adds "as many digits as necessary", which is what you get from \: in kdb+ (3.4+), but for oK I'd need to know how many 10s to put in my list.

Excel VBA, 69 bytes
An anonymous VBE immediate window function that takes input from range [A1] and outputs to the console.
n=[A1]:While n>9:s=0:For i=1To Len(n):s=s+Mid(n,i,1):Next:n=s:Wend:?n

Test Function
For each x in Array(1,45,341,6801,59613,495106):[A1]=x:n=[A1]:While n>9:s=0:For i=1To Len(n):s=s+Mid(n,i,1):Next:n=s:Wend:?x"->"n:Next
 1 -> 1
 45 -> 9
 341 -> 8
 6801 -> 6
 59613 -> 6
 495106 -> 7

QBasic 1.1, 66 bytes
INPUT N
WHILE N>9
M=N
N=0
WHILE M
N=N+M MOD 10
M=M\10
WEND
WEND
?N

K (ngn/k), 8 bytes
(+/10\)/

Try it online!
this is based on @streetster's oK answer but uses a feature specific to ngn/k: 10\x is the list of digits of x

Ohm v2, 5 bytes
ì‹9%›

Explanation:
ì‹9%›
ì     Takes input as integer
 ‹    Decrements
  9%  Modulus 9
    › Increment

Try it online!

MBASIC, 105 94 bytes
1 INPUT N
2 A$=STR$(N):N=0:FOR I=1 TO LEN(A$):N=N+VAL(MID$(A$,I,1)):NEXT:IF N>9 THEN 2
3 PRINT N

Output:
? 495106
 7

? 59613
 6

? 6801
 6

Explanation:
Convert input to a string, then walk the string, adding each digit to a total. If the resulting total has more than 1 digit, repeat the process.
Otherwise, print the total.
Okay, so it's not APL. But it will run on an 8-bit CP/M system. :-)

Keg, 6 bytes(SBCS on Keg wiki)
¿;9%1+

Explanation:
¿#      Take implicit input
 ;9%1+# Digital Root Formula
# Implicit output

TI-Basic, 11 bytes
1+9fPart((Ans-1)/9

Takes input in Ans.

Vyxal, 3 bytes
⁽∑Ẋ

Try it Online!
⁽ Ẋ # Until the result converges...
 ∑  # Sum digits

Your first answer does not work when the input is a multiple of 9.

@Yousername Oops. Deleting.

https://vyxal.pythonanywhere.com/#WyJnIiwiIiwi4oG94oiR4oaUIiwiIiwiNDgyIl0=   another 3 byte solution

APL (Dyalog Classic), 3 bytes
9⊤⊢

Try it online!
Anonymous tacit prefix fork train.
 ⊤      ⍝ Tail of base conversion of
   ⊢    ⍝ right argument to
9       ⍝ base 9

COBOL (GNU), 131 bytes
PROGRAM-ID.A.DATA DIVISION.
	WORKING-STORAGE SECTION.
	01 N PIC 9(9).
PROCEDURE DIVISION.ACCEPT N.COMPUTE N=FUNCTION REM(N- 1,9)+ 1

Try it online!
Explanation :
PROGRAM-ID.A.DATA DIVISION.
       * The first line is necessary and can't be removed
        WORKING-STORAGE SECTION.
       * sadly so is this (accept input / output)
        01 N PIC 9(9).
       * This accepts input N that is upto 999,999,999 (output is via same)
        PROCEDURE DIVISION.
       * Time to start working on program itself.
        ACCEPT N.
       * Accepts the input from stdin.
        COMPUTE N = FUNCTION REM(N - 1, 9) + 1
       * compute n such that it is mod of n - 1 and 9 and then add one (standard forumla of --N%9+1

Output is via display N.

Vyxal, 4 bytes
‹9%›

Try it Online!

Charcoal, 9 bytes
⁺﹪⁻Ｎ¹¦⁹¦¹

TryItOnline!
Explanation:
⁻Ｎ¹  - take a integer input and subtract one from it
﹪     - modulo function
⁺     - addition function which given to it n-1%9 and 1
⁹     - number 9 which is like 10-1
¦     - just a argument separator

PS: You could have reduced the argument separator by writing it in this order:
⁺¹﹪⁻¹Ｎ⁹ but 7 is not a cool length to have, Also you could put a Ｉ before the whole thing to cast the result to printable integer value but since the numbers are represented as - characters in charcoal i ignored that.

05AB1E, 3 bytes
ΔSO

Try it online or verify all test cases.
Or a minor alternative:
Δ1ö

Try it online or verify all test cases.
Explanation:
Δ    # Loop until the result no longer changes,
     # using the (implicit) input-integer in the first iteration
 S   #  Convert it to a list of digits
  O  #  Sum those together
     # (after which the resulting digit is output implicitly)

Δ    # Loop until the result no longer changes,
     # using the (implicit) input-integer in the first iteration
 1ö  #  Convert it from base-10 to base-1
     #  (which is a non-vectorizing way to sum an integer's digits in 05AB1E)
     # (after which the resulting digit is output implicitly)

Go, 75 bytes
func f(n int)int{if n<10{return n}
k:=0
for;n>0;n/=10{k+=n%10}
return f(k)}

Attempt This Online!
Go, Modulus solution, 29 bytes
func(n int)int{return^-n%9+1}

Attempt This Online!

Fig, \$4\log_{256}(96)\approx\$ 3.292 bytes
}%9{

Try it online!
}%9{
   {  # decrement with implicit input
 %9   # mod 9
}     # increment

><> (Fish), 36 bytes
>0$:1(?v:&a%+&a,:1%-20.
^v?(a:~<
n<;

Try it online! - Interactive Version
Expects input as a number pushed onto the stack in advance.
Explanation
There are 2 basic loops, one for summing the digits and one for checking if the number is less than 10 yet.
   :1(?v

Checks if the number is less than 1, if not all the digits are summed.
        :&a%+&a,:1%

Add the modulo to the accumulator, and then push the division again. We subtract the number %1 to make it a integer.
                   20.

Skip the first 3 letters of the bottom row.
^v?(a:~<
n<;

If the number is less than 10 (a is 10 in fish, it uses hexadecimal), print it and exit. Otherwise, go back to the start of the program with the number pushed to the stack.
>0$

Push the accumulator to the second from first spot on the stack.

You can save 20 bytes by performing the operations on the input and erroring out: :a(?n:a%$a,:1%-+

Perl 34 28 bytes
Includes +1 for -p
s/./+$&/g,$_=eval while/../

Uses the method described in the question.
Example:
$ echo -n 495106 | perl -p DigitalRoot.pl
7

You need to count -p in your bytecount. (in that case, it will count for 3 bytes, but if you replaces the '' with "" then it's only 1 byte). And you can golf it further : the same approach can be written like s/./+$&/g,$_=eval while/../. Or you could do s/(.)(.)/$1+$2/e&&redo which is even shorter. And a shorter code (the approach is totally different) :  $_=--$_%9+1.

@Dada I was trying to figure out why it wouldn't run on the command line for so long that I must have forgotten to add the extra bytes when I gave up (I don't use perl much).

@Dada s/(.)(.)/$1+$2/e&&redo doesn't exactly follow the method given in the question either.

perl -lpe 's%%s/\B/+/g;$_=eval%egr'

Groovy, 57 Bytes
{n->for(;(n=(""+n).collect{(int)it-48}.sum())/10>1;){};n}

Repeatedly converts to string, sums the ascii conversion of the digits and continues while the resultant integer divided by 10 is greater than 1. Then it returns the mutated input.
Tried recursion too, cost more bytes though:
x={i->i?i%10+x(i.intdiv(10)):0};y={i->x(i)/10<1?x(i):y(x(i))}

C#, 79 Bytes
Golfed:
string R(string i){while(i.Length>1){i=i.Sum(o=>int.Parse(o+""))+"";}return i;}

Ungolfed:
string R(string i)
{
  while (i.Length > 1)
  {
    i = i.Sum(o => int.Parse(o + ""))+"";
  }

  return i;
}

Testing:
var printTheDigitalRoot = new PrintTheDigitalRoot();
Console.WriteLine(printTheDigitalRoot.S("1")); //1
Console.WriteLine(printTheDigitalRoot.S("45")); //9
Console.WriteLine(printTheDigitalRoot.S("341")); //8
Console.WriteLine(printTheDigitalRoot.S("6801")); //6
Console.WriteLine(printTheDigitalRoot.S("59613")); //6
Console.WriteLine(printTheDigitalRoot.S("495106")); //7

string is already IEnumerable<char> so you don't need to ToCharArray() before calling Sum() on it. o-48 is a shorter than int.Parse(o+""). Having said these, the mod 9 trick will be much shorter than actually summing the digits.

Element, 32 bytes
_2:1-+9/3:0<!{1-+2:0<!}1+-+9-*+`

Try it online!
This is using the typical closed-form formula, although it is noticeably more painful since Element lacks any rounding functionality.
_2:1-+9/3:0<!{1-+2:0<!}1+-+9-*+`
_2:                               make two copies of input
   1-+9/                          for one copy, subtract 1 and divide by 9
        3:0<!{1-+2:0<!}1+-+       floor it
                           9-*    multiply by -9
                              +`  add to the original input value, then output

Racket 152 bytes
(let p((ol'())(n n))(let*-values(((q r)(quotient/remainder n 10))((l)(cons r ol)))
(if(= q 0)(begin(let((s(apply + l)))(if(< s 10)s(p'()s))))(p l q)))))

Ungolfed:
(define (f n)
  (let loop ((ol '())
             (n n))
    (let*-values (((q r) (quotient/remainder n 10))
                 ((l) (cons r ol)))
      (if (= q 0)
          (begin
            (let ((s (apply + l)))
              (if (< s 10)
                  s
                  (loop '() s))))
          (loop l q))
      )))

Simpler version:
(define (f1 N)
  (define (getDigitList n)                   ; sub-fn  to get digits
    (let loop ((ol '())
               (n n))
      (let-values (((q r) (quotient/remainder n 10)))
        (if (= q 0) (cons r ol)
            (loop (cons r ol) q)))))

    (let loop2 ((n N))                       ; actual fn
      (define s (apply + (getDigitList n)))  ; get sum of digits
      (if (< s 10)
          s
          (loop2 s))))

Testing:
(f 1)
(f 45)
(f 341)
(f 6801)
(f 59613)
(f 495106)

Output:
1
9
8
6
6
7

Thunno 2 t, 2 bytes
9B

Attempt This Online!
Port of Jonathan Allan's Jelly answer.
Explanation
9B  # Implicit input
 B  # Convert the input to a
9   # list of digits in base 9
    # Implicit output of last item


text:
Convert Chinese numbers
In Chinese, numbers are written as follows:
1 一 2 二 3 三 4 四 5 五 6 六 7 七 8 八 9 九 10 十
For numbers above 10, it is expressed as the number of tens and the number of ones. If there is only one ten, you do not need to explicitly say one, and if there are no ones, you don't need to put anything after:
11 十一
24 二十四
83 八十三
90 九十
For numbers above 100, you use the same logic, but with the character 百. This time though, if there is only one hundred, you still need to write it out, and if there are no tens, you need to say 零.
100 一百 231 二百三十一 803 八百零三 999 九百九十九
Your task is to convert these Chinese numerals into Arabic numerals. Given a number N in Chinese (一 (1) <= N <= 九百九十九 (999)), convert it into an Arabic number.
Remember, this is code-golf, so the code with the smallest number of bytes wins.

Can you add test cases 503 and 380?

^ Good point. If I am following correctly, it should be 503 -> 五百三 and 380 -> 三百八十. Also, you say for tens that you do not need to explicitly say one. Does that mean it doesn't matter if we do?

Related

Up to 999? You shuold give the upper limit

503 should be 五百零三 as there are no tens (I think)

JavaScript (ES6), 112 bytes
s=>[...s].map(c=>d=(i="零一二三四五六七八九十百".search(c))>9?(n+=(d||1)*(i*90-890),0):i,n=d=0)&&n+d

Digits 一-九 are converted to decimal and saved in d, while 十 and 百 multiply the last digit by 10 or 100 respectively and accumulate it in n. 零 is effectively ignored, since d is already zero when it is encountered.

PHP, 225 Bytes
preg_match_all("#[1-9]?10+|[1-9]#",str_replace(["一","二","三","四","五","六","七","八","九","十","百"],[1,2,3,4,5,6,7,8,9,10,100],$argv[1]),$z);foreach($z[0]as$p)$s+=($b=substr_count($p,0))?$p[0]*10**$b:$p;echo$s;

Too bad that strtr is not multibyte safe. It could save you 23 bytes. But you can use 0+ instead of 00?, saving one byte or you can a) replace with a and aa instead of 10 and 100, b) use a+ instead of 100? in the regex and c) a instead of 0 for substr_count (-4).

@Titus your way with a can not work in the range 10-19

Perl, 110 bytes
98 bytes code + 12 for -plC -Mutf8.
Perl does hate unicode. Hopefully I haven't missed any edge cases, I had an issue with numbers like 二百十 but I've addressed that now!
s/十/*10+/;s/百/*100+/;y/一二三四五六七八九零/123456789 /;s/^\*|\+\*/+/g;$_=eval"$_-0"

Usage
perl -plC -Mutf8 -e 's/十/*10+/;s/百/*100+/;y/一二三四五六七八九零/123456789 /;s/^\*|\+\*/+/g;$_=eval"$_-0"' <<< '一
二
三
四
五
六
七
八
九
十
十一
二十四
八十三
九十
一百
二百三十一
八百零三
九百九十九'
1
2
3
4
5
6
7
8
9
10
11
24
83
90
100
231
803
999

Java 7, 236 233 229 bytes
int c(String s){String x=" 一二三四五六七八九十百";int l=s.length(),i=x.indexOf(s.charAt(l-1)),j=x.indexOf(s.charAt(0)),q=j*100;return l<2?i:l<3?i==10?j*10:i>10?q:10+i:l<4?j*10+i:l<5?q+i:q+i+x.indexOf(s.charAt(2))*10;}

Ungolfed & test code:
Try it here.
class M{
  static int c(String s){
    String x = " 一二三四五六七八九十百";
    int l = s.length(),
        i = x.indexOf(s.charAt(l-1)),
        j = x.indexOf(s.charAt(0));
    if(l<2) return i; // 1-10
    if(l<3){
      if(i==10) return j*10; // 20,30,40,50,60,70,80,90
      if(i>10) return j*100; // 100,200,300,400,500,600,700,800,900
      return 10+i; // 11-19
    }
    if(l<4) return j*10+i; // 21-29,31-39,41-49,51-59,61-69,71-79,81-89,91-99
    if(l<5) return j*100+i; // 101-109,201-209,301-309,401-409,501-509,601-609,701-709,801-809,901-909
    return j*100+i+x.indexOf(s.charAt(2))*10; // 111-119,121-129,131-139,...,971-979,981-989,991-999
  }

  public static void main(String[] a){
    System.out.println(c("一"));
    System.out.println(c("二"));
    System.out.println(c("三"));
    System.out.println(c("四"));
    System.out.println(c("五"));
    System.out.println(c("六"));
    System.out.println(c("七"));
    System.out.println(c("八"));
    System.out.println(c("九"));
    System.out.println(c("十"));
    System.out.println(c("十一"));
    System.out.println(c("二十四"));
    System.out.println(c("八十三"));
    System.out.println(c("九十"));
    System.out.println(c("一百"));
    System.out.println(c("二百三十一"));
    System.out.println(c("八百零三"));
    System.out.println(c("九百九十九"));
  }
}

Output:
1
2
3
4
5
6
7
8
9
10
11
24
83
90
100
231
803
999

PowerShell Core, 131 bytes
$args|%{if($i=("一二三四五六七八九"|% I*f $_)+1){$b=$i}if($_-eq"十"){$t+=(!$b+$b)*10
$b=0}if(!$i){$t+=$b*100
$b=0}}
$t+$b

Try it online!
-10 bytes thanks to Zaelin Goodman!

-10 bytes

PowerShell, 107 bytes
switch -r($args){百{$s+=100*$d}十{$s+=10*($d+!$d)}.{$d='一二三四五六七八九'.IndexOf($_)+1}}$d+$s

Try it online!

106 bytes!

Python 3, 128 bytes
Saving 2+3 bytes thanks to Shebang and 2 for replacing (d>9)+(d>10) with max(d-9,0)
n=a=0
for c in input():d=" 一二三四五六七八九十百".find(c);n+=[0,10*a**(a>0),a*100][max(d-9,0)];a=d*(d<10)
print(n+a)

Ungolfed:
n=a=0
for c in input():
 d=" 一二三四五六七八九十百".find(c)
 n+=[0, 10*a**(a>0), a*100][max(d-9,0)]
 a=d*(d<10)
print(n+a)

Initial answer
n=a=0
for c in input():
 d=" 一二三四五六七八九十百".find(c)
 if d<=9:a=d
 elif d==10:n+=[1,a][a>0]*10;a=0
 elif d==11:n+=a*100;a=0
print(n+a)

n will be the final number and a is the previous digit.

The spec has changed.

@Shebang Luckily it does not matter, 803 still works.

@TimmyD It is ignored. find returns -1 and that is smaller than 9 so n and a  are untouched.

Also, this is 135 bytes. All of the chinese chars are 3 bytes long.

@Shebang You are right. Just looked at the char counter.

[1,a][a>0]*10 -> 10*a**(a>0) saves two bytes :)

[0,d][d<=9] -> d*(d<10) saves three bytes too!

C#, 197 210 bytes
int x(string s){if(s=="")return 0;if(s[0]=='零')s=s.Substring(1);if(s[0]=='十')s="一"+s;string t=" 一二三四五六七八九";return s.Length<2?t.IndexOf(s[0]):(t.IndexOf(s[0])*(s[1]=='百'?100:10)+x(s.Substring(2)));}

Wrong byte count previously due to encoding ignored...
Big5 Encoding
A recursive solution which pads the input if it's 10-19 for easier processing, then process from left 2 characters at a time.
Ungolfed
public int x(string s)
{
    if (s == "")
        return 0;   // Recursion termination when input is divisible by 10 (no unit digit character)
    if (s[0] == '零')
        s = s.Substring(1);   // Ignore '零'
    if (s[0 ]== '十')
        s = "一" + s;   // Normalize 10-19 by padding with "一"
    string t = " 一二三四五六七八九";   // Index lookup
    return s.Length < 2
        ? t.IndexOf(s[0])   // 0-9
        : (t.IndexOf(s[0]) * (s[1] == '百' ? 100 : 10) + x(s.Substring(2)));
    // Get the first character's digit, multiply by 100 or 10 depends on 2nd character, and recursively process from 3rd character onwards
}


text:
Display an xkcd
xkcd is everyone's favorite webcomic, and you will be writing a program that will bring a little bit more humor to us all.
Your objective in this challenge is to write a program which will take a number as input and display that xkcd and its title-text (mousover text).
Input
Your program will take a positive integer as input (not necessarily one for which there exists a valid comic) and display that xkcd: for example, an input of 1500 should display the comic "Upside-Down Map" at xkcd.com/1500, and then either print its title-text to the console or display it with the image.

Due to their proximity across the channel, there's long been tension between North Korea and the United Kingdom of Great Britain and Southern Ireland.
Test case 2, for n=859:

Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or ;;"''{<<[' this mouseover text."
Your program should also be able to function without any input, and perform the same task for the most recent xkcd found at xkcd.com, and it should always display the most recent one even when a new one goes up.
You do not have to get the image directly from xkcd.com, you can use another database as long as it is up-to-date and already existed before this challenge went up. URL shortners, that is, urls with no purpose other than redirecting to somewhere else, are not allowed.
You may display the image in any way you chose, including in a browser. You may not, however, directly display part of another page in an iframe or similar. CLARIFICATION: you cannot open a preexisting webpage, if you wish to use the browser you have to create a new page. You must also actually display an image - outputting an image file is not allowed.
You can handle the case that there isn't an image for a particular comic (e.g. it is interactive or the program was passed a number greater than the amount of comics that have been released) in any reasonable way you wish, including throwing an exception, or printing out an at least single-character string, as long as it somehow signifies to the user that there isn't an image for that input.
You can only display an image and output its title-text, or output an error message for an invalid comic. Other output is not allowed.
This is a code-golf challenge, so the fewest bytes wins.

Is output aside from the image/alt-text allowed? i.e. the entire source of the page?

@LukeFarritor You can only display the image and output the title text or output some form of error message for an invalid comic.

If your sample size is 1, import antigravity in Python ;)

Funny fact n=404 http://xkcd.com/404 is a 404 page.

Is simply finding and outputting the  to an HTML file okay?

xkcd is everyone's favorite webcomic [Citation needed]

@carusocomputing the source would have to be a file downloaded to your computer and the program would have to open the html file in a browser.

Test case: 859

@betseg Lol, QUICK! Everyone use use .eval() statements.

If we can't open a pre-existing webpage, would it be cheating to download the HTML remotely into a local HTML file and open that?

@JAL you A) cannot display anything but the image and title text, and B) can only use files downloaded by the program to your computer as the src for img tags.

Is it acceptable to print out the alt text after the image window is closed?

@quartata Yes, that would be acceptable.

Something that people may not be aware of but which may be relevant: there's an XKCD API.

@EriktheGolfer I just figured that I'd accept the current lowest answer and then change it if anyone comes up with a lower one. I'm fairly new here, and was not aware that that was how it was supposed work.

Perl + curl + feh, 86 84 75 bytes
`curl xkcd.com/$_/`=~/<img src="(.*)" title="(.*?)"/;$_=$2;`feh "http:$1"`

Requires the -p switch. I have accounted for this in the byte count.

@Matt It worked on all the comics I tried. It only matches images with alt-text so.

You may not need the quotes around the src attribute.

I don't think you need the ? in the first match group. You could use -p and $_=$2 instead of print$2, but then the title text is printed only after feh is closed. Not sure if that's valid.

@m-chrzan Yeah looks like I can drop the reluctant quantifier there, thanks. I thought about using -p but wasn't sure how the OP would feel about it.

@ConorO'Brien Unfortunately Randall observes good HTML coding practices... and capturing the quotes doesn't then quote the arguments due to how backticks work in Perl.

@quartata Oh...

perl + curl = ... pceurl?

You should be able to replace curl -L http://xkcd.com/$_ with curl xkcd.com/$_/.

@Dennis Doesn't work on my machine.

Do you provide input with or without a trailing linefeed?

@Dennis Without a trailing linefeed it works. Strange.

http://xkcd.com/n redirects to http://xkcd.com/n/. If the input has a trailing linefeed, curl xkcd.com/$_ will fail because of the redirect, then / (on the next line) causes a syntax error.

Oh, I see now. Oops.

PowerShell v3+ 110 99 107 103 Bytes
iwr($x=((iwr "xkcd.com/$args").images|?{$_.title})).src.Trim("/") -outf x.jpg;if($x){ii x.jpg;$x.title}

Thanks to Timmy for helping save some bytes by using inline assignments.
If no arguments are passed then $args is null and it will just get the current comic. Download the picture, by matching the one with alt text, into a file in the current running directory of the script. Then display it with the default viewer of jpg's. The alt text is then displayed to console. iwr is an alias for Invoke-WebRequest
If the number passed (or any invalid input for that matter) does not match the process fails with at least a 404 error.
iwr(                                  # Request the comic image from XKCD
  $x=((iwr "xkcd.com/$args").images|  # Primary search to locate either the current image
                                      # or one matching an argument passed
     ?{$_.title}))                    # Find the image with alt text
        .src.Trim("/")                # Using the images associated link and strip the leading slashes
  -outf x.jpg                         # Output the image to the directory local to where the script was run
if($x){                               # Test if the image acquisition was successful
    ii x.jpg                          # Open the picture in with the default jpg viewer
    $x.title                          # Display alt text to console
}                                     # I'm a closing bracket.

Only just got my comment privilege on this sub now, check out my very similar answer

@ConnorLSW Nice approach in your answer. Things to think about for next time.

AutoIt, 440 bytes
Yes, it's long, but it's stable.
#include<IE.au3>
#include<GDIPlus.au3>
Func _($0='')
_GDIPlus_Startup()
$1=_IECreate('xkcd.com/'&$0)
For $3 In $1.document.images
ExitLoop $3.title<>''
Next
$4=_GDIPlus_BitmapCreateFromMemory(InetRead($3.src),1)
$6=_GDIPlus_ImageGetDimension(_GDIPlus_BitmapCreateFromHBITMAP($4))
GUICreate(ToolTip($3.title),$6[0],$6[1])
GUICtrlSendMsg(GUICtrlCreatePic('',0,0,$6[0],$6[1]),370,0,$4)
_IEQuit($1)
GUISetState()
Do
Until GUIGetMsg()=-3
EndFunc

First of all, this doesn't use RegEx to scrape the site (because I have no time to test this on all comics), but rather uses the Internet Explorer API to iterate through the DOM's img tags until it finds one with a title text.
The binary stream is read from the image URL and rendered into a bitmap using GDIPlus. This is then displayed in a nice, auto-sized GUI with an actual tooltip to make it behave almost exactly like the website.
Here's a test case (_(859)):

)

It would be better if you added the bracket back into the image.

Wow, just found out that I can run AutoIt under Wine on Ubuntu. Now all I need to do is get IE working on there. On second thoughts... +1 for the answer

@ElPedro If you have a modern CPU, use qemu KVM and seamlessRDP (basically a DIY parallels for linux) instead of wine. This integrates Windows apps seamlessly into the linux desktop and has 100% compatibility + GPU passthrough. Just a tip.

Thanks @mınxomaτ. I may give that a go. I work with Windows all day so prefer to use Linux (various flavours) out of work but I am always interested in experimenting :) Tip gratefully received.

Powershell, 93 Bytes
93 Byte version to use local image viewer.
$n=(iwr xkcd.com/$args).images|?{$_.title};$n.title;iwr ("http:"+$n.src) -OutF x.jpg;ii x.*

Saved 2 bytes by removing needless doublequotes, then another lot by using ("http:"+$n.src) instead of "https://"+$n.src.trim("/") - since the img src comes with // already on it, and xkcd doesn't require https.
$n=(iwr xkcd.com/$args).images|?{$_.title};$n.title;saps ("http:"+$n.src)

$n=(iwr "xkcd.com/$args").images|?{$_.title};$n.title;saps ("https://"+$n.src.trim("/"))
extremely similar to Matts powershell answer, (should probably be a comment but low reputation)
Instead this opens a new tab/window in the default browser, and other things, saving some bytes.
iwr is an alias for Invoke-WebRequest
saps is an alias for Start-Process which opens 'it' in the default context.

Skirting the edges of the rules about opening an existing webpage, because this is just directly launching the browser at the pre-existing .jpg (or whatever), but a nice answer.

@TimmyD might have misunderstood here then - I assumed you can use the xkcd webpage itself - you can just change saps to iwr and append  -OutF x.jpg;ii x.* to the end if you want it to open in the default local image viewer.

The OP specified that you aren't allowed to open a pre-existing webpage. The 93 byte version I think is fine though

I don't think this is going to always work the same if you give a number that works then a number that does not. It will open the image that existed from the previous run.

I accept the 93 byte version, but your shorter one violates the conditions of the puzzle.

R, 358 328 310 298 bytes
f=function(x){H="http:";p=paste0;library(XML);a=xpathSApply(htmlParse(p(H,'//xkcd.com/',x)),'//div/img',xmlAttrs)[[1]];download.file(p(H,a[1]),'a');I=`if`(grepl('png',a[1]),png::readPNG,jpeg::readJPEG)('a');d=dim(I)/100;quartz(,d[2],d[1]);par(mar=rep(0,4));frame();rasterImage(I,0,0,1,1);cat(a[2])}

With new lines and comments:
f=function(x){
H="http:"
p=paste0
library(XML) #Needed for xpathSApply, htmlParse and xmlAttrs
# The following line find the first img element and extract its attributes
a=xpathSApply(htmlParse(p(H,'//xkcd.com/',x)),'//div/img',xmlAttrs)[[1]]
download.file(p(H,a[1]),'a') #Download to a file called 'a'
I=`if`(grepl('png',a[1]),png::readPNG,jpeg::readJPEG)('a') #Check if png or jpeg and load the file accordingly
d=dim(I)/100 #convert dimension from pixel to inches (100 ppi).
quartz(,d[2],d[1]) #open a window of the correct dimension
par(mar=rep(0,4)) #Get rid of margins
frame() #Create empty plot
rasterImage(I,0,0,1,1) #Add png/jpeg to the plot
cat(a[2]) #Print title text to stdout
}

Screenshots of test cases:
for x=1500:

for x empty:

case when picture is a jpeg:

x=859:

I wonder if it's necessary to display the image in the correct dimensions. When I was playing around with this challenge I simply did plot.new();rasterImage(...).

@Billywob Well it would be completely distorted as the default size for the plot is 7x7 inches. It's true that the OP didn't explicitely ask for the image to not be distorted but I prefer it this way :) I am however considering getting rid of the xaxs and yaxs as the result would still be proportionate.

PHP, 95 bytes
<?php echo str_replace("title=\"","/>",file_get_contents("https://xkcd.com/".$_GET["id"])); ?>

Save as main.php, run server
php -S localhost:8123

Open http://localhost:8123/main.php?id=1500

Python 2.7, 309 299 295 274 bytes
Full program. Definitely more golfable, but having read xkcd comics for so long I couldn't let this pass (who knows if this will be helpful in a future for easily browsing xkcd).
If no input is passed, gets current comic. If a valid comic number is passed as input then gets that comic. If an invalid input (not a number comic in the valid range) is passed, throws an error.
Any suggestions on how to reduce byte count are welcome! Will revisit (and add explanation) when I have more time.
-10 bytes thanks to @Dopapp
-21 bytes thanks to @Shebang
import urllib as u,re
from PIL import Image
h='http://';x='xkcd.com/'
o=u.URLopener()
t=u.urlopen(h+x+raw_input()).read()
c=sum([re.findall(r,t)for r in[h+'imgs.'+x+'c.*s/.*\.\w{1,3}','\.\w{1,3}" t.*e="(.*)" a']],[])
Image.open(o.retrieve(c[0],'1.png')[0]).show();print c[1]

You can change try:... and except:... to try:n=... and except:n='', saving you 10 bytes total

Why do you even have a try statement? The program spec says you will always get a positive integer.

@Shebang it should also return the latest comic when there is no input. I wasn't able to manage this case without carching the exception of input error.

@Joannes Why not use raw_input()? By default the user can press [Enter] and n will contain the empty string anyways. If you remove that try-except block and do t=u.urlopen(h+x+n).read() -> t=u.urlopen(h+x+raw_input()).read() you get it down to 274 bytes.

This no longer works, because xkcd image URLs use https. However, it's still valid, because it worked at the time of posting. To make it work now, change line 3 to start with h='https://' for +1 byte.

PHP, 42 bytes
<?=@file('http://xkcd.com/'.$_GET[i])[59];

Save to a file and fire it up in your web server of choice

Welcome to PPCG! I don't know PHP, but there doesn't seem to be a part of your code that's fetching the image's title text?

Wolfram Language 45 bytes ( Mathematica )
Import["https://xkcd.com/"<>#,"Images"][[2]]&

Usage with number:
%@"1500"

Usage without number:
%@""

Python 3 + Requests + PIL, 192 186 bytes
from requests import*
import PIL.Image as f
from io import*
r=get("https://xkcd.com/%s/info.0.json"%input()).json()
f.open(BytesIO(get(r["img"],stream=1).content)).show()
print(r["alt"])

Opens up an image viewer (whichever is default on the system it's being run on) containing the comic, and posts the title text to the console.

JavaScript + HTML, 124 + 18 = 142 bytes
i=>fetch(`//crossorigin.me/http://xkcd.com/${i||""}/info.0.json`).then(r=>r.json()).then(d=>(A.innerHTML=d.alt,B.src=d.img))

Cross-origin solution thanks to Kaiido's answer here.
17 bytes (//crossorigin.me/) can be saved if the proxy required to connect to xkcd.com can be subtracted (meta post about this).
Test Snippet

f=
i=>fetch(`//crossorigin.me/http://xkcd.com/${i||""}/info.0.json`).then(r=>r.json()).then(d=>(A.innerHTML=d.alt,B.src=d.img))
<input id=I> <button onclick="f(I.value)">Run</button>