g | x | w | all
Bytes Lang Time Link
018AWK170329T120455Zmik
031R240610T092003ZGlory2Uk
043Rust230607T185136ZJSorngar
003Thunno 2230607T172033ZThe Thon
006GolfScript230113T141145Zemirps
013x86‑64 assembly machine code230112T160139Zl4m2
005Pyt230112T005922ZKip the
255Nibbles221023T082400ZDominic
015jq R221023T033007Zpmf
017x86‑64 assembly machine code221022T223647ZKai Burg
024Factor + math.unicode221008T211745Zchunes
030Bash170328T180920Zmarcosm
nanFig221019T143652ZSeggan
022Julia 1.0221008T195533ZAshlin H
006MATL170328T134809ZSuever
005Risky210627T065220ZDLosc
053Mascarpone210628T105615ZSoup Gir
00405AB1E210201T225033ZMakonede
028Excel210323T133028ZAxuary
129CSASM v2.3210323T112022Zabsolute
nanPxem210323T083212Zuser1004
027Dash POSIX shell with POSIX utility210317T054419Zuser1004
003Vyxal210316T042129Zlyxal
017Javascript210316T031333Zl4m2
012Perl 5 p170329T112116Zmik
016BRASCA210202T091633ZSjoerdPe
005K ngn/k210202T001523Zcoltim
028Clojure210201T233122Zwintermu
023TI BASIC191212T214945ZTiKevin8
008Keg191212T063257Zlyxal
137W191212T091115Zuser8505
031Wren191212T090710Zuser8505
012Befunge 98170327T221246ZMercyBea
028TXR Lisp170330T003833ZKaz
033Google Sheets170328T074024ZGrant Mi
014J170328T182133ZkaoD
039PHP170330T144120ZTecBrat
008Noodel170329T142540Ztkellehe
009J170330T033230ZTikkanz
021C#170328T195926ZGrax32
106Racket170329T171552Zrnso
010dc170328T163339ZMitchell
015Brainfuck170328T153837ZZack C.
024Q170328T214425ZDaniel P
024D170328T212021ZGassa
064Chip170328T211255ZPhlarx
019Bash + coreutils170328T111444Zseshouma
019Bash +utilities170328T075331Zzeppelin
028Pure bash170328T194804ZDigital
016Python 2170327T200129ZRod
039AHK170328T174002ZEngineer
009Scala170328T154317Zcorvus_1
026JavaScript170328T152556ZGrax32
022JavaScript ES6170327T202315ZNeil
036REXX170328T121117Zidrougge
019Retina170327T202648ZRiley
054Java 7170328T110556ZKevin Cr
043PHP170327T203229ZJör
026JavaScript ES6170327T210041Zedc65
052Batch170327T203043ZNeil
053PHP170328T093617ZMartijn
027PHP170328T070323ZChristop
014Octave170328T031925Zrahnema1
031C tcc170328T005128ZDennis
037PHP170328T013837Zuser6395
018Cubix170328T004536ZMickyT
031C clang170328T003751ZBijan
005Pip170328T001452ZDLosc
022Python170327T235907Zxnor
014Lambdabot Haskell170327T224412ZGeneric
025Ruby170327T234757ZFlambino
047Common Lisp170327T225043Zdjeis
128Fortran 95170327T210133ZSteadybo
004APL Dyalog170327T195719ZAdá
025Mathematica170327T211807ZGreg Mar
014Ruby170327T210841ZLevel Ri
044C170327T210914ZSteadybo
021Perl 5170327T195401ZDada
006Japt170327T210104ZOliver
025QBIC170327T204014Zsteenber
003Jelly170327T201744ZDennis
023Haskell170327T201051ZLaikoni
005Brachylog 2170327T202541Zuser6213
00505AB1E170327T202321ZEmigna
022Octave170327T202209ZLuis Men
nanBrainFlak170327T195045ZWheat Wi
005Pyth170327T200125ZKarlKast
036GNU sed170327T201302ZRiley
00605AB1E170327T200830ZRiley
028Röda170327T200324Zfergusq
005CJam170327T195752ZBusiness
030PowerShell170327T195722ZAdmBorkB

AWK, 18 bytes

{$1=/0/?9-$1%9:0}1

Try it online!

Explanation: If 0 exists in the input, return 9 - modulo 9 of the input, otherwise return 0. Implicit print.

R, 31 bytes

\(S)(0:9)[!mapply(grepl,0:9,S)]

Attempt This Online!

I think it's very easy: the range 0..9 is subset by a TRUTH/FALSE vector.

Rust, 43 bytes

|s:&str|s.bytes().fold(477,|s,b|s-b as i32)

This is the same strategy as in Level River St's Ruby answer.

Attempt This Online!

Thunno 2, 3 bytes

kDḍ

Attempt This Online!

Explanation

kDḍ  # Implicit input
  ḍ  # Symmetric set difference
kD   # with the string "0123456789"
     # Implicit output

GolfScript, 6 bytes

10,`^~

Try it online!

There's a shorter, 4-byte solution if input can be taken in the form of an array of integers:

10,^

Try it online!

Explanation

10,`^~

10,     # create an array of integers from 0-9
   `    # convert it into a string
    ^   # setwise difference
      ~ # dump array onto the stack

The 4-byter just removes the need for a string because it takes input as an array and the difference doesn't include any [ characters, removing the need for the ~

x86‑64 assembly machine code, 13 B

f:      use64
6A09    push 9
59      pop rcx
6A01    push 1
5A      pop rdx
a:
AC      lodsb
30C2    xor dl, al
E2FB    loop a
92      xchg eax, edx
C3      ret

read string from [rsi] and return rax

Pyt, 5 bytes

ɳą←ą\

Try it online!

Takes input as a string (with quotes)

ɳ          push "0123456789"
 ą         convert to array of characters
  ←ą       get input string; convert to array of characters
    \      set difference; implicit print

Pyt, 5 bytes

Ś9△-~

Try it online!

Takes input without quotes

Ś        implicit input; sum of digits
 9△      45 (9th triangle number)
   -     subtract
    ~    negate; implicit print

Nibbles, 2.5 bytes (5 nibbles)

`r-_$
`r-_$
`r      # get the first integer found in
        # the string of
  - $   # remove the command-line arg 
   _    # from the string in STDIN
        # (but if there is no STDIN,
        # from all printable ASCII)

Input string is provided as a command-line argument.
If STDIN is empty, Nibbles assigns a default value of 'the list of printable ascii characters in a more useful order". The first (and only) integer present in this list after the input string is removed should be the missing digit from the input string.

enter image description here

(Note that since Nibbles will check to see if there's anything in STDIN, in the screenshot above I've pressed 'ctrl-D' to terminate STDIN with no input)

jq -R, 15 bytes

explode|477-add

Try it online!

x86‑64 assembly machine code, 17 B

input

code listing

  1                      missing_integer:
  2 00000000 6A09           push 9          ; rsp ≔ rsp − 8  rsp↑ ≔ 9
  3 00000002 59             pop rcx         ; rcx ≔ rsp↑     rsp ≔ rsp + 8
  4 00000003 31C0           xor eax, eax    ; eax ≔ 0
  5 00000005 BADD010000     mov edx, 477    ; edx ≔ 477
  6                      .digit_sum:
  7 0000000A AC             lodsb           ;  al ≔ rsi↑     rsi ≔ rsi + 1
  8 0000000B 29C2           sub edx, eax    ; edx ≔ edx − eax
  9 0000000D E2FB           loop .digit_sum ; ecx ≔ ecx − 1   ZF ≔ ecx = 0
 10                                         ; if ¬ZF then goto digit_sum
 11 0000000F 92             xchg eax, edx   ; shorter than `mov eax, edx`
 12 00000010 C3             ret

output

Factor + math.unicode, 25 24 bytes

[ "0123456789"swap ∖ ]

Try it online!

Set difference () with "0123456789".

Bash, 36 30 bytes

(fold -1;seq 0 9)|sort|uniq -u

Try it online!

Posting to get golfing tips over this.

Thanks @DigitalTrauma, big fan ;)

fold -1 writes one char of input per line

seq 0 9 writes 0..9 one per line after this.

Those lines are fed to sort and filtered by uniq -u displaying only not duplicated lines.

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

Fxcd

Try it online!

Fxcd
Fx   # Remove all elements of the input
  cd # From the string "0123456789"

Julia 1.0, 22 bytes

~x=(w='0':'9')[w.∉x]

Try it online!

MATL, 6 bytes

4Y2jX-

Try it at MATL Online

Explanation

4Y2     % Pre-defined literal for '0123456789'
j       % Grab input as a string
X-      % Compute the set difference between the two, yields the characters in 
        % '0123456789' that are missing in the input
        % Implicitly display the result

Risky, 5 bytes

+0/+/-_?}*

Input and output are integers. Try it online!

Explanation

Here's a rough diagram of the program's parse tree:

    +
    -
  0   _
 +     }
/ /   ? *

It calculates the set difference between the list of numbers 0 through 9 and the list of digits in the input (example input 134567890):

  /         5
  /+/       5+5 = 10
 0/+/       range(10) = [0,1,2,3,4,5,6,7,8,9]
       ?    input number = 134567890
         *  10
       ?}*  to-base(134567890, 10) = [1,3,4,5,6,7,8,9,0]
      _?}*  no-op
 0/+/-_?}*  diff([0,1,2,3,4,5,6,7,8,9], [1,3,4,5,6,7,8,9,0]) = [2]
+0/+/-_?}*  sum([2]) = 2

If input as a list of digits is acceptable, here's a 3-byte solution:

+0*-_?

It's the same idea, just skips the base-conversion step.

Mascarpone, 82 53 bytes

[9876543210]$v[v'$>,<]v*'#<^v'.>1#########^0123456789

Try It Online!

Explanation

[9876543210]$      // push the string '[9876543210' (we can ignore the '[')
v                  // push the current interpreter
 [      ]v*        // define an operation (under the current interpreter)
  v'$>,<           // "bind a symbol from stdin to 'Pop ToS'"
           '#<^    // bind this operation to '#' and install it to the environment
v'.>1              // push an interpreter that defaults to "Output ToS"
     #########     // bind 9 symbols from stdin to "Pop ToS"
              ^    // install this interpreter to the environment
0123456789         // one of these will output ToS, the rest will only pop
                   // the symbols to output are on the stack from line 1

05AB1E, 4 bytes

žhsм

Try it online!

žhsм  # full program
   м  # remove all characters of...
  s   # implicit input...
   м  # from...
žh    # "0123456789"
      # implicit output

s can also be I or ¹ and h can be m with no change in functionality.

Excel, 28 bytes

=SUM(45,-MID(A2,ROW(1:9),1))

CSASM v2.3, 129 bytes

func main:
lda 0
sta $1
in ""
conv ~arr:char
pop $a
push "0123456789"
.lbl a
push $a
ldelem $1
sub
inc $1
push $1
push 9
sub
brtrue a
print
ret
end

Commented and ungolfed:

func main:
    ; Initialize $1 to 0
    lda 0
    sta $1

    ; Get the input, convert it to an array of <char>s, then store it in $a
    in ""
    conv ~arr:char
    pop $a

    push "0123456789"
    .lbl loop
        ; Get the <char> in $a at index $1
        push $a
        ldelem $1

        ; Remove it from the <str> currently on the stack and push the updated <str>
        sub

        ; Increment $1 and stop looping if $1 == 9
        inc $1
        push $1
        push 9
        sub
        brtrue loop

    ; The string will now only contain the remaining digit.  Print it
    print
    ret
end

Pxem, Filename: 28 bytes + Content: 0 bytes = 28 bytes.

Try it online! (with pxem.posixism)

With comments

XX.z
# push 9; heap=pop
.a\011.tXX.z
# while empty || pop!=0; do
.a.wXX.z
  # push 48; push getchar
  .a0.iXX.z
  # push abs(pop-pop); if size>=2; then push pop+pop; fi
  .a.-.+XX.z
  # push heap; push 1; push abs(pop-pop)
  .a.m\001.-XX.z
  # dup; heap=pop
  .a.c.tXX.z
# done
.a.aXX.z
# push 48; push abs(pop-pop); printf "%d", pop
.a\055.-.n

Dash (POSIX shell with POSIX utility ), 50 47 27 bytes

$((1${1%0*}-1$1?9-9$1%9:0))

Try it online!

The code above evaluates to a string of digit.

Alternative

$((1${1#*0}-1$1?9-9$1%9:0))

How it works

Vyxal, 3 bytes

kd⊍

Try it Online!

Imagine not having set operations.

Explained

kd⊍
kd    # "0123456789"
  ⊍   # set(↑) ^ set(input)

Javascript, 18 17 bytes

-1B from tsh

s=>9-('0x9'+s)%15

F=
s=>9-('0x9'+s)%15
;
console.log(F('135792048'))

Perl 5 -p, 12 bytes

$_=-hex()%15

Try it online!

Explanation:

Interprets input as hex string, negates it, and calculates modulo 15 (based on xnor's Python answer).

BRASCA, 16 bytes

477SSm8[a+A{]x-n

Try it online!

Explanation

<implicit input>     - Push STDIN to stack
477SSm               - Push 477 (the sum of all digits' ASCII codes) to the bottom
      8[    ]        - Loop 9 times:
        a+A          -   Put loop counter in register, add the top two digits, then take it back out.
           {         -   Decrement the loop counter
             x-      - Remove the loop counter, then subtract the sum of all digits from 477
               n     - Output the result as a number

K (ngn/k), 5 bytes

477-/

Try it online!

Subtracts the ASCII character codes of the input string from 477.

Clojure, 28 bytes

#(- 477(apply +(map int %)))

TI BASIC, 23 bytes

45-sum(seq(expr(sub(Ans,I,1)),I,1,9

Turns the input string in Ans into a list containg the digits and then sums the list so that the number can be derived from subtracting the sum from 45. The byte count is affected by the 2 byte tokens expr(, sub(, and Str1. A full program could prompt for Str1 for 5 additional bytes.

Keg, 14 8 bytes

?⅀ȍ$-

Try it online! -6 bytes thanks to @A̲̲

Answer History

14 bytes

`0123456789`᠀-

Try it online!

W, 13 7 bytes

'0'9.St

Explanation

'0'9.   % Define the range of string 0 to 9
     S  % Swap so that instructions are in the right order
        % a[0], "0...9" -> "0...9", a[0]
      t % Trim out everything in 0...9 that appears in a[0]
        % The result is the remaining number

W, 8 bytes

CJ525S-C

Explanation

C         % Convert every character to its code point form
 J        % Sum the list
  525S-   % Minus 525 from the value
       C  % Convert to character form
          % Implicit output

Wren, 31 bytes

Fn.new{|x|"0123456789".trim(x)}

Try it online!

Explanation

Fn.new{|x|                      // New anonymous function with parameter x
          "0123456789"          // Declare all the numbers
                      .trim(x)  // Trim out everything included in x
                              } // The remaining number is the result

Befunge 98, 14 12 bytes

I saved 1 byte by moving the program onto 1 line and 1 byte by doing some better math

~+;@.%a--7;#

Try it online!

Explanation

The sum of the ASCII values range from 477 to 468 depending on which number is missing. By subtracting this from 7, we get the range -470 to -461. By modding this number by 10, we get the range 0 - 9, which we can then print.

~+;       ;#    Sums the ASCII values of all characters to stdIn
~          #    The # doesn't skip over the ~ because it's on the end of a line
~               Once EOF is hit, the ~ reverses the IP's direction
          ;#    Jump the ; that was used before
       --7      Subtract the sum from 7 (really just 0 - (sum - 7))
     %a         Mod it by 10
   @.           Print and exit

The reason I use the ASCII values instead of taking integer input is because the & command in Try it Online halts on EOF (Even though it should reverse the IP). The ~ works correctly, though.

Old Program, 14 bytes

#v~+
@>'i5*--,

The sum of the ASCII values of all 10 digits is 525. By subtracting the sum of the given digits from 525, we get the ASCII value of the missing character.

#v~+         Sums the ASCII values of all characters on stdIn
             Moves to the next line when this is done
 >'i5*       Pushes 525 (105 * 5)
      --     Subtracts the sum from 525
@       ,    Prints and exits

TXR Lisp, 28 bytes:

This is 28 bytes. It reads a line of digits and yields a string of the missing ones as the result value;

(diff"0123456789"(get-line))

This uses the awk macro to do read every line of input and print the missing digits. It only adds one byte to the length:

(awk((mf(diff"0123456789"))))

At the system prompt:

$ txr -P '(diff"0123456789"(get-line))'
135249
0678

$ txr -e '(awk((mf(diff"0123456789"))))'
123456789
0
234567890
1
012357698
4
13579
02468
^D

Google Sheets, 39 33 bytes

Input is entered into cell A1.

Code:

=REGEXEXTRACT(4&2^29,"[^"&A1&"]")

Saved 6 bytes thanks to Steve Kass.

Previous Code:

=REGEXEXTRACT("0123456789","[^"&A1&"]")

Result:

enter image description here

J, 14 bytes

((i.10)-."."0)

Try it online!

J is always surprisingly inadequate for golfing :(

(                )  NB. Monadic fork: (f g h) x = (f x) g (h x)
  (i.10)            NB. Array of integers from 0 to 9
            "."0    NB. Digits of string (". = evaluate, "0 = each atom)
         -.         NB. Except

PHP, 50 39 Bytes

function x($y){echo(45-array_sum(str_split($y)));}

Jörg Hülsermann's answer prompted me to try the CLI method, Thanks.

echo 45-array_sum(str_split($argv[1]));

Test it at the command line with:

php -r 'echo 45-array_sum(str_split($argv[1]))."\n";' /'12346789'

Test it (The old version) here if you'd like.

Wheat Wizard's answer put me in the right direction and I got help from This Answer

Noodel, 8 bytes

ɲdFḶṡạĖ⁻

Try it:)


How it works

ɲdFḶṡạĖ⁻
         # Input implicitly pushed onto the stack.
ɲd       # Pushes the string "0123456789" onto the stack.

  FḶṡạĖ⁻ # Loops nine times removing digits from the string "0123456789" producing the missing number.
  F      # Pushes the string "F" onto the stack.
   Ḷ     # Consumes the string "F" and converts to a base 98 number producing 9 then loops the following that many times.
    ṡ    # Swaps the string "0123456789" with the input on the stack.
     ạ   # Gets the ith element from the input and pushes it onto the top of the stack.
      Ė  # Grabs the string "0123456789" at the bottom of the stack and puts it at the top.
       ⁻ # Removes the element pulled out of the input from the string.
         # Implicit end of the loop.

         # Implicit push to the screen, outputting the missing digit.

J, 9 bytes

Num_j_&-.

Try it online!

C#, 21 bytes

z=>45-z.Sum(v=>v-'0')

The expression v-'0' takes the char value such as '3' and subtracts the char value for '0', leaving the value 3, essentially converting the character 3 into the integer 3.

45 is the sum of all the numbers 0 through 9. 45 - the sum of the passed-in integers yields the missing integer.

Sample code

public static void Main()
{
    Func<string, int> X = z=>45-z.Sum(v=>v-'0');
    
    Console.WriteLine(X("123456789"));
    Console.WriteLine(X("134567890"));
    Console.WriteLine(X("867953120"));
}

Test Here: https://dotnetfiddle.net/yanR5S

Racket 106 bytes:

(filter-not(λ(x)(member x(string->list(number->string n))))
(for/list((i(range 48 58)))(integer->char i)))

Ungolfed:

(define (f n)
  (filter-not
   (λ(x)
     (member x
             (string->list
              (number->string n))))
   (for/list((i(range 48 58)))(integer->char i))))

Testing:

(f 867953120)

Output:

'(#\4)

dc, 12 10 bytes

Cdi?B%-B%p

Try the dc version online!

This uses the fact that the sum of the digits from 0 to 9 is 45, which is 1 more than a multiple of 11.

The program works by viewing the input as a base 12 number, finding its remainder when divided by 11, and subtracting that from 12 (to find the missing digit). The only catch is that if 0 or 1 is the missing digit, this would give an answer of 11 or 12, respectively, so I mod out by 11 one additional time at the end to take care of those cases.


This yields a short bash solution also:

Bash + Unix utilities, 17 15 bytes

dc -eCdi?B%-B%p

Try the bash version online!

Brainfuck, 17 15 bytes

-[-[->-<],]>++.

Try it out here. This solution works on standard Brainfuck (8-bit cells) only, as it relies on wrapping.

It's a rare day when Brainfuck can actually compete, but this challenge just happened to line up with the BF spec pretty well!

Instead of straight-up breaking down this answer, I'd like to step through the iterations I took, because I think it would be more understandable (and more interesting).
Note: this solution is inspired largely by Wheat Wizard's Brain-Flak answer.

Explanation

Step 1, 26 bytes

In his answer, Wheat Wizard pointed out that the sum of the ASCII values from 0-9 sum to 525. And since standard Brainfuck only has a notion of [0,255], this makes the value 525 % 256 = 13. That is to say, subtracting the ASCII values of the input from 13 nets you the missing digit.

The first version of this program was:
1. Put 13 in the first cell
2. Take inputs into the second cell
3. Subtract the second cell from the first cell
4. Jump to 2 if there are inputs remaining
5. Print the first cell

And here's the code for the simple solution:

+++++++++++++ #Set the first cell to 13  
>,            #Take inputs into the second cell  
[[<->-],]     #Subtract the second cell from the first cell and repeat until inputs are over  
<.            #Print the first cell  

Step 2, 19 bytes

As pointed out in his answer, since we know the input will be exactly length 9, we can use that value as a constant, and eliminate that long string of +'s right at the beginning.
It also doesn't matter at what point we add 13 (thanks, commutative property!), so we'll mix it in with the subtraction and printing steps.

,        #Take input to enter the loop
[[->-<], #Subtract the first cell from the second cell 
>+<]     #Add 1 for each input; totaling 9
>++++    #Add the missing 4 to make 13
.        #And print

This was my original answer to this problem, but we can do better.

Step 3, 17 bytes

Interestingly enough, the previous answer works even if we begin with a + instead of a ,

+[[->-<],>+<]>++++.

Brainfuck required something in a cell in order to begin a loop. We naively added that extra 4 in the end, when it could have gone in other places.

-[[->-<],>+<]>++.

With some totally intentional (read: trial and error) loop trickery, starting off the program with a - leads to two interesting results:

  1. One gets added to the second cell (saving 1 byte at the end).
  2. The loops runs one extra time, totaling 10 instead of 9 (saving another 1 byte).

1 + 10 + 2 = 13, and we end up with the original answer.

Looking back on it, this is probably an excessive write-up for such a simple Brainfuck program.

Step 4, 15 bytes

After thinking about this solution a bit more, I was able to cut off 2 bytes.

I wanted to clarify something about the previous step:
The minus to enter the loop effectively adds 1, but what it's actually doing is subtracting 255 from the second cell (resulting in 1).

It's obvious in retrospect, but subtracting 1 from the first cell is the same as adding 1 to the second cell (because everything in the first cell gets subtracted from the second cell.)

-[-[->-<],]>++.

I was able to remove the ">+<" by adding a "-" at the beginning of the first loop. It has to go there, and not where the ">+<" was, because the program will loop infinitely otherwise.

Q, 24 bytes

{1#iasc"0123456789"in x}

Gets a boolean vector between the expectation and input, then sorts the indices of the expectation by that boolean vector in ascending order, first value always being the missing element since boolean for it is set to 0 and we know that value=index in this case.

D, 24 bytes

writeln(477-readln.sum);

Just add up all characters in the given string (not terminated by a newline). The sum is s = 48 * 9 + (0 + 1 + 2 + ... + 9 - x) = 477 - x, therefore, x = 477 - s.

The calls make use of optional parentheses (-4 bytes), and .sum invocation uses uniform function call syntax (-1 more byte).

Try it online!

Chip, 64 bytes

Azv~a
##'Bzv~b
`^v##'Czv~c
*f|`^-##'Dzv~d
Z~'~e `^-##'
ZZZZZZZ~S

Try it online!

Chip is a 2D language that operates on individual bits in a byte stream. Each byte of input is broken down into its component bits for computation, then stitched back together for output.

This solution uses a rather simple algorithm, that is only a minor twist on that used by many of the other solutions:

  1. Start with a value of 0x2:

     0+1+2+3+4+5+6+7+8+9 =  45 (0x2D)
                     ~45 = -46 (0xD2)    *
              -46 & 0x0F =   2  (0x2)
    

    * I only do half of two's complement negation; I skip the increment at the end for a reason. I'll get back to this.

  2. Add each code point in the string, masked with 0x0F, ignoring carries.

  3. After the ninth addition, the current value will be equal to -1 minus the missing digit, masked with 0x0F:

    Let's say we were missing the digit '4':

                  -1 - 4 =  -5  (0xB)
                   ~(-5) =   4  (0x4)    *
    

    * Again, we only do half of negation. This instance cancels out the offset introduced by the previous negation.

  4. Prefix the value with 0x3, giving the codepoint for the missing digit:

              0x30 | 0x4 =  52 (0x34)
    

What portions of the code do each bit? Well, they're a bit mixed together, but I'll try to cover the highlights:

Bash + coreutils, 19 bytes

I found a shorter bash solution, that uses an interesting checksum approach:

sum -s|dc -e524?--P

Try it online!

Explanation:

The sum command prints a checksum and a block count. I don't know many details, but using the option -s (System V algorithm) will make the checksum equal to the ASCII sum of each input character code. As such, the checksum remains constant when the order of the same input characters changes.

Given 867953120 as test case (last example), here is how the script works:

Bash (+utilities), 22, 19 bytes

seq 0 9|tr -d \\n$1 

Test

$seq 0 9|tr -d \\n123456789
0

Try It Online!

Pure bash, 28

a=1234567890
echo ${a//[$1]}

Try it online.

Python 2, 18 16 bytes

+beauty thanks to @Sarge Borsch

`99066**2`.strip

Try it online!

99066**2 is just a shorter way to generate a string that contains 0~9

AHK, 39 bytes

i=[%1%]
Send % RegExReplace(99066**2,i)

Again, the inherent confusion between the input variable 1 and the actual number 1 causes confusion in AHK functions. At least it only cost 3 bytes this time.

99066**2 = 99066^2 = 9814072356 (a trick I copied from Rod's answer)

Scala, 9 bytes

477-_.sum

To use it, assign it to a variable:

val f:(String=>Int)=477-_.sum

_ is syntactix sugar for the arguments of a function, so this expands to x => 477 - x.sum, which will subtract the sum of the ascii codes of the input from 477.

JavaScript, 26 bytes

v=>45-eval([...v].join`+`)

I'm not a big fan of eval, but it does the job. The sum of all digits 0-9 is 45. 45 minus the sum of the passed-in digits is the value of the missing digit.

Test

f=v=>45-eval([...v].join`+`)


function test() {

  var i=I.value;
  O.textContent = f(i)
}  

test()
<input oninput='test()' value='012987654' id=I>
<pre id=O></pre>

JavaScript (ES6), 31 29 28 22 bytes

s=>(15-`0x${s}`%15)%15

Port of @xnor's Python answer, except that JavaScript only has a remainder operator rather than a modulo operator, so I can't do it in a single step. Edit: Saved 6 bytes thanks to @Arnauld.

REXX, 36 bytes

#=0123456789
arg n
say verify(#,n)-1

Retina, 27 21 19 bytes

-6 Thanks to Basic Sunset
-2 Thanks to Martin Ender

.
$*_5$*
+`_1|1_

1

Try it online!

Replace every digit with that many _s and 5 1s:

.
$*_5$*

Remove all of the _s and a 1 for each:

+`_1|1_ 


Count the number of 1s left:

1

Java 7, 61 54 bytes

long d(int n){return(15-Long.valueOf(n+"",16)%15)%15;}

Based on @Neil's JavaScript (ES6) answer (just like JavaScript, Java uses remainder for negative-modulo. Original port is from @xnor's Python answer)

Old answer (61 bytes):

String c(int n){return"0123456789".replaceAll("["+n+"]","");}

Try it here.

PHP, 43 Bytes

for(;strpos(_.$argv[1],48+$i++););echo$i-1;

PHP, 50 Bytes

<?=join(preg_grep("#[{$argv[1]}]#",range(0,9),1));

JavaScript (ES6), 26

Edit 1 byte save thx @Neil, with a much more smarter trick

Xoring all the values from 1 to 9 gives 1. Xor 1 one more time and the result is 0. So, if any single value is missing, the result will be the missing value.

s=>eval([1,...s].join`^`)

Test

f=s=>eval([1,...s].join`^`)

function go() {

  var i=I.value;
  O.textContent = f(i)
}  

go()
<input oninput='go()' value='012987653' id=I>
<pre id=O></pre>

Batch, 83 76 52 bytes

@set/pn=
@cmd/cset/a(641670-0x%n:~,4%-0x%n:~4%)%%15

Takes input on STDIN. Uses @xnor's hex modulo 15 trick, except that a) Batch only has 32-bit integers, so I have to split the string into two b) Batch only does remainder, not modulo, so I have to subtrat the values from a large multiple of 15 first.

PHP, 53 bytes

There allready was a array_sum and regex solution, wanted to provide another:

print_r(array_diff(range(0,9),str_split($argvs[1])));

A few bytes more, but as bonus it will provide all missing numbers.

PHP, 27

<?=trim(32043**2,$argv[1]);

uses the trick from Rod's answer to generate a string containing all digits then removes all digits except for the missing one.


PHP, 41

for($b=1;$i<9;$b^=$argv[1][$i++]);echo$b;

This one uses xor because I haven't seen it yet.

Octave, 20 19 14 bytes

@(a)477-a*~~a'

Try it online!

Developed independently but the same as some other answers.

a'          transpose of array `a`
~~a'        convert all elements of a' to 1
a*~~a'      matrix multiplication of `a` with a column vector of 1s
            that is equivalent to sum(a)
477-a*~~a'  subtract from [477=sum('0123456789')-48]

C (tcc), 36 31 bytes

f(long*s){s=9-(*s+s[1]%16)%15;}

Takes a string as input and returns an int. As written, this work only on little-endian architectures.

The lack of a return statement is undefined behavior, but this works with tcc and gcc.

Try it online!

Alternate version, 33 bytes, no UB

f(long*s){*s=57-(*s+s[1]%16)%15;}

Takes a string pointer as input and overwrites the string with the result (allowed by default).

While this is perfectly valid C, it will not work with compilers such as gcc, which store strings in read-only memory sections.

Try it online!

PHP, 37 bytes

<?=45-array_sum(str_split($argv[1]));

Cubix, 18 Bytes

5v&;52/ni?@.>!&oW+

Expanded

    5 v
    & ;
5 2 / n i ? @ .
> ! & o W + . .
    . .
    . .

Try it here

Uses the same sort of method as this brain-flak answer.

Create the value -525 on the stack by pushing 5, 2, concatenate, push 5, concatenate and negate.
Then repeatably get input and add until end of input is hit.
Remove the last input, negate(make positive) the last add result, output the character and halt.

The reason for working from -525 up is that the character output is hit for each input iteration. Since the value is negative, nothing is output until the loop is exited and the negative value is made positive.

C (clang), 31 bytes

f(x){return x?f(x/10)-x%10:45;}

Strictly speaking, f(x) returns the sum of the missing digits. This lets me knock off a digit, get the sum of the missing digits, then add it back on.

Try it online!

Pip, 5 bytes

5 bytes seems to be the number for all golfing languages that aren't Jelly.

,tDCa

Takes input as a command-line argument. Try it online!

Explanation

,t     Range(10)
  DC   From each element, delete all characters...
    a  ...that are in 1st cmdline arg
       Concatenate and print (implicit)

The result is actually a list like ["";"";"";"";4;"";"";"";"";""] (which is what you get if you put RP at the front of the code). Lists by default are concatenated together before printing, so all you will see is 4.

Python, 22 bytes

lambda s:-int(s,16)%15

Try it online!

An arithmetic solution. Interprets the input string as hex, negates it, and takes the result modulo 15.

Lambdabot Haskell, 14 bytes

(['0'..'9']\\)

After realizing I could just make a list with the String "0123456789" instead of the integers [0,1,2,3,4,5,6,7,8,9], the step for converting the string to integers could be skipped.

Type is now String -> String (takes a string and returns a string with the correct number). Call like:

(['0'..'9']\\)"149263708"         -- Outputs "5"

Previous:

([0..9]\\).map digitToInt

Uses set difference, unlike the other Haskell answer, type String -> Int

Call like

([0..9]\\).map digitToInt$"123467890"  -- Outputs 5

Ruby, 25 bytes

->x{'0123456789'.tr x,''}

Not terribly competitive, I'm afraid

Common Lisp, 47 bytes

(lambda(s)(- 45(reduce'+ s :key'digit-char-p)))

Ungolfed:

(lambda (s) (- 45 (reduce '+ s :key 'digit-char-p)))

Explaination:

(reduce '+ s :key 'digit-char-p)

This loops through the chars in s, converts them to digits, and adds them. Digit-char-p, conveniently, return the number of the char as its "true" value, so it can be used as a test or a conversion.

(- 45 ...)

Subtract from 45 gives back the digit that was missing from the input.

Fortran 95, 146 128 bytes

function m(s)
character(len=10)::s,t
t='0123456789'
do j=1,10
k=0
do i=1,9
if(s(i:i)==t(j:j))k=1
end do
if(k==0)m=j-1
end do
end

Not very short, I'm afraid.

Ungolfed:

integer function m(s)
    implicit none

    character(len=9)::s
    character(len=10)::t
    integer:: i, j, k

    t='0123456789'
    do j=1,10
        k=0
        do i=1,9
            if (s(i:i) == t(j:j)) k=1
        end do
        if (k==0) m=j-1
    end do

end function m

APL (Dyalog), 4 bytes

Derived function

⎕D∘~

⎕DDigits

 (ties a left argument to the following dyadic function to create a monadic function)

~ except [the argument]

Try it online!


Function train

⎕D~⊢

⎕DDigits

~ except

 the right argument

Try it online!


Explicit program

⎕D~⍞

⎕DDigits

~ except

 character input

Try it online!

Mathematica, 25 bytes

477-Tr@ToCharacterCode@#&

Pure function taking a string as input and returning an integer. Mathematica has long command names and is reluctant to convert between strings and integers, which makes it particularly bad at this challenge. The best I could find was the algorithm from Level River St's Ruby answer, which does a computation based on the total of the ASCII codes of the input string; in Mathematica, this uses only one long command name.

Ruby, 14

Sums the ascii codes and subtracts from 48*9+45

->s{477-s.sum}

Use like this

f=->s{477-s.sum}

puts f["123456789"]

C, 44 bytes

j;f(char*s){for(j=477;*s;)j-=*s++;return j;}

Try it online!

Perl 5, 21 bytes

20 bytes of code + -p flag.

s/./+$&/g;$_=45-eval

Try it online!
Note that the input needs to be supplied without final newline (with echo -n for instance).


Some other (longer) approaches (all with -p flag):

$\=45;$\-=$_ for/./g}{

$_=9876543210=~s/[$_]//gr

for$@(0..9){$\=$@if!/$@/}}{

Japt, 6 bytes

¬x n45

Try it online!

Explanation:

¬x n45
   n45     // 45-
¬          //    Split the input into an array "123" → ["1","2","3"]
 x         //    Return the sum of all the items ["1","2","3"] → 6
           // 45 - 6 = output

QBIC, 25 bytes

;{~instr(A,!a$)|a=a+1\_Xa

Explanation

;       Get the input as A$
{       Start an infinite DO loop
~instr  Test if A$ has an occurrence of a% cast to string       
(A,!a$) a starts out as 0. !..$ casts to string.
|a=a+1  If we did find an instance, tets for the next a
\_Xa    Else, quit, printing our missing number.

Jelly, 3 bytes

ØDḟ

Simply filters () the input string from “0123456789” (ØD).

Try it online!

Haskell, 24 23 bytes

(477-).sum.map fromEnum

Try it online! Usage: (477-).sum.map fromEnum $ "123456890". 477 is the sum of the character codes of the digits 1 to 9, excluding 0. This anonymous function computes 477 minus the sum of all digit character codes to find the missing one.

Turning the char digits to ints is one byte longer:

(45-).sum.map(read.pure)
foldl(\a b->a-read[b])45

Try it online!

Brachylog (2), 5 bytes

ẹ:Ị↔x

Try it online!

Arguably should be shorter (I'm still confused as to why the is necessary), but this is the best I could do.

Explanation

ẹ:Ị↔x
ẹ      Split the input into a list of characters
 :Ị    Pair that list with the string "0123456789"
   ↔x  Remove all elements of the list from the string

05AB1E, 5 bytes

žhISK

Try it online!

Explanation

žh     # from the string "0123456789"
    K  # remove
  IS   # each digit of the input

Octave, 22 bytes

@(x)setdiff('0':'9',x)

Try it online!

Brain-Flak, 48 38 36 + 3 = 39 bytes

10 bytes saved thanks to DJMcMayhem!

((([]())[]{}){()()({}[()])}{}[{{}}])

Try it online!

Explanation

The sum of all the digits in Ascii is 525. This program sums up the input and subtracts it from 525 to get the missing digit.

((([]())[]{}){()()({}[()])}{}      )

Will push 525. This takes advantage of the fact that we know there will be 9 elements of input to begin with. This means that [] evaluates to 9 which allows us to get to large numbers like 525 quickly.

Next we have the bit:

                             [{{}}]

which will sum up the inputs and subtract it from the total.

Pyth, 5 Bytes

-jkUT

try it!

explanation

-jkUT
    T   # 10
   U    # The unary range of ten: [0,1,..,9]
 jk     # join that on the empty string
-       # set minus

"-jUT" also kinda works but produces newlines for every int.

GNU sed, 36 bytes

Includes +1 for -r

s/$/0123456789/
:
s/(.)(.*)\1/\2/
t

Try it online!

s/$/0123456789/ # Append 0123456789
:               # Start loop
s/(.)(.*)\1/\2/ # remove a duplicate character
t               # loop if something changed

05AB1E, 6 bytes

45¹SO-

Try it online!

45     # Push 45
  ¹    # push input
   S   # Split
    O  # Sum
     - # Subtract (45 - sum)

Röda, 28 bytes

{(_/"")|ord _|sum|chr 525-_}

Try it online!

CJam, 5 bytes

A,sq-

Try it online!

A,     e# The range from 0 to 9: [0 1 2 3 4 5 6 7 8 9]
  s    e# Cast to a string: "0123456789"
   q   e# The input
    -  e# Remove all characters from the range that are in the input
       e# Implicit output

PowerShell, 30 bytes

param($n)0..9|?{$n-notmatch$_}

Try it online!

Takes input $n, constructs a range 0..9 (i.e., 0, 1, 2 ... 9), then uses a Where-Object clause (the |?{...}) to pull out the number that does regex -notmatch. That's left on the pipeline, output is implicit.