Pizza And Maths

Most of the time, when i talk about maths to anyone, i hear the same chat:
Maths is hard
You either get it or you don’t
Maths is not for everyone
Rather you than me
Oooo. Maths. Eish.

And so on… Well, maybe true but maybe not true at all. Regardless of how you feel about it, there are times when it’s very practical, almost *fun*, to know just a little about it. And you don’t need first year university maths to work some things out.

Butlers Pizza (arguably the best pizza in Cape Town) have a deal where you can buy 2 large pizzas or get a 3 for the price of 2- for roughly the same price if you get 3 mediums. Which is more pizza? Which is better value for money? And more serious questions like: how much cold pizza will i have left over for lunch/breakfast tomorrow?

A medium is 26cm, a large, 32cm in diameter. Assuming the bases and toppings are all mostly equal, you can simplify your calculations to work on the surface area of pizza presented. And given pizzas are more or less round, you use the formula for the area of a circle (π r2). Once you’ve established the area for a medium, multiply the result by 3 to get a combined pizza surface area. For the larges, repeat the exercise and multiply by 2.

You can judge at this stage which deal is going to give you more pizza. But what about best value? Well, take the total amount of pizza and divide it by the cost. Your answer is pizza/rand. So go for the deal that has the highest number. So the “Big Deal” will cost you 98.95, the 3 pizzas will cost you 2×49.95 (assuming simplest case) . You should know pretty soon which you want: more pizza or best value for money?

Of course, it gets so-called “complicated” when you start adding extra toppings and wheat-free bases. But all those “complications” are just little additions to the same steps. It’s actually not complicated at all- it’s methodical. And all the information is there, you just need a simple calculator.

Of course, some might say: why bother? Indeed. Why bother at all? Well, why not? It’ll take you less than 5 minutes to arrive at an answer which maximises your utility- which is economic speak for: get the best bang for buck. And especially when it’s close to the end of the month. But there’s also a deeper truth which you start to uncover… just how “special” is a special really? And even more grave, what’s breakfast going to be like?


A New Language: Where To Start?

When you learn a new speaking language (English, French, Spanish, Hebrew, Afrikaans….) you generally find your course or program is broken down into scenarios. For example, mostly all books, audio or videos will have the topics: Greetings, At The Airport, Public Transport, At The Hospital, Hotel, Restaurant and so on. Essentially, everything you need to “get going”. Of course, a lot is assumed, but the assumptions cover 80% of the market picking up a new language. Is it different with programming?

I think not. What we don’t always have is a “program” of topics to cover that can be referenced- or at least, not one readily packaged. There are many reasons for that being the case, but this post is not about that. So what are the topics….?

For me, that is, i find going back to good ol’ One-Oh-One basics of data structures a really useful way to learn the ins and outs of a language. This is not a new idea by any stretch of the imagination. But take a list like this, and tackle the structures one by one in your new language. Pretty soon, you get to figure the language out in the detail you need to get on with the job.

Of course, the bonus is that you’re going to need a variation of one of those implementations somewhere in some form or another (even if your framework provides native implementations). But building data structures from the ground up teach you all the essential scenarios: How to define a class, inheritance capabilities (if applicable), methods, signatures, variables… And provided you are (should be) familiar with the details of the requirement, you can free your mind to focus on the language, and not a new problem at the same time.


Classical, Functional or Prototypal?

I have updated the maths playground on this site as part of an ongoing adoption and learning of new languages and in particular, programming approaches. The language itself is not really the issue when you’re tackling a task. In fact, learning a ‘programming language’ itself (the syntax that is) is a non-issue. What you do come up against is, is a mindset.

Taking the “classical” languages like C, C++, C# and Java as examples, the way you code in each is roughly the same. Different semantics, but a lot of variable commonality. (Of course, you can get frameworks, like the Symbian SDK, which obsfucate things enough for you to appear as another language). Then you take something like Ruby, and the way you think _has_ to change, or you’re just going to hit your head against the proverbial. And then still, something quite different like Javascript (in it’s more modern form).

Having been schooled in more classical approaches (C, C++), the jump to functional programming was an interesting curve. And now, another shift to prototypal programming has been as interesting. Still some concepts make me ponder though. Nonetheless, i’ve documented the differences, in the form of code, between the pseudo-classical and prototypal approaches in using Javascript.

Any pointers welcome, thanks 🙂