-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathhotdate.html
76 lines (54 loc) · 2.21 KB
/
hotdate.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<title>Puzzle: A Hot Date With itertools</title>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<p class="subtle"><a href="/">« Boston Python puzzles</a></p>
<h1>A Hot Date With itertools</h1>
<p>[inspired by <a href="http://www.dgp.toronto.edu/~flaps/progprobs.html">http://www.dgp.toronto.edu/~flaps/progprobs.html</a>]</p>
<p>Consider these base-10 digits: 123456789. If you insert spaces between them, you get various sequences of numbers:</p>
<pre>
1 2 3 4 5 6 7 8 9
12 3 4 5 67 8 9
1 2 34 5 6 7 89
12 34 56 78 9
1 23456 78 9
12345 6789
etc.
</pre>
<p>1) Write a program that generates all possible combinations of those digits. </p>
<p>How many are there?</p>
<p>Now let's insert a maximum of 8 addition or subtraction operators between the numbers, like this:</p>
<pre>
1+2+3+4+5+6+7-8+9
12-3+4+5-67-8+9
1+2+34+5-6-7-89
12-34+56+78+9
1+23456-78-9
12345+6789
etc.
</pre>
<p>Notice that those arithmetic expressions equate to different values:</p>
<pre>
1+2+3+4+5+6+7-8+9 = 29
12-3+4+5-67-8+9 = -48
1+2+34+5-6-7-89 = -60
12-34+56+78+9 = 121
1+23456-78-9 = 23370
12345+6789 = 19134
etc.
</pre>
<p>2) Write a program that generates all possible expressions in this way.</p>
<p>How many sum to 100?</p>
<p>3) Write a program that finds all such expressions for any sum.</p>
<p>Which sum is the most popular, i.e. has the most expressions?</p>
<p>4) Bonus: We can haz pretty data viz?</p>
<p>Like how about a histogram of the number of expressions with sums from -23456788 to 123456789. (A log scale might help. Maybe binning, too.)</p>
<h2>Solutions</h2>
<ul>
<li>Michelle Fullwood's solution is an <a href="http://nbviewer.ipython.org/urls/dl.dropbox.com/s/629zj3av5t5w1i4/Boston%20Python%20Puzzle%20%231%20Solution.ipynb">IPython notebook</a></li>
<li>Allen Downey's solution is an <a href="http://nbviewer.ipython.org/github/allendowney/ThinkStats2/blob/master/code/puzzle1.ipynb">IPython notebook</a></li>
<li>Josh McGrath's solution is <a href="https://github.com/BostonPython/puzzles/blob/gh-pages/solutions/joshmcgrath08/hotdate.py">hotdate.py</a></li>
</ul>
<p>If you have a solution you'd like to share see the <a href="solutions.html">Solutions page</a> for instructions.</p>