Which multiple of 5 is missing?

This file contains the multiples of 5 between 5 and 955, inclusive. One of the multiples of 5 is missing though.

Which number is missing?

Click here to open the file.

Details and assumptions

File may contain duplicate numbers.


The answer is 335.

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

The answer is 335 .

This solution uses two loops: the first creates a lookup table of the numbers in the file, and the second loop iterates through the multiples of 5 to check if they are in the lookup table. In the below python code, any multiples of 5 that are missing are printed out.

# Python code
def missing_5_multiple():
    with open('cs_missingmultiple.txt', 'r') as f:

        # create a dictionary of numbers in the file
        nums = {}
        for n in f:
            n = int(n)
            if n not in nums:
                nums[n] = 1

        answer = None
        # loop through all multiples of 5 between 5 and 955
        for n in range(5, 955 + 5, 5):
            # if n is missing, print it out
            # Note: if more than one number is missing, all missing ones will be printed
            if n not in nums:
                answer = n
                print answer

        if answer:
            print 'Missing multiple found!"
        else:
            print 'No multiples of 5 missing!'
Talha Butt
Dec 17, 2015

My solution, using python built-in sets, assumes that only one multiple of five is missing.

with open("D:\Source\multiplesoffive.txt") as f:
    sum_of_multiples = sum({int(i) for i in f.readlines()})

def triangular_number(n):
    return (n * (n + 1))/2

missing_multiple = (triangular_number(955/5) * 5) - sum_of_multiples

# Outputs 335
print missing_multiple

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...