Guest Post: Tax Calculation by Computer Science in Diagon Alley (David Martin)

From Professor and profound Potter Pundit David Martin:

As a Harry Potter fan who teaches Computer Science, I envy my fellow academics in other disciplines – such as philosophy and psychology – who can easily find so many ways to incorporate the Harry Potter novels into their courses.  However, I have found one small area I can use in my Computer Science One course.  Here it is:

========= The Assignment =================================

In the Harry Potter novels, the money used in the magical world comes in three denominations: bronze Knuts, silver Sickles, and golden Galleons.  29 Knuts equal one Sickle, and 17 Sickles equal one Galleon.

(I suppose that Rowling is here acknowledging – or satirizing? – the older British system of currency that was used until the “decimalization” reform of the 1970s.  Under that older system there were 12 pence to the shilling and 20 shillings to the pound.  British school children had a whole additional topic to study in math class just learning how to handle calculations in that non-decimal system.)

Let us imagine that the Ministry of Magic finances itself, in part, with a 4.5% sales tax on all goods sold in Diagon Alley, the main shopping area in the magical world.

Here is the assignment: Write a program to calculate this tax and add it to the cost of the sale.

Your program should begin by asking for the amount of the sale (in Galleons, Sickles, and Knuts) and then print out the amount the sale, the amount of the sales tax, and the total to be paid.

Here are two sample executions:


++++++++++++++++++++++++++++++++++++++++++++++++++

How many Galleons? 123
How many  Sickles? 11
How many    Knuts? 22

Sale:  123 Galleons, 11 Sickles, 22 Knuts
Tax:    5 Galleons,  9 Sickles, 18 Knuts
——————————————
Total:  129 Galleons,  4 Sickles, 11 Knuts

 

How many Galleons? 30
How many  Sickles? 15
How many    Knuts? 25

Sale:   30 Galleons, 15 Sickles, 25 Knuts
Tax:    1 Galleons,  6 Sickles, 19 Knuts
——————————————
Total:   32 Galleons,  5 Sickles, 15 Knuts

++++++++++++++++++++++++++++++++++++++++++++++++++

Hint:  To program this, convert the amount of the sale into the smallest unit (Knuts), compute the tax (rounded to the nearest Knut) and the total in knuts, and then convert those two amounts back into Galleons, Sickles, and Knuts.   Use a “printf()” command on the output so that the columns line up.

Here are a few more test cases:
>>  Hermione’s books from Flourish and Blotts:                 15 Galleons, 15 Sickles, and 15 Knuts.
>>  Ron’s purchases from Weasleys’ Wizard Wheezes:      3 Galleons, 9 Sickles.
>>  The price of Harry’s wand from Ollivander’s:                7 Galleons
(Answers below.)

Please name your program DATax.java and submit it for grading.

Here are the answers for test cases:

>>  Hermione’s books from Flourish and Blotts:
Sale:   15 Galleons, 15 Sickles, 15 Knuts
Tax:    0 Galleons, 12 Sickles,  5 Knuts
——————————————
Total:   16 Galleons, 10 Sickles, 20 Knuts

>>  Ron’s purchases from Weasleys’ Wizard Wheezes:
Sale:    3 Galleons,  9 Sickles,  0 Knuts
Tax:    0 Galleons,  2 Sickles, 20 Knuts
——————————————
Total:    3 Galleons, 11 Sickles, 20 Knuts

>>  The price of Harry’s wand from Ollivander’s:
Sale:    7 Galleons,  0 Sickles,  0 Knuts
Tax:    0 Galleons,  5 Sickles, 10 Knuts
——————————————
Total:    7 Galleons,  5 Sickles, 10 Knuts

========= End of Assignment =================================

If any instructor wants to use this programming assignment, please feel to do so.  And because someone else might want to use this as a programming assignment, I am not including the source code here.

But of course, all of this is impossible because as we know that electronic equipment such as computers can’t work in area where there is a lot of magic.

Comments

  1. Addooshoes says:

    Hey, computer science harry potter fan! how you imagine a muggle-born wizard who wanted to try to integrate computer science and magic would attempt to go about it? asking for a friend.

  2. David Martin says:

    Integrating the fictional magic of the Harry Potter world with the normal content of a computer science
    curriculum is not easy.

    In some fields it is possible to take themes directly from the books. For example, one can look at the “Pure Blood” mania and discuss how that is (or is not) like racism in a sociology class. One can look at Harry’s moral choices and dissect them in an ethics class. However, aside from a few mentions of playing games on Dudley’s computer, the books never mention computers or any fancy calculations Maybe there would be something if we knew a bit more about Hermione’s arithmancy class there would be something. I see no themes or ideas that we can take DIRECTLY from the novels.

    What we can do is use the fictional wizarding world as a setting for our programming problems. We can also get some interesting problems from the wizarding world’s non-decimal currency as shown in my post above about calculating the sales tax in Diagon Alley. Here are some other examples:

    – Some Muggles laid an Internet cable across a corner of the Hogwarts grounds. In order to convince the Muggles that a cable there would be unreliable, Dumbledore worked a spell on the cable so that all bits passing through the cable would be reversed (although the parity bits would adjusted as needed.) The following short message
    (in hexadecimal) was received after passing through the cable:

    ab 97 9e 8b d8 8c df 8b 97 9a df 8d 96 98 97 8b df 9e 91 8c 88 9a 8d d1 f2 f5 f2 f5

    What was the original message? (Assume that the original message was in ASCII.)

    – The original US version of Fantastic Beasts and Where to Find Them has its price printed on the back cover: $3.99 or 14 Sickles 3 Knuts. Using this piece of information as a starting point, write a program which will convert prices between US and wizarding currency (both ways).

    – At the Magical Menagerie we want to buy exactly 100 animals for exactly 100 Galleons. Cats cost five Galleons, rats cost two galleons, and poisonous orange snails cost three Sickles each. Write a computer program to find how we can do this.

    (The solution is 8 cats, 24 rats, and 68 snails.)

    – If we can imagine that there are 100 numbered lockers in a row at Hogwarts, that well-known programming problem about the lockers could be moved to Hogwarts.

    – On a more imaginative level, we could say that a reference to an object is like a Horcrux. The object is not de-allocated (not vulnerable to garbage collection) until all the references to it are gone.

    – Could we say that casting a variable is like using polyjuice potion on it? Maybe.

    You get the idea. I would be grateful for any additional ideas people could come up with.

  3. Kelly Loomis says:

    I never did any programming classes but if I did, I would have loved problems like these!!

  4. Brian Basore says:

    In regard to pre-decimalisation British money, the notes with my 1970 Proof Set say that the three main metals used for coins were, in descending value, gold, silver, and bronze. (Wizard coins apparently kept to this after 1970.)

    The one pound equals 240 pennies system made sense as long as the value of currency was metal-based. According to the Troy weight table “(used in weighing gold, silver, and precious stones)” in the 1948 Funk and Wagnall Standard Collegiate Dictionary:
    24 grains (gr.)=1 pennyweight (pwt.)
    20 pennyweights=1 ounce (oz.)
    12 ounces=1 pound (lb.)

    That is, 1 pound=20 shillings, each shilling made up of 24 pennies. Hence, one pound had 240 silver pennies (“sterling”). Here is part of the note from the Proof Set regarding the Penny:
    The penny was the original English coin, first struck in Kent in the eighth century. It was made of silver and, as first conceived, it contained one 240th part of a pound weight of silver. In Anglo-Saxon times its weight varied, but it was stabilized by William the Conqueror at 22 1/2 grains Troy and it held that weight for two hundred years. It was during this stable period, when it was the best and most reliable currency in Europe, that it was given the alternative name of ‘sterling’ in international markets.

    During the fourteenth and succeeding centuries, with the progress of inflation, the weight of the penny was progressively reduced until by the eighteenth century it had become a tiny coin, much too small for convenient use. In 1797 it was replaced by a large copper piece and in 1860 this in turn was superseded by the bronze coin of which this set contains an example.

    [end of quote]

    Incidentally, according to the notes, the Florin, or two-shilling piece, was first issued in 1849, and was intended as a first step towards decimalisation of the currency; early issues carried the inscription ‘one tenth of a pound’.

    It appears that Ms. Rowling indeed based wizard money on pre-1971 muggle money, which was not as irrational as it now seems.

  5. Brian Basore says:

    Oops. Correction: 12 shillings times 20 pennies is 240 pennies. (This is why I have my taxes done and filed for me.)

    If the Ministry of Magic detects and traces each time someone says ‘Voldemort’, and detects and traces under-age magic in the muggle world, is that the equivalent of a virtual computer at work? That’s programing using magic, isn’t it? And in the time of Harry Potter’s parents when they were at Hogwarts it was common to make custom spells. That’s writing programs. When Harry used one of the Half-Blood Prince’s horrific spells on Draco, only the spell’s author (Snape) knew the counter-spell.

    Patronuses, Obscurials, and Luna’s mother who died from a bad experiment in Magic. White Light spells. Research at the Ministry of Magic. People like Bill Weasely who layer by layer remove protection from objects for Gringotts.

    Hmm. Magic as technology, with programing. That’s a postmodern attitude, I think, not mystical at all.

  6. Brian Basore says:

    The math doesn’t work for the money, does it? If 1 pound is supposedly 240 grains, that’s 10 shillings, not twelve shillings. On the other hand that made it easy to go decimal, since all that had to be changed in the equation was to change the grain value from 24 to 10. Of course people would object to the devaluation, so the change was put off until after it was generally accepted that the sun had set on the British Empire.

  7. Brian Basore says:

    JKR is right to satirize the old money. The Troy Weight standard assures the merchant’s profit, to the detriment of the customer, any way you do the math. In the case of using the standard as a basis of currency, the government’s profit to the detriment of the users of the money was assured.

    Taking it in its stated form, if a pound of silver is divided into 240th parts, that’s 10 pennies, that is, only half a shilling. But the Troy weight standard states there are 12 ounces (shillings) in a pound, which works out to 5760 grains. 5760 grains divided by 240 grains is 24 pounds per Pound. Only one of those 240 grain pounds has to be officially accounted for.

    Using the grossly simplified approach, as I did in the post just before this one, that one pound equals 240 grains, and that a pound must be made of shillings, that works out to 10 shillings, not 12 shillings. That leaves two phantom shillings in each Pound, which is a much more pleasant fiction than a 23 pounds per pound overcharge built into the system. It is worth mentioning because the two official phantom shillings allowed the upper classes to be given better money than common people had. Professionals and upper class had the Guinea (one pound/one shilling). That’s still not 12 shillings to the Pound, but it was better, and it made large fortunes seem less than they were, and so less vulgar than the fortunes of American magnates. (American fortunes, via marriages to American heiresses, propped up impoverished British aristocracy in the twentieth century. The Honorable Winston Spencer Churchill was equally of New York and British aristocracy as a result of this phenomenon, for example.)

    Decimalisation of the currency made the Pound equal for rich and poor alike, and stripped very large fortunes of any appearance of gentility. It also completely reset the money to the modern standard of money being worth whatever the government sets as the value. This may have been the truth of the matter all along.

    It seem to me that all of the above is reflected in JKR’s attitudes toward money.

  8. Brian Basore says:

    Okay, I stand corrected. But 12 pennies at 24 grains each is 288 grains, not 240. That’s one Pound, two shillings, and that’s only half a Pound if there are twenty shillings to a Pound! Twenty shillings to the Pound at 12 pennies each does equal 240 pennies, but that’s still too many grains of silver. Adjusted to William the Conqueror’s 22.5 grains (in value), that’s still 270 grains. The point is that the 240 pennies to a Pound stayed the official definition though the value varied according to inflation.

    *Ten* pennies at 24 official grains is 240. That’s less – and a lot more – than a shilling, at 20 shillings to the Pound. The math doesn’t work. People were being shortchanged. People used the old money system every day for centuries despite that. It was part of their personal and national identities. (JKR was six when decimalization took effect but she’s had older people around her to reinforce her knowledge of old money.)

Speak Your Mind

*