41
\$\begingroup\$

You will be given a string. It will contain 9 unique integers from 0-9. You must return the missing integer. The string will look like this:

123456789
 > 0

134567890
 > 2

867953120
 > 4
\$\endgroup\$
9
  • 5
    \$\begingroup\$ @riker That seems to be about finding a number missing in a sequence. This seems to be about finding a digit missing from a set. \$\endgroup\$
    – DJMcMayhem
    Mar 27, 2017 at 19:48
  • 12
    \$\begingroup\$ @Riker I wouldn't think it's a duplicate, given that the linked challenge has a strictly incrementing sequence (of potentially multi-digit numbers), whereas here it's in arbitrary order. \$\endgroup\$ Mar 27, 2017 at 19:50
  • 3
    \$\begingroup\$ Hi Josh! Since no one else has mentioned it so far, I'll direct you to the Sandbox where you can post future challenge ideas and get meaningful feedback before posting to main. That would have helped iron out any details (like STDIN/STDOUT) and resolved the duplicate dilemma before you received downvotes here. \$\endgroup\$ Mar 27, 2017 at 20:23
  • 1
    \$\begingroup\$ It's such a shame that 9-x%9 works for any digit except 0. Maybe someone more clever than me will find a way to make it work. \$\endgroup\$
    – Bijan
    Mar 28, 2017 at 0:45
  • 3
    \$\begingroup\$ Several answers take an integer as function input. Is that allowed? \$\endgroup\$
    – Dennis
    Mar 28, 2017 at 0:52

91 Answers 91

1 2 3
4
0
\$\begingroup\$

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!

\$\endgroup\$
1 2 3
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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