Please visit my new campsite listing site ukcampingmap.co.uk


Archive for the ‘php’ Category

More pizza squabbles

Saturday, May 2nd, 2009

The other day I ruminated on whether going for the smallest slice of pizza initially will result in your getting more in the long run than going for the biggest first, and concluded that I should try and write a computer model of it, which I have now done (bear in mind the page is a bit slow to load), to a degree.

The graphs below, plotting number of pizza slices vertically (increasing as you go down) and number of people horizontally (increasing to the right), and average over 100 trials per slices/people combination, show that there is a small area, when the number of people is roughly equal to half the number of pizza slices, and the number of people is not too big, where taking the smallest available slice on the first go pays off. But an even better strategy under these circumstances is to take the smallest of the N largest slices, where N is the number of people.

Graphs of pizza slice taking strategies

Graphs of pizza slice taking strategies

There are lots of alterations I’d like to make to the model, as it’s not quite a true reflection of reality.

  1. Add the ability to have people eating at different rates.
  2. At present the sizes of the slices are chosen randomly (and then normalised to make sure the total size is equal to the number of slices). However, the distribution in real life pizza slice sizes is far from random; they will probably have roughly a normal distribution, with very few extra big slices and very few extra small ones. Because the size of one slice is not independent of the sizes of other slices, they are likely to follow a more complex distribution, but it’s probably beyond me to work out what it is.
  3. The colours are nowhere near contrasting enough. I’ve done a bit of a fiddle on the greens to bring them out a bit more, but it’s a bit of a cheat that probably won’t always work. There are regions in the graph where one strategy is consistently slightly better than the other, but it doesn’t show. A high contrast version (below) does show this info (and in fact also showing that most of the time you’re better off wtha smaller slice first strategy if more than two slices per person), but I think it’s important to show the subtleties too.
    pizza-slices-high-contrast
  4. The slow loading is an issue.

For the record, now that I know how OOP works in PHP I used my new skills to write the model, and it was most useful. Much easier to keep track of what values you’ve written to where.

I have shot ourselves in the foot

Sunday, April 26th, 2009

A word of warning for anyone not remotely interested in programming, the rest of this post will be a long, hard, meaningless slog, though not without some comic payoff.

Object oriented programming (OOP) is a major concept to grasp if you want to go places as a programmer. My problem for the last year or so is that I have got to grips with the concept pretty well, but was still no closer to being able to do it.

OOP is a bit like set theory and group theory, which I’m more than familiar with as I studied maths for a good many years, and I could easily come to grips with the 4 basic tenets of OOP, but despite this I was still mystified as to how all these web-pages (in my case, though OOP reigns supreme in any big software project) know what to do with all these classes you’ve set up; how it knows where to find their definitions in particular was the bit that mystified me.

I know have the answer. After posting a question on a forum I discovered it’s not actually part of OOP theory at all, it’s just that programming languages that support OOP tend to have some way of enabling you to very concisely specify where the classes are to be found. The obvious answer I suppose.

Using the new search term “autoinclude” I was able to find a decent how-to tutorial. The tutorial is very well put together, save for some pretty on the cheap editing. Someone at a late stage before its publication must’ve thought it could do with coming across as more personable. A quick find and replace later, and all the “we”‘s have gone, replaced by “I”‘s. Which has left such beautiful turns of phrase as:

I have shot ourselves n the foot

I are using two external constants

I have a million products in my database, and I are not going to tell you about any of them!

Junior’s a programmer now

Saturday, April 11th, 2009

I didn’t take the traditional route to my present career. After graduating in maths I knew I didn’t want to take the obvious route of becoming an actuary or accountant as maths, contrary to popular belief, is nothing remotely to do with adding up (although, in hindsight I reckon being an actuary might be fairly interesting, but you still have to mix with graduate training scheme types).

So many years later, after leaning web-wards through a series of charities and lower jobs, I find myself a reasonably competent web-developer.

But I still have a lot to learn and the book I’m reading (Deep Simplicity by John Gribbin) is proving to be a great source of ideas to stretch my programming legs. Making websites is all well and good, but the examples of complex systems emerging from simple rules, and the constant talk of computer models, has given me the impetus to stretch my abilities to making convoluted programs to model certain behaviours.

The first one I’ve attempted is the following scenario:

You have N buttons and an unlimited number of threads. You pick up 2 buttons and connect them with a thread, and then do this repeatedly.

So I wrote something to produce a graph of interesting things to keep track of during this process.

It’s also given me the idea for a jQuery plugin

Happy valentine’s

Saturday, February 14th, 2009

The funniest thing just happened:

I was adding this as my facebook status in one of the study pods at the library:
“Rhys is wondering why the amsterdam library has lots of signs up saying “2,000+ dicks”. 2,000 people and some dicks? More than 2,000 dicks?”

Just then a middle-aged man with his elderly father poked his head in to the pod and said in dutch something which must have been along the lines of “And look, father, in this modern library there are plenty of places where people such as this young genius can study hard”

Could there be a  better illustration of how the internet lowers our level of thought. From now on I will only have studious facebook messages.

On another note, I’m trying to choose a php framework to learn to use (akelos is the frontrunner), and used the website -www.phpframeworks.com to help me. Two interesting aspects of it are:

  1. The site is wider than my screen. I guess it’s really as wide asmy screen, but they forgot to account for scroll bars. A rare example of a website aimed at the programming community that takes advantage of the fact that most of us (though alas not I) have massive screens.
  2. It uses tables for its layout. After working for a day converting a site made with Frontpage to standards compliant, semantic xHTML, and revelling in the difference between the sites when I turn CSS off, it saddens me that everyone isn’t doing it. I mean, it’s actually quite good fun.

Happy valentine’s day