Forensic Technology FB

In Forensic Technology complex problem solving is a large part of our day-to-day work.

Paying homage to our fondness of brain-teasers, we’re launching a monthly Forensic Technology Challenge - a new series of logical, analytical and coding problems that put into practice the STEM, finance and technology skills essential to our work.

Every month we’ll post a new challenge created by the Forensic Technology team, focusing on one of these skills. You can solve these problems in any way that you want. We’re looking forward to seeing the different ways that you approach them!

Without further ado, here is the first challenge straight from the Forensic Technology hive-mind:

Of the first 2016 prime numbers, which ones have digits that sum to 13?

Our solution involved creating a Python script to do all of the heavy-lifting, but this is only one tactic. What was your method?

We’ll be posting how we solved this next month, along with Challenge #2. Don't forget to look out for our bonus question next week!

If you are someone who enjoys problem-solving, logical thinking and technology, check out our Forensic Technology graduate professional roles to see if they are the right fit.

What's the answer?

Here’s what you’ve been waiting for, the solutions to the first #4TechChallenge posted last month as well as the answer to the bonus question.


So without further ado here is the Python script we used to generate the list of primes and subsequently find how many had their digits sum to a specified total. (Note we used Python 3.5.1.)

FT-Challenge1-Answer800x562

 

Of the first 2016 prime numbers, 141 have their digits sum to 13. Here is the complete list of them:

 

FT-Challenge1-Answer2800x327

 

If you've enjoyed this quiz, have a go at the Bonus Question and keep an eye on the blog for more quizzes to come.

 

 

Comments

  • Def is_prime(num)
    If num== 0 or num==1: return false
    For x in range(2,num):
    If num % x == 0:
    Return false
    Else:
    Return true
    Filter(is_prime,[I for I in xrange(2016) if sum([int(x) for x in str(I)])==13])

    Posted by: Mr robot on 11/07/2016

  • The previous comment is a good start, but it's worth pointing out that you don't want an if/else statement when checking if num is prime, because it will terminate and return True as soon as it finds an x that does not divide it. e.g. is_prime(9) will return True because 9%2=1. You want the "return True" line after the for loop to give it a chance to try all possible factors (but still keep the "if num%x==0" line).

    Below is a possibly rather verbose Python script, which allows the user to choose how many prime numbers to check and what they want the digits to sum to. Of course, in this case, we could just set them to 2016 and 13, respectively, in the code.

    https://github.com/rhjohnstone/random/blob/master/deloitte_primes.py

    Posted by: Ross Johnstone on 12/07/2016

  • Mine is longer, but more customizable and uses a slightly quicker check for the primes - just something I quickly threw together. If I have time I may steal your code and make a more efficient one, only checking the already existing list of primes. Haven't used python in ages, so not brilliantly written...

    import math
    z = 0
    while z in range(99999):
    top = int(input("\nHow many primes do you wish to check? "))
    digital = int(input("What digital sum are you looking for? "))
    num = int(input("What is your first number? "))
    primes = []
    x = 0
    print("Calculating...")
    while len(primes) != top :
    for i in range(2,(int((math.sqrt(num)))) + 1):
    if (num % i) == 0:
    x = 1
    break
    if x == 0:
    primes.append(num)
    num = num + 1
    x = 0
    for x in range(0, (top - 1), 1):
    number = primes[x]
    result = sum(int(digit) for digit in str(number))
    if result == digital:
    print("Prime = ", number, "Digital sum = ", result)

    Posted by: Daniel on 12/07/2016

  • Hi Mr Robot, thanks for your post! Your solution looks good -- but make sure you are looking through the first 2016 prime numbers rather than the primes up to 2016.
    Look out for our bonus question next week!

    Posted by: Josh Murray (Deloitte) on 12/07/2016

  • Also, your method only find the primes up to the interger 2016 (if I am correctly understanding your code). The question seemed to be asking for a list of 2016 prime numbers, and then for you to check that list for ones where the digits summed to 13. As I said before, I haven't used python in ages, so I may be misreading your code.

    Posted by: Daniel on 13/07/2016

  • Hi Daniel, thanks for your answer! Using your code as a base, can you also find the total number of first 2016 prime numbers which have digits that sum to 13?
    As you suggested, the question is asking for the first 2016 prime numbers, rather than the prime numbers up to integer 2016, that have digits that sum to 13.
    Hope you enjoyed the challenge!

    Posted by: Josh Murray (Deloitte) on 18/07/2016

  • New program output:

    ========== RESTART: C:\Users\Daniel\Documents\Python\Find primes.py ==========

    How many primes do you wish to check? 2016
    What digital sum are you looking for? 13
    What is your first number? 1
    Calculating...
    Prime = 67 Digital sum = 13
    Prime = 139 Digital sum = 13
    Prime = 157 Digital sum = 13
    Prime = 193 Digital sum = 13
    Prime = 229 Digital sum = 13
    Prime = 283 Digital sum = 13
    Prime = 337 Digital sum = 13
    Prime = 373 Digital sum = 13
    Prime = 409 Digital sum = 13
    Prime = 463 Digital sum = 13
    Prime = 571 Digital sum = 13
    Prime = 607 Digital sum = 13
    Prime = 643 Digital sum = 13
    Prime = 661 Digital sum = 13
    Prime = 733 Digital sum = 13
    Prime = 751 Digital sum = 13
    Prime = 823 Digital sum = 13
    Prime = 1039 Digital sum = 13
    Prime = 1093 Digital sum = 13
    Prime = 1129 Digital sum = 13
    Prime = 1237 Digital sum = 13
    Prime = 1291 Digital sum = 13
    Prime = 1327 Digital sum = 13
    Prime = 1381 Digital sum = 13
    Prime = 1453 Digital sum = 13
    Prime = 1471 Digital sum = 13
    Prime = 1543 Digital sum = 13
    Prime = 1723 Digital sum = 13
    Prime = 1741 Digital sum = 13
    Prime = 1831 Digital sum = 13
    Prime = 2029 Digital sum = 13
    Prime = 2083 Digital sum = 13
    Prime = 2137 Digital sum = 13
    Prime = 2281 Digital sum = 13
    Prime = 2371 Digital sum = 13
    Prime = 2551 Digital sum = 13
    Prime = 2713 Digital sum = 13
    Prime = 2731 Digital sum = 13
    Prime = 2803 Digital sum = 13
    Prime = 3019 Digital sum = 13
    Prime = 3037 Digital sum = 13
    Prime = 3109 Digital sum = 13
    Prime = 3163 Digital sum = 13
    Prime = 3181 Digital sum = 13
    Prime = 3217 Digital sum = 13
    Prime = 3253 Digital sum = 13
    Prime = 3271 Digital sum = 13
    Prime = 3307 Digital sum = 13
    Prime = 3343 Digital sum = 13
    Prime = 3361 Digital sum = 13
    Prime = 3433 Digital sum = 13
    Prime = 3541 Digital sum = 13
    Prime = 3613 Digital sum = 13
    Prime = 3631 Digital sum = 13
    Prime = 4027 Digital sum = 13
    Prime = 4153 Digital sum = 13
    Prime = 4243 Digital sum = 13
    Prime = 4261 Digital sum = 13
    Prime = 4423 Digital sum = 13
    Prime = 4441 Digital sum = 13
    Prime = 4513 Digital sum = 13
    Prime = 4603 Digital sum = 13
    Prime = 4621 Digital sum = 13
    Prime = 4801 Digital sum = 13
    Prime = 5107 Digital sum = 13
    Prime = 5233 Digital sum = 13
    Prime = 5323 Digital sum = 13
    Prime = 5413 Digital sum = 13
    Prime = 5431 Digital sum = 13
    Prime = 5503 Digital sum = 13
    Prime = 5521 Digital sum = 13
    Prime = 5701 Digital sum = 13
    Prime = 6007 Digital sum = 13
    Prime = 6043 Digital sum = 13
    Prime = 6133 Digital sum = 13
    Prime = 6151 Digital sum = 13
    Prime = 6421 Digital sum = 13
    Prime = 7213 Digital sum = 13
    Prime = 7321 Digital sum = 13
    Prime = 7411 Digital sum = 13
    Prime = 8221 Digital sum = 13
    Prime = 8311 Digital sum = 13
    Prime = 9013 Digital sum = 13
    Prime = 9103 Digital sum = 13
    Prime = 10039 Digital sum = 13
    Prime = 10093 Digital sum = 13
    Prime = 10273 Digital sum = 13
    Prime = 10453 Digital sum = 13
    Prime = 10651 Digital sum = 13
    Prime = 10723 Digital sum = 13
    Prime = 10831 Digital sum = 13
    Prime = 10903 Digital sum = 13
    Prime = 11047 Digital sum = 13
    Prime = 11083 Digital sum = 13
    Prime = 11119 Digital sum = 13
    Prime = 11173 Digital sum = 13
    Prime = 11317 Digital sum = 13
    Prime = 11353 Digital sum = 13
    Prime = 11443 Digital sum = 13
    Prime = 11551 Digital sum = 13
    Prime = 11731 Digital sum = 13
    Prime = 11821 Digital sum = 13
    Prime = 12037 Digital sum = 13
    Prime = 12073 Digital sum = 13
    Prime = 12109 Digital sum = 13
    Prime = 12163 Digital sum = 13
    Prime = 12253 Digital sum = 13
    Prime = 12343 Digital sum = 13
    Prime = 12433 Digital sum = 13
    Prime = 12451 Digital sum = 13
    Prime = 12541 Digital sum = 13
    Prime = 12613 Digital sum = 13
    Prime = 12703 Digital sum = 13
    Prime = 12721 Digital sum = 13
    Prime = 13009 Digital sum = 13
    Prime = 13063 Digital sum = 13
    Prime = 13171 Digital sum = 13
    Prime = 13441 Digital sum = 13
    Prime = 13513 Digital sum = 13
    Prime = 13711 Digital sum = 13
    Prime = 14071 Digital sum = 13
    Prime = 14107 Digital sum = 13
    Prime = 14143 Digital sum = 13
    Prime = 14251 Digital sum = 13
    Prime = 14323 Digital sum = 13
    Prime = 14341 Digital sum = 13
    Prime = 14431 Digital sum = 13
    Prime = 14503 Digital sum = 13
    Prime = 15061 Digital sum = 13
    Prime = 15241 Digital sum = 13
    Prime = 15313 Digital sum = 13
    Prime = 15331 Digital sum = 13
    Prime = 15511 Digital sum = 13
    Prime = 15601 Digital sum = 13
    Prime = 16033 Digital sum = 13
    Prime = 16141 Digital sum = 13
    Prime = 16231 Digital sum = 13
    Prime = 16411 Digital sum = 13
    Prime = 17041 Digital sum = 13
    Prime = 17203 Digital sum = 13
    Prime = 17401 Digital sum = 13
    Total: 141

    Posted by: Daniel on 18/07/2016

  • Hi Daniel. Your answer looks good -- make sure you look out for our answer blog next week to see how we approached the challenge!

    Posted by: Josh (Deloitte) on 20/07/2016

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.