The missing numbers

This text file contains a list of arithmetic progression with a common difference of 4 4 . At random three numbers were removed from the list excluding the beginning and end. If ( A 1 , A 2 , A 3 ) (A_{1},A_{2},A_{3}) are the three such numbers in increasing order..

A 3 ( A 2 + A 1 ) = ? A_{3}-(A_{2}+A_{1})= ?


The answer is 7589.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Bill Bell
Sep 6, 2015
1
2
3
4
5
6
7
8
terms=[3, 7, 11, ... ]

missings=[]
for i in range(-1+len(terms)):
    if terms[i+1]-terms[i]==8:
        missings.append((terms[i+1]+terms[i])/2)
A1, A2, A3=missings
print A3-(A2+A1)

Nice, short code. It is possible that the terms that were removed from the sequence were consecutive, so we should also check for cases where the difference terms[i+i] - terms[i] is 12 and 16.

Pranshu Gaba - 5 years, 9 months ago

Log in to reply

You are quite right. I was lucky. Come to think of it, that would have made a much better problem, if the three numbers had been deliberately selected so that what you suggested could have been made to happen.

Bill Bell - 5 years, 9 months ago

Log in to reply

i could have done that, but that wouldn't have made it harder only more error prone. I mostly focused on a generalized binary search to solve this problem

Beakal Tiliksew - 5 years, 9 months ago

Log in to reply

@Beakal Tiliksew I'm disinclined to argue very long about this but making people (like me) look for leaks in code is generally a good thing.

I am sorry to have given offence. I think I've contributed all of two problems myself. ;)

Bill Bell - 5 years, 9 months ago

Log in to reply

@Bill Bell i see no offense in your remarks, i fully agree with you in finding leaks in a code, which is why i think it would be preferable if the questions provided test cases.

Beakal Tiliksew - 5 years, 9 months ago

Log in to reply

@Beakal Tiliksew Naw! Let us all trip over our own feet.

Bill Bell - 5 years, 9 months ago
Aareyan Manzoor
Sep 19, 2015

very quick code and short code python:

Could be shorter:

1
leftovers = [x for x in list(range(min(ap), max(ap) + 4, 4)) if not x in ap]

Abdelhamid Saadi - 5 years, 8 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...