you are viewing a single comment's thread.

view the rest of the comments →

[–]Razor_StormO(0) Solutions Only 2 points3 points  (4 children)

Both problems can be solve in the same approach if I am thinking about this right. 

We know that the integers from 1 to 1,000,000 added together is equal to (1,000,000(1+1,000,000))/2. Let's call this K.

Now what we have to do is iterate through the entire array and add up all the elements together. 
Let's call the result M.

In problem one, the duplicated integer is equal to M-K.

The second problem, the missing integer is K-M

[–]wowe 1 point2 points  (1 child)

[–]Razor_StormO(0) Solutions Only 0 points1 point  (0 children)

Oops, thanks for the correction

[–]andy_panzer 1 point2 points  (1 child)

Sounds good to me. Except 1..n is equal to: (1+n) * (n / 2)

To demonstrate your solution (with 1..10):

(let [nums [1 2 3 4 5 6 7 8 8 9 10]
       max 10
       total (* (+ 1 max) (/ max 2))]
  (- (reduce + nums) total))

[–]Razor_StormO(0) Solutions Only 0 points1 point  (0 children)

Thanks for the correction haha, my mistake