# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1636: Risky business

From New Scientist #2802, 5th March 2011 [link]

Just before Christmas in Joe’s town, population 20,775, there was a bug going around, which, it was known later, had affected just 75 people. At the time the only test that could detect the bug was just 92 per cent accurate and was never used. Joe wondered, if all the population had been tested, what percentage of those who came up positive would actually have had the bug.

What would the percentage have been?

[enigma1636]

### One response to “Enigma 1636: Risky business”

1. jimrandell 12 December 2011 at 5:04 pm

A trivial amount of programming involved in this puzzle. (Runtime: 29ms).

```# if the test is 92% accurate it means that for every 100 people tested
# with the bug 92 of them will test +ve, 8% of them will test -ve.

# also for every 100 people tested without the bug 8 will test +ve and
# 92 will test -ve

# so for a population of 20775 where 75 have the bug

# of the 75 tested with the bug:
# 0.92 * 75 = 69 people will (correctly) test +ve
# 0.08 * 75 =  6 people will (incorrectly) test -ve

# of the 20700 people without the bug:
# 0.08 * 20700 =  1656 people will (incorrectly) test +ve
# 0.92 * 20700 = 19044 people will (correctly) test -ve

# so of those that came up +ve
# 69 / (69 + 1656) = 4% will correctly test +ve

correct = int(0.92 * 75)
incorrect = int(0.08 * 20700)
total = correct + incorrect
print "correctly test +ve = {}% ({} of {} (= {} + {}))".format(100 * correct / total, correct, total, correct, incorrect)
```

Solution: 4% would correctly test positive.