-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDev_Notes.txt
More file actions
92 lines (72 loc) · 3.87 KB
/
Dev_Notes.txt
File metadata and controls
92 lines (72 loc) · 3.87 KB
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
base_multiply.py
2014-10-12 ejb
Here's a good start:
- quotient (ie. carry) and remainder (ie. number(?!)) from divmod
- input to divmod:
- index of digit times index of digit
- where what we are indexing into is the substring of 0-F that is appropriate for the base
- the base
Now we just need to - hm, well, on second thought this is going to more complicated than I initially thought.
I was going to think about whether I should do right-to-left processing by just reversing the input string of digits,
or by doing something fancier with a negative step.
But that's possibly premature.
Well, no, I guess I do have to address it now.
But let's start with a simple case, with only one number at more than one (ie. 2) digits.
And by just reversing the stings, for simplicity's sake. I may revisit that later.
Okay, so far so good; I've got it working when one number is multi-digit.
Next: handle both numbers being multi-digit.
Hm, that's actually a bit awkward, since I'm dealing with these things as strings.
I'll need to store the output string for each row (ie. result of multiplying x with the current digit of y),
appending an extra zero to the end (ie. one more zero than the one before)
And then I'll have to write an addition function.
Okay, wrote an base_addition module and imported it. (Symlinked the py file into this directory so I don't have to
muck about with add its location to the library path.)
Implemented the loop over the other input's digits.
And it works! Woohoo!
Nope, no good.
Worked for all of my tests in base four.
But base-8 711x5007 includes '9's in the answer, which is nonsense.
And a base-16 test that should have had letters in the output didn't.
So, some closer thinking and debugging is required.
=> DONE
=> It was a trivial oversight, using the results of arithmetic operations directly instead of getting the character
at that index in the digits list.
NEXT:
- arg-handling:
- take args if given on the commandline
=> Okay, I've got this
- else prompt for arg
=> I'm not sure I want to do this
=> NAH.
- Take the body out of __main__ and put it in a method so that it can be imported as a module
=> DONE.
- Make __main__ run the test-suite
- Or should __main__ be used in both for running the script, and I'll have some separate test harness? I guess so...
- Maybe a mutually-exclusive arg group for --test
=> DONE.
- Implement arg-parsing in base_addition
=> DONE.
- TODO: Can base_addition respect base_multiplication's --debug flag?
- Probably either by uglily adding a debug parameter to the base_addition function, or else by converting the entire enterprise to object-oriented and making debug a member-variable
- test suites for base_addition and base_multiplication
=> DONE
- Also sort out the IDE project and git repos, because I've got three different things semi-confounded here (on sjgould).
BUGS:
- I am getting an incorrect result on base-16 789ABC x 5DEF (2C40CF27F4 instead of 2C40CEC184; ie. I am *over*)
- So I am walking through the calculation on paper and comparing interim results.
- 789ABC x F is correct: 7 11 11 04
- 789ABC x E is also correct *by itself*: 6 98 76 48
- But as part of the full calculation, that partial product is wrong: 6 98 76 4F 0 (where the trailing zero is from being in the tens position
=> FIXED.
FUTURE:
- TODO: convert/refactor to object-oriented (just for the exercise)
- allow arbitrary number of multiplicands?
- That shouldn't be too bad, actually: put them in a list, initialize an accumulator to 1, and multiply the
accumulator with list.pop().
- The easy way to do this would be in __main__, but I want to do it in the actual base_multiply method so that it still works as an imported module
- _TODO first: extract the meat of base_multiply out of __main__ into its own function.
=> DONE
=> DONE
- Do the equivalent with base_addition.
=> DONE
=> DONE