-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathKata.html
131 lines (129 loc) · 5.23 KB
/
Kata.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>Untitled Document.md</title><style type="text/css">
html, body {
font-family: Georgia,Cambria,serif;
height: 100%;
}
html {
font-size: .875em;
background: #fff;
color: #373D49;
}
body {
margin: 0;
}
*, *:before, *:after {
box-sizing: border-box;
}
h2, h3 {
line-height: 3rem;
}
h1, h2, h3, h4, h5, h6 {
font-family: "Source Sans Pro","Helvetica Neue",Helvetica,Arial,sans-serif;
-webkit-font-feature-settings: 'dlig' 1,'liga' 1,'lnum' 1,'kern' 1;
font-feature-settings: 'dlig' 1,'liga' 1,'lnum' 1,'kern' 1;
font-style: normal;
font-weight: 600;
margin-top: 0;
}
code, kbd, pre, samp {
font-family: monospace,monospace;
}
pre {
overflow: auto;
}
pre {
padding: .66001rem 9.5px 9.5px;
display: block;
margin: 0 0 10px;
word-break: break-all;
word-wrap: break-word;
color: #333;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
}
</style></head><body id="preview">
<h3><a id="C_UG_Dresden__11052017_0"></a>C++ UG Dresden - 11.05.2017</h3>
<h1><a id="Kata_BankOCR_2"></a>Kata BankOCR</h1>
<pre><code>This Kata was presented at XP2006 by Emmanuel Gaillot and Christophe Thibaut.
</code></pre>
<p><strong>Problem Description</strong></p>
<h3><a id="User_Story_1_8"></a>User Story 1</h3>
<p>You work for a bank, which has recently purchased an ingenious machine<br>
to assist in reading letters and faxes sent in by branch offices. The<br>
machine scans the paper documents, and produces a file with a number of<br>
entries which each look like this:</p>
<pre><code> _ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|
</code></pre>
<p>Each entry is 4 lines long, and each line has 27 characters. The first 3<br>
lines of each entry contain an account number written using pipes and<br>
underscores, and the fourth line is blank. Each account number should<br>
have 9 digits, all of which should be in the range 0-9. A normal file<br>
contains around 500 entries.</p>
<p>Your first task is to write a program that can take this file and parse<br>
it into actual account numbers.</p>
<h3><a id="User_Story_2_29"></a>User Story 2</h3>
<p>Having done that, you quickly realize that the ingenious machine is not<br>
in fact infallible. Sometimes it goes wrong in its scanning. The next<br>
step therefore is to validate that the numbers you read are in fact<br>
valid account numbers. A valid account number has a valid checksum. This<br>
can be calculated as follows:</p>
<pre><code>account number: 3 4 5 8 8 2 8 6 5
position names: d9 d8 d7 d6 d5 d4 d3 d2 d1
checksum calculation:
(d1+2*d2+3*d3 +..+9*d9) mod 11 = 0
</code></pre>
<p>So now you should also write some code that calculates the checksum for<br>
a given number, and identifies if it is a valid account number.</p>
<h3><a id="User_Story_3_46"></a>User Story 3</h3>
<p>Your boss is keen to see your results. He asks you to write out a file<br>
of your findings, one for each input file, in this format:</p>
<pre style="page-break-before:always;"><code>457508000
664371495 ERR
86110??36 ILL
</code></pre>
<p>ie the file has one account number per row. If some characters are<br>
illegible, they are replaced by a ?. In the case of a wrong checksum, or<br>
illegible number, this is noted in a second column indicating status.</p>
<h3><a id="User_Story_4_59"></a>User Story 4</h3>
<p>It turns out that often when a number comes back as ERR or ILL it is<br>
because the scanner has failed to pick up on one pipe or underscore for<br>
one of the figures. For example</p>
<pre><code> _ _ _ _ _ _ _
|_||_|| || ||_ | | ||_
| _||_||_||_| | | | _|
</code></pre>
<p>The 9 could be an 8 if the scanner had missed one |. Or the 0 could be<br>
an 8. Or the 1 could be a 7. The 5 could be a 9 or 6. So your next task<br>
is to look at numbers that have come back as ERR or ILL, and try to<br>
guess what they should be, by adding or removing just one pipe or<br>
underscore. If there is only one possible number with a valid checksum,<br>
then use that. If there are several options, the status should be AMB.<br>
If you still can’t work out what it should be, the status should be<br>
reported ILL.</p>
<p><strong>Clues</strong></p>
<p>I recommend finding a way to write out 3x3 cells on 3 lines in your<br>
code, so they form an identifiable digits. Even if your code actually<br>
doesn’t represent them like that internally. I’d much rather read</p>
<pre><code>" " +
"|_|" +
" |"
</code></pre>
<p>than</p>
<pre><code>" |_| |"
</code></pre>
<p>anyday.</p>
<p>When Christophe and Emmanuel presented this Kata at XP2005 they worked<br>
on a solution that made extensive use of recursion rather than<br>
iteration. Many people are more comfortable with iteration than<br>
recursion. Try this kata both ways.</p>
<p>Some gotchas to avoid:</p>
<ul>
<li>be very careful to read the definition of checksum correctly. It is not a simple dot product, the digits are reversed from what you expect.</li>
<li>The spec does not list all the possible alternatives for valid digits when one pipe or underscore has been removed or added</li>
<li>don’t forget to try to work out what a ? should have been by adding or removing one pipe or underscore.</li>
</ul>
</body></html>