Daily Challenge #33

Create a procedure that takes an array of numbers between 1 and 10 (excluding one number) and returns the missing number.

Examples

missingNum([1, 2, 3, 4, 6, 7, 8, 9, 10]) ➞ 5

missingNum([7, 2, 3, 6, 5, 9, 1, 4, 8]) ➞ 10

missingNum([10, 5, 1, 2, 4, 6, 8, 3, 9]) ➞ 7

Notes

  • The array of numbers will be unsorted (not in order).
  • Only one number will be missing.
6 Likes

I get it to work like this:

  1. Get the sum of numbers which is total = n*(n+1)/2
  2. Subtract all the numbers from sum and you will get the missing number

Pretty rough work though (Your suggestions will be really helpful to me)…

Here is demo APK and AIA:
MissingNumber.apk (4.8 MB)
MissingNumber.aia (2.8 KB)

Edit 1: Thanks @Peter for the hint :wink: (Reduced blocks from 40 to 33) Even now looks neat.

3 Likes

Do you know where the little blue gear is for in the add block? You should try that in your procedure.

2 Likes

This is my version
image

Input is a string like 1,2,3,4,5,6,8,9,10 result is 7.

6 Likes

or this:

missingNumber.aia (9.2 KB)

5 Likes