Skip to content

bediger4000/guncontrol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Found a puzzle on the notorious Futility Closet web site.

Here's Futility Closet's puzzle. Mr or Ms Closet decided to call the puzzle "Gun Control". I don't know if they chose the title to skirt controversy or something.

Problem Statement

Marksman A hits a certain small target 75 percent of the time. Marksman B hits it 25 percent of the time. The two of them aim at that target and fire simultaneously. One bullet hits it. What’s the probability that it came from A?


I decided to solve this via a simulation.

Simulation

  1. Chose a random numer between 0 and 100 inclusive. If that random number evalutes to less than 75, Marksman A hit the target.
  2. Chose a random numer between 0 and 100 inclusive. If that random number evalutes to less than 25, Marksman b hit the target.
  3. If A or B (but not both!) hit the target, count who hit the target, A or B
  4. Repeat a few times, display percentages of who hit the target.

Build and run

$ cd $GOPATH/src
$ git clone https://github.com/bediger4000/guncontrol.git
$ cd guncontrol
$ go build gc1.go
$ ./gc1

Usage

  -A int
        Proability in percent that Marksman A hits the target (default 75)
  -B int
        Proability in percent that Marksman B hits the target (default 25)
  -N int
        Number of rounds of shooting to simulate (default 10000)

I put 10,000 iterations as a default, but 100,000 iterations works better, and is computationally quite quick.

About

Marksman A hits a target 75% of the time, B 25%. When they both shoot and one hits the target, who is it?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages