projects

Archive for projects

Fruit Flinging

You may of seen the original Sony Bravia advert where they hurled thousands of balls down a steep street in San Francisco. Initially a lot of people thought it was cgi, but it turns out they really did do it.

For those that havn’t seen it, you can watch the advert here.

bravia commercial image large

The advert was hugely successful and spawned a slew of imitators. One of these was one relativly short lived take off by Tango (Clear).

Now, its more likely you havn’t seen this advert. Same music, same concept though replacing the hilly streets of San Francisco for a street in Swansea.

Also, the balls are now fruit. You can watch this one here.

But thats not the interesting part. The interesting part is this website:

Swansea North Residents Association

Examining the site you can find various interviews about how terrible the advert was – how it ruined their lovely street, even how Aled Edward’s was late to work that evening because he had to wash the pulpy mess off his car. You just can’t make this stuff up.

My personal favourite is the video interviews with the shocked and angered residents. With this quote from this woman, being my favorite.:

Eileen survived both wars with the utmost composure, but couldn’t contain her anger when her home was bombarded by kiwis and citrus fruit.

I think I may just sign the petition, I mean, its their street today, what about tommorrow? These terrible TV types, will be flinging fruit down everybody’s streets. Oh No!

I guess its one way to get kids to eat fruit.

(I’ve got a slightly nasty feeling this may be part of a failed viral campain – I mean it just seems too lame to make up doesn’t it?)

sometimes its the small things

While opening an old c# project today it came up with the following error:

Refreshing the project failed. Unable to retrieve folder information from the server.

Now this is rather annoying, but after a quick google session I found the answer.

Rather simply the strange solution is this:

Delete the folder VSWebCache which is in your Documents and Settings folder.

That solved it for me – Go Internet!

seriousbusiness

Ajax fun!!! (Drag and Drop Reordering)

Drag and Drop reordering is a really useful thing to have. The original motivation is to let merchants using Karova Store reorder the way in which articles, products display on their sites, but as I was implementing it we found it easier to basically let them reorder anything that could be displayed in a table.

Theres lots of examples and guides online to show you how to us the scriptaculous libraries to do this, but they all seem to deal with li’s within ul’s not tables.

The tech I’m using for this is pretty simple stuff. The html is coming from an xslt, the data’s going to be held in an xml file, the client side scripting is basic javascript and the server side ajax post back is being handled in c#. All of the things we’re going to do here can be done in lots of different languages, as its likely your setup is going to be different from this.

So heres what we want to do:

  • Display the items in a table,
  • Be able to reorder them by just dragging and dropping them
  • Record what the new order is whenever it changes
  • Use this new order when displaying them to the end user

Follow the white rabbit

1. We need libraries

No, we’re not going to be writing this from scratch, so we need the real engines that are going to do most of the work. So run off and get the latest version of the scriptaculous libraries. We’re using version 1.6.5, but anything recent should work.

Assuming you’ve got them now, just include the the prototype and scriptaculous libraries in your header, making sure the prototype reference is before the scriptaculous reference. They’ll import everything else they need as long as they’re in the same directory.

2. Make up your mark up

For the libraries to work properly we need to have our table to have the right id’s and so on. To use the default markup that works with the scriptaculous libraries mark it up with the tbody having an id of ‘item_list’ and the individual tr’s having id’s of ‘item_{ID}‘.

Basically all you need for it to work is the container to have an id of item_list (you can change this later on) and the individual items with and id of the form item_ID. If you really want to change structure of the individual id’s on the ’s you can, but you’ve got to go and change the scriptaculous libraries, so if I were you, I’d stick with this, at least for now.

3. Initial Dragging and Dropping

Before we go ahead and get all the ajax posting sorted, lets just check it works in its current form. Somewhere in your code you need to put the following javascript to tell the libraries to work their magic.

Sortable.create('item_list',{tag:'tr',
ghosting:true,constraint:'vertical'})

Oh, and this needs to be put in AFTER the table. Otherwise it won’t work. Got that? After, as in further down, later, nearer the end. Ok?

Its the Sortable.create() that does the magic, the first argument is just the id of the thing your reordering, while the things inside the braces are optional arguments. You can find a list of the extra options you can add on wiki page for sortable.create.

Basically the three we’ve got here do the following things:

  • ‘tag’ – the tag, by default its taken as li, so this only needed if its different, as it is here for use in a table
  • ‘ghosting’ – setting this to true displays a transparent version of what you are moving under your mouse
  • ‘constraint’ – tells it house we’re moving the elements. Here its up and down, thus vertical, simple really

We’ll add some more later but for we just need to see that it works.

4. Recording the Reordering

What good is it if the user moves all the items around and but we have no record of what’s changed. No good. Thats how much good it’d be. We could have the user hit a confirm button when their done reordering, but thats and extra click. Of course we could just record what the new order as and when it changes.

Which is what we’ll do. Don’t panic, it’s surprisingly easy.

All we need to do is add a new argument to our sortable.create. This ones called ‘onUpdate‘, and we use it like this:

Sortable.create('item_list',{tag:'tr',
ghosting:true,constraint:'vertical',
onUpdate : updateOrder});

With the updateOrder function looking like this:

var options = { method : 'post',
parameters : Sortable.serialize('item_list') };

For some reason this didn’t work for me. It did return a serialized list yes, but not one in a format I could use. But don’t fret. If this has not worked for you either, try this (longer more scary looking) version.

var ampcharcode= '%26';
var serializeOpts = Sortable.serialize('item_list')
+ unescape(ampcharcode)
+"key=item_list;
var options = { method : 'post',
parameters : serializeOpts };

For this to work totally right we also need to add this new part to our sortable.create function…

Sortable.create('item_list',{tag:'tr',
ghosting:true,constraint:'vertical',
onUpdate : updateOrder,
tree:true})

There, that bit at the end. Don’t ask me why it helps it work, but it does. Just take it and be thankful.

Hold Up! Wheres this ajax you were promising? Oh wait, here it comes, I was just building it up a bit.

So, we now have all the information, all we need to do is pass it along to our server so it can do some tricks with it. For this we need to add the line ‘new Ajax.Request(’reorder.aspx’,options);‘. Where ‘reorder.aspx is the name of the this you’re posting to.

This is what our finished bit of javascript should look like:

function updateOrder(){
var ampcharcode= '%26';
var serializeOpts = Sortable.serialize('item_list')
+ unescape(ampcharcode)
+"key=item_list;
var options = { method : 'post',
parameters : serializeOpts };
new Ajax.Request('Reorder.aspx',options); }

Sortable.create('item_list',{tag:'tr',
ghosting:true,constraint:'vertical',
onUpdate : updateOrder,
tree:true})

If you want to debug at this point, all you need to do is add an alert(options.parameters) before the ajax request.

Now – onward onto the server side fun!

6. Actually using this stuff

Remember, we’re doing this in c#, so if you’re not doing it in c#, you don’t really need to follow all this too carefully.

The posted things come through to the c# as a form, but for safety, lets check it the form has keys with a simple test.

if(System.Web.HttpContext.Current.Request.Form.HasKeys())
{
//do some stuff here
}

Simple. Child’s play. Now lets fill it up with everything.

The stuff we get out of the seriazable comes back in the form ‘item_list[1][id]‘ with the key being the position. To get out exactly what we need lets use a regular expression to get out the numbers and leave everything else.

System.Xml.XmlDocument docO
= new System.Xml.XmlDocument();
docO.LoadXml("");
string itemKey
= System.Web.HttpContext.Current.Request.Form.Get("key");

foreach (string key in
System.Web.HttpContext.Current.Request.Form.Keys)
{
if(key.IndexOf(itemKey) > -1)
{
System.Text.RegularExpressions.Match m
=System.Text.RegularExpressions.
Regex.Match(key,itemKey+@"[(?d+)][]");
if(m.Groups["position"]!=null)
{
System.Xml.XmlElement posEl
= docO.CreateElement("position");
String itemOrder
= m.Groups["position"].Value;
posEl.SetAttribute("pos",itemOrder);
Sring itemId
= System.Web.HttpContext.Current.Request.Form.Get(key);
posEl.SetAttribute("id",itemId);
docO.DocumentElement.AppendChild(posEl);
}
}
}

As you can see here, the c# takes the parameters that are passed and puts them into an xml document, ending up with some xml of the form:

7. The Finished product

So we’re done. Quickly, lets go over what we’ve got.

Using the prototype and scriptaculous libraries we can reorder lines in a table. When ever we do, a function called ‘updateOrder‘ gets called. This serializes the new sequence in our table and posts it through to some waiting c# for some server side handling. On the server side we take the serialized sequence, do some reg ex clean up then generate some xml with it, which can then be used however we want.

Its all good.

As ever, if you notice any problems with anything above, let me know and I’ll go through and fix it. Let me know if this was useful to you.

You can a working example of what we’ve done here all packed up nicely for you. Have fun!

flocking autonomous agents

A while ago I completed my Mathematics BSc from Bangor University. Its a course they’ve stopped doing now, but at the time, it was a most excellent thing. For those that are interested I did my final year dissertation on Flocking Autonomous Agents. That is, the order that appears when groups of supposedly simple agents congregate.

Its the sort of thing that you see in the wild with swallows flying about. Theres no master plan of where they’re going, nor any central command to the system. So how do these simple creatures manage to form cohesive flocks that can travel, with what seems, singular purpose?

It was just this question I proposed to answer in my dissertation (and I thought I did that rather well) as well as explaining the deceptively complex maths behind it.

Long story short. The system works like this:

  1. The individual agents are only aware of whats going on in an area directly around them (their vision range).
  2. The individual agents will try to adjust their direction to that of their neighbors.
  3. They won’t always do this right.
  4. There is 4th rule.

It seems almost counter-intuitive that the fact that a agent makes mistakes in their headings would actually help the flock as a whole but, after some rather intense mathematics, you can prove that, up to a point, it helps the system.

The crux of the matter is this – If there is group of agents flying together in sync and none of them ever makes a mistake as to their heading or position, their relative positions will conceivably never change.

If however they do make mistakes something wonderful happens.

Mistakes that have a negative impact on the flock as a whole get naturally canceled out while mistakes that bring the flock together are reinforced. Over time a very tight, cohesive, resilient flock is formed.

I even wrote a lovely java applet for it and ill post it up here when i figure out how to embed it properly. Ill even give you the source code, cos I’m nice like that.

phil

Archive for phil

hello the internets!

Hmm. I’m looking for some code. I could use Krugle but that would mean navigating away from this page and thats a real hassle. If only i could use the firefox search bar to search Krugle for me. Oh well. It doesn’t look like thats possible. Theres no extensions to do that.

But wait.

Fret no more. Phil Roche, programmer extrodinare, Irish guy, and proud owner of a very heavy duty laptop stand (and co-worker) has written a plugin for firefox. That busy little man. He even got a post on the Krugle blog for his troubles. (And rather suspiciously also just completed and external audit for them and got a $50 amazon voucher – bribing maybe?)

So if you want to read his original post, you can get it here. But don’t let him bask in it too much. Hes enjoying the extra traffic a little too much as it is.

1072

music

Archive for music

The Klein Four- Finite Simple Group

(of order two)

If I were somehow forced to write a song to woo a young math lady this is what it would be like.

Yes I know I’m a math nerd, but did YOU get all the maths jokes.

In case you really want to know, the lyrics are here too…

The path of love is never smooth
But mine's continuous for you
You're the upper bound in the chains of my heart
You're my Axiom of Choice, you know it's true

But lately our relation's not so well-defined
And I just can't function without you
I'll prove my proposition and I'm sure you'll find
We're a finite simple group of order two

I'm losing my identity
I'm getting tensor every day
And without loss of generality
I will assume that you feel the same way

Since every time I see you, you just quotient out
The faithful image that I map into
But when we're one-to-one you'll see what I'm about
'Cause we're a finite simple group of order two

Our equivalence was stable,
A principal love bundle sitting deep inside
But then you drove a wedge between our two-forms
Now everything is so complexified

When we first met, we simply connected
My heart was open but too dense
Our system was already directed
To have a finite limit, in some sense

I'm living in the kernel of a rank-one map
From my domain, its image looks so blue,
'Cause all I see are zeroes, it's a cruel trap
But we're a finite simple group of order two

I'm not the smoothest operator in my class,
But we're a mirror pair, me and you,
So let's apply forgetful functors to the past
And be a finite simple group, a finite simple group,
Let's be a finite simple group of order two
(Oughter: "Why not three?")

I've proved my proposition now, as you can see,
So let's both be associative and free
And by corollary, this shows you and I to be
Purely inseparable. Q. E. D.

Its possibly the most awesome math based love song I’ve hear all morning.

If you want, you can even download it. Isn’t that nice.

Finite Simple Group (or order two) – The Klein Four Group

Eleven saints

This song if from the accordion-aficionado Jason Webley, watch it through and by the end you’ll be singing along. Rather unusual to find a video like this that looks like it was actually made by cutting out bits of paper/(I don’t know – it might be in flash but i don’t think so).

If you really like the song, you can even download it. Now isn’t that nice.

GO – Jason Webley – Eleven Saints.

a new band to look out for

so while skimming over digg last night i stumbled across a cover of outkast’s Hey ya. Now to say this cover is excellent is not enough.

Its stunning, its magnificent. Its totally changed the song for me, and in my opinion at least, its better than the original by miles. So here’s that video from You Tube.

The band is called Obadiah Parker and its very hard to pin down exactly what their style is. The best way to get a sense of it is just to listen.

Apart from the cover of Hey Ya there is also a splendid cover of idoteque by radiohead. Do yourself a favour and give them 10 minutes of your time, you won’t regret it.

Even though i really dislike the whole myspace thing, if you want to check out a few of the other songs they do and even read their blog, check out their myspace page. Thankfully it has the default formatting.

Ill be ordering the EP at the first oportunity.

model rocket

Archive for model rocket

the maiden flight of Kandor One

Ok, so I’ve never done model rocketry before. This was my first attempt at it and my was it a good one.

Don’t ask me why I suddenly decided to buy a model rocket kit after years of wanting one but last week i did exactly that. I bought a starter kit from www.modelrockets.co.uk. It came with everything you need to start off and send something skyward, the base, the remote and of course the rocket, all in bits you understand. It was this one, if you’re interested. And coming in at under £20 you really can’t fault it.

I don’t know why I didn’t trust the pack. Maybe it was the lack of instruction that came with the pack (not the actual rocket – that came with detailed instructions on where to put all the bits, and even how to sandpaper down the fins). It was the equivalent of me handing someone a box with some some oddly shaped pieces of plastic, some metal bits and a pack of explosives and telling them they’ve got everything they need to make a working rocket.

But I guess I’m being too harsh. After about 15 minutes of playing around I got the whole thing into a configuration I was happy with – at least, I’d used all the pieces and everything seemed to fit together nice and tight.

So launch day rolls around and the final parts of the puzzle are assembled. Parts that previously were only placed together, are glued down, knots get gobs of glue on them and fins get sanded down to near aerodynamic perfection (no rough edges at least). And so a paint job is decided upon. A striking mettalic red, something that will stand out against the both the sky for the flight and the grass for the recovery. We decided on the launch site (a surprisingly large and out of the way field kind of place called the Vadre) – where even if it does all go terribly wrong the biggest worry is it landing in a pile of sheep poo. And we were on our way.

I really did expect the whole thing to just sit there on the pad, maybe smoke a bit and topple off its perch with a *pop* and that would be the whole spectacle over. But no. That was not to be. It shot up like it was born to be in the air.

985

Instead came a critic defying (my self included) amazing first flight. On the windless day it took the rocket to next to near 300 feet by my reckoning. And, not only that, but the parachute deployed perfectly, returning it within 100 yards of the launch pad. In fact it was nearly too close as I offered Byron £5 (Gemma rashly upped that to £50 soon after) if he could catch the thing on its decent. And he nearly did. (look close in the picture)

859

So, we reset the whole thing and in total launched it three times in a period of about 20 minutes. A most excellent spending of £20. So good in-fact that I have ordered some more rocket motors today, along with a more beasty staged rocket kit. Oh the fun we will have.

While mr. postman is bringing me the new bits and pieces you can check out the all the pictures we took that day here

Also, since the event we have posthumously named the rocket “Kandor One” with the hope of collecting a whole family of the beasties.

Much Rocket Love

mathematics

Archive for mathematics

Video Enhancement

I’ve got say it. At first I thought this was pretty cool.

Then I thought that theres almost no real use for it.

In the end I can see some limited use, but not to justify the amount of effort taken to do it. Sorry, hang on, you need to watch this first.

or watch it on vimeo.

Ok, so the gist of it is that you can use a few well placed high quality photographs to increase the resolution and dynamic range of low quality videos. Sounds great right?

Well, yes, but only when you think about the cases it uses. Basically tracking shots of static things, taken in low quality video, like the kind of video an average digital camera takes. So you then take a few still shots of the scene to boost the resolution.

Great, but just why would I do that? Almost the whole reason for taking quick videos like that is not to show a simple scene, but some action that you can’t get with a still shot.

So in review, I would give it about a B-, good effort, but honestly come on guys, not really that useful, though I don’t doubt some of the maths would be very interesting.

More on it here.

friendly numbers

This is in reponse to this comic.

So what are friendly numbers? Lets do this quick.

We need first to get define a divisor function over the integers, written σ(n) if you’re so inclined. To get it first we get all the integers that divide into n. So for 3, it’s 1 and 3. For 4, it’s 1, 2, and 4, and for 5 it’s only 1 and 5.

Now sum them to get σ(n). So σ(3) = 1 + 3 = 4, or σ(4) = 1 + 2 + 4 = 6, and so on.

For each of these n, there is something called a characteristic ratio. Now that’s just the divors function over the integer itself ( σ(n)/n . So the characteristic ratio where n = 6 is σ(6)/6 = 12/6 =2.

Once you have the characteristic ratio for any integer n, any other integers that share the same chacteristic are called friendly with each other. So to put it simply a friendly number is any integer that shares its characteristic ratio with at least one other integer. The converse of that is called a solitary number, where it doesn’t share it’s characteristic with anyone else.

1,2,3,4 and 5 are solitary. 6 is friendly with 28. ( σ(6)/6 = (1+2+3+6)/6 = 12/6 = 2 = 56/28 = (1+2+4+7+14+28)/28 = σ(28)/28.

You may be now be thinking the following:

  1. That’s all well and good, but what are they good for?
  2. Who cares?

So what are they good for?

I dunno. But it’s interesting no? Actually while on the face of it, it all seems quite straight forward it quickly becomes far more complex than you would think.

Some numbers are easily proved to be solitary. Other’s we know to be friendly. But my-o-my there are alot more we don’t know. I mean look. Here is the complete list of friendly numbers we know about. And I mean COMPLETE.

6, 12, 24, 28, 30, 40, 42, 56, 60, 66, 78, 80, 84, 96, 102, 108, 114, 120, 132, 135, 138, 140, 150, 168, 174, 186, 200, 204, 210, 222, 224, 228, 234, 240, 246, 252, 258, 264, 270, 273, 276, 280, 282, 294, 300, 308, 312, 318, 330, 348, 354, 360, 364, 366, 372

That’s it. What about 10, 14, 15, or 20? Don’t know. Infact it’s on the list of unsolved Mathematical problems at wolfram. Doubt there’s a cash prize involved but why not give it a go. It’s harder that it looks.

Wow.
Well done. You read all the way to the end. To give you a treat I present this lovely video. It’s a visualization of Lovely Head by Goldfrapp. Yes it’s got lot’s of maths in. No it doesn’t have anything to do with friendly numbers.

Or even better, watch it in hd.

If you were wondering. No. I didn’t just get this all off the top of my head. You can read more about friendly numbers at wolfram, or wikipedia, and here is where the full list of friendly numbers came from. Personally I find amicable pairs more interesting but then, who really cares about that?

Math, not Meth

282501676 3f64746a9c

 

Found here, on Flickr.

Happy Pi Approximation Day!

July 22nd (22/7) is Pi Approximation Day!. You know like 22 / 7 = 3.1428…

Isn’t that awesome?

You know it is.

(on a side not, I actually missed it by 2 days, so if we’re being honest it’s more like 24/7, or 3.4285… – but thats not as catchy is it?)

Physical theories as women

Originally by Simon Dedeo

0. Newtonian gravity is your high-school girlfriend. As your first encounter with physics, she’s amazing. You will never forget Newtonian gravity, even if you’re not in touch very much anymore.

1. Electrodynamics is your college girlfriend. Pretty complex, you probably won’t date long enough to really understand her.

2. Special relativity is the girl you meet at the dorm party while you’re dating electrodynamics. You make out. It’s not really cheating because it’s not like you call her back. But you have a sneaking suspicion she knows electrodynamics and told her everything.

3. Quantum mechanics is the girl you meet at the poetry reading. Everyone thinks she’s really interesting and people you don’t know are obsessed about her. You go out. It turns out that she’s pretty complicated and has some issues. Later, after you’ve broken up, you wonder if her aura of mystery is actually just confusion.

4. General relativity is your high-school girlfriend all grown up. Man, she is amazing. You sort of regret not keeping in touch. She hates quantum mechanics for obscure reasons.

5. Quantum field theory is from overseas, but she doesn’t really have an accent. You fall deeply in love, but she treats you horribly. You are pretty sure she’s fooling around with half of your friends, but you don’t care. You know it will end badly.

6. Cosmology is the girl that doesn’t really date, but has lots of hot friends. Some people date cosmology just to hang out with her friends.

7. Analytical classical mechanics is a bit older, and knows stuff you don’t.

8. String theory is off in her own little world. She is either profound or insane. If you start dating, you never see your friends anymore. It’s just string theory, 24/7.

The e^x joke

If you don’t get it never mind, but trust me, its funny.

The cocky exponential function ex is strolling along the road insulting the functions he sees walking by. He scoffs at a wandering polynomial for the shortness of its Taylor series. He snickers at a passing smooth function of compact support and its glaring lack of a convergent power series about many of its points. He positively laughs as he passes |x| for being nondifferentiable at the origin. He smiles, thinking to himself, “Damn, it’s great to be ex. I’m real analytic everywhere. I’m my own derivative. I blow up faster than anybody and shrink faster too. All the other functions suck.”

Lost in his own egomania, he collides with the constant function 3, who is running in terror in the opposite direction.

“What’s wrong with you? Why don’t you look where you’re going?” demands ex. He then sees the fear in 3’s eyes and says “You look terrified!”

“I am!” says the panicky 3. “There’s a differential operator just around the corner. If he differentiates me, I’ll be reduced to nothing! I’ve got to get away!” With that, 3 continues to dash off.

“Stupid constant,” thinks ex. “I’ve got nothing to fear from a differential operator. He can keep differentiating me as long as he wants, and I’ll still be there.”

So he scouts off to find the operator and gloat in his smooth glory. He rounds the corner and defiantly introduces himself to the operator. “Hi. I’m ex.”

“Hi. I’m d / dy.”

when to add milk to coffee

Heres the situation – you have a hot black cup of coffee. You like you’re coffee hot, but you also like it with milk. You are not going to be drinking the coffee right away, so the question becomes – should you add the milk now or just before you drink it in order to have the coffee at its hottest.

Enter maths.

Lets make some initial conditions and normalize our temperature scale to room temp., ie. 0 degrees = room temperature.

Now assuming this is an ordinary mug the coffee is in, nothing special will happen in the cooling. Thus we can assume that the coffee will cool at a proportional rate to the temperature difference between it and the room temp. Further to that, the amount of milk added is small enough to not affect that rate.

Some quick calculus will show how the coffee temperature decays exponentially over time, ie.

eqn6239

also,

eqn6239 2

We can assume that the difference between the specific heats of the coffee and milk are negligle, hence if we add milk at temperature M, to coffee at temperature C, the resulting mix has a temperature of aM+bC, where a and b are constants between 0 and 1, with a+b=1. (ie. the a and b are the relative volumes of milk and coffee of the final volume)

So, lets assign some variables.

We can denote the starting coffee temperature by C, and the starting milk temperature by M. Hence –

eqn6239 3

Thus, the difference is d=(1-l)aM. As l<1 and a>0, so now we need to worry about whether M is positive or not.

eqn6239 4

Case 1. Warm milk – you should add the milk just before you are to drink the coffee.

Case 2. Room Temperature Milk – It really doesn’t matter when you add the milk. Do it now, do it later, I really don’t care.

Case 3. Cold milk – its best add this right when the coffee gets to you.

To figure all this out without even touching any of the maths all you need to do (as with so many things in maths) is to consider the extreme examples.

For instance, lets assume you’ve got a coffee at room temperature and the milk you are to add is either really hot or just above freezing. So it becomes obvious that you should add the hot milk later, the cold milk early.

Further variations

For this entire problem we have assumed that the milk’s temperature is constant throughout, up until you add it to to the coffee. What happens if this isn’t the case? ie. you can let the milk stand at room temperature.

For this, let r = the exponential decay constant for the milk’s container.

So now we can add the acclimated milk later, giving –

eqn6239 5

This gives us a whole slew of new cases.

r<l: The milk pot is larger than your coffee cup.
(E.g, it really is a pot.)
r>l: The milk pot is smaller than your coffee cup.
(E.g., it’s one of those tiny single-serving things.)
M>0: The milk is warm.
M<0: The milk is cold.

If you’re interested in the derivation you must be a really sad individual, so lets just jump to the end and the conclusions:

Add warm milk in large pots LATER.
Add warm milk in small pots NOW.
Add cold milk in large pots NOW.
Add cold milk in small pots LATER.

Of course, observe that the above summary holds for the case where the
milk pot is allowed to acclimate; just treat the pot as of infinite
size and the problem goes away. Marvelous.

The Integration of Pretty Little Polly Nomial

Once upon a time, (1/T) pretty little Polly Nomial was strolling through a field of vectors when she came to the edge of a singularly large matrix. Now Polly was convergent and her mother had made it an absolute condition that she never enter such an array without her brackets on.

Polly, however, who had changed her variables that morning and was feeling particularly badly behaved, ignored this condition on the grounds that it was insufficient and made her way in amongst the complex elements.

Rows and columns enveloped her on all sides. Tangents approached her surface. She became tensor and tensor. Quite sudenly, 3 branches of a hyperbola touched het at a single point. She oscillated violently, lost all sense of directrix, and went completely divergent. As she reached a turning point, she tripped over a square root protruding from the erf and plunged headlong down a steep gradient.

When she was differentiated once more, she found herself, apparently alone, in a non-Euclidean space. She was being watched, however. That smooth operator, Curly Pi, was lurking inner product.

As his eyes devoured her curvilinear coordinates, a singular expression crossed his face. Was she still convergent, he wondered. He decided to integrate improperly at once. Hearing a vulgar fraction behind her, Polly turned around and saw Curly Pi approaching with his power series extrapolated. She could see at once, by his degenerate conic and his dissipated terms, that he was up to no good.

“Eureka,” she gasped.

“Ho, ho,” he said.

“What a symmetric little polynomial you are. I can see you are bubbling over with secs.”

“Oh, sir,” she protested. “Keep away from me. I haven’t got my brackets on.”

“Calm yourself, my dear,” said our suave operator. “Your fears are purely imaginary.”

“I, I,” she thought, “perhaps he’s homogeneous then.”

“What order are you?” the brute demanded.

“Seventeen,” replied Polly. Curly leered.

“I suppose you’ve never been operated on yet?” he asked.

“Of course not!” Polly cried indignantly. “I’m absolutely convergent.”

“Come, come,” said Curly, “let’s off to a decimal place I know and I’ll take you to the limit.”

“Never,” gasped Polly. “Exchlf,” he swore, using the vilest oath he knew.

His patience was gone. Coshing her over the coefficient with a log until she was powerless, Curly removed her discontinuities. He stared at her significant places and began smoothing her points of inflection. Poor Polly. All was up. She felt his hand tending to her asymptotic limit. Her convergence would soon be gone forever. There was no mercy, for Curly was a heavyside operator. He integrated by parts. He integrated by partial fractions. The complex beast even went all the way around and did a counter integration. What an indignity to be multiply connected on her first integration. Curly went on operating until he was absolutely and completely orthogonal.

When Polly got home that night, her mother noticed that she was no longer piecewise continuous, but had been truncated in several places. But it was too late to differentiate now. As the months went by, Polly’s denominator increased monotonically. Finally, she went to L’Hopital and generated a small but pathological function which left surds all over the place and drove Polly to deviation.

The moral of our sad story is this:

If you want to keep your expression convergent, never allow them a single degree of freedom.

krugle

Archive for krugle

hello the internets!

Hmm. I’m looking for some code. I could use Krugle but that would mean navigating away from this page and thats a real hassle. If only i could use the firefox search bar to search Krugle for me. Oh well. It doesn’t look like thats possible. Theres no extensions to do that.

But wait.

Fret no more. Phil Roche, programmer extrodinare, Irish guy, and proud owner of a very heavy duty laptop stand (and co-worker) has written a plugin for firefox. That busy little man. He even got a post on the Krugle blog for his troubles. (And rather suspiciously also just completed and external audit for them and got a $50 amazon voucher – bribing maybe?)

So if you want to read his original post, you can get it here. But don’t let him bask in it too much. Hes enjoying the extra traffic a little too much as it is.

firefox

Archive for firefox

hello the internets!

Hmm. I’m looking for some code. I could use Krugle but that would mean navigating away from this page and thats a real hassle. If only i could use the firefox search bar to search Krugle for me. Oh well. It doesn’t look like thats possible. Theres no extensions to do that.

But wait.

Fret no more. Phil Roche, programmer extrodinare, Irish guy, and proud owner of a very heavy duty laptop stand (and co-worker) has written a plugin for firefox. That busy little man. He even got a post on the Krugle blog for his troubles. (And rather suspiciously also just completed and external audit for them and got a $50 amazon voucher – bribing maybe?)

So if you want to read his original post, you can get it here. But don’t let him bask in it too much. Hes enjoying the extra traffic a little too much as it is.

enigma

Archive for enigma

Enigma 1438 – Soccer Stats

set by Susan Denham

Question

In a league of five teams, each team plays each of the others once a season. Below is a league table at the end of last season. Three of the numerical entries are incorrect.

Whats are the scores in Arnsley’s four games?

Won Drawn Lost Goals for Goals against
Arnsley 2 1 1 2 2
Boldham 3 1 0 2 1
Cleeds 1 3 0 1 0
Drochdale 1 2 1 1 1
Erby 1 0 3 1 3

Enigma 1437 – Two Squared

set by Richard England

Question

Harry and Tom each replaced each asterisk with a digit in such a way that the three numbers that could be read across and the two numbers that could be read down were five different perfect squares each of which consisted of three different digits (with no leading zero). Tom did not use any of the 3-digit squares that Harry used.

Which three 3-digit squares (of three different digits with no leading zero) did neither of them use?

shape1

Answer

First lets get all the 3 digits perfect squares (of which there are 13). They are as follows:

169, 196, 256, 289, 324, 361, 529, 576, 625, 729, 784, 841, and 961 (corresponding to squares of integers 13 – 31)

We could just put these numbers in the format and test them, so that’s what I did first.

After some trail and error I came upon a solution.

soln1

These two worked fine but wait. I turns out there are three possible ways of arranging the numbers.

soln2

and

soln3

After comparing all three of these we can see that they only use the same 10 squares out of the thirteen. So the three digits that the were not used turned out to be 324, 729, 784. And just for the hell of it, here’s a graphic for that too.

missing

Oh the fun. We can only hope they’re going to get harder some time soon.

(On a side note, as I don’t always get the time early in the week to solve the puzzles as they are set so instead of holding back posting the complete question/solution when I have, I’m going to post up the question when I get them – usually Thursday/Friday – and update them when I’m happy I have a solution. If anybody fancies a crack at them please feel free.)

Enigma 1436 – One More Step

Here’s this weeks problem:

Consider the following set of numbers:

1, 3, 7, 13, 21…

Send in the following:

a) The 600th member of the series

b) A member of the series above the first with less than five digits which is a perfect cube

c) A member of which is a five-digit palindrome which can also be read as a binary number

d) The smaller of the two consecutive members which are 1000 apart

Oh the joys. Yet another one that can be solved with a brute force method.

First we have to find out an how the sequence is generated. Looking at it carefully we can see it increments first by 2, then 4, 6, 8… To generate this sequence we do simply this: (n-1) * n + 1

A – 600th member

To calulate this just set n to be 600. This gives us: 599 * 600 +1 = 359401

B – perfect cube first with less than 5 digits.

Perfect cubes is simply the third power of an integer. To solve this we need to get all the perfect cubes with up to 4 digits and compare them against the members of the series. Lets do it with some php. First the cube array.

$cubesArray = array(); for($a = 2; $a <= 21; $a++) { $cube = $a*$a*$a; array_push($cubesArray,$cube); }

We know that the cube of 21 is the largest perfect cube with less than 5 digits so we only need the cubes up to there. No we need the corresponding array for the series and then loop through them and compare.

$seriesArray = array(); for($b = 1; $b <=600; $b++) { $value = ($b-1) * $b+1; array_push($seriesArray, $value); } foreach ($cubesArray as $currentCube) { if (in_array($currentCube, $seriesArray) { echo ‘Perfect Cube in Series: ‘.$currentCube; break; } }

From this we get the answer to be 343

C – The palindrome

This is relatively simple. The two contraints of it being the number being a palindrome, 5 digits and being able to be read as a binary leave us with only 4 options, 10001, 10101, 11011, 11111. Of these, a little bit of trial and error, leaves us with the answer as 10101. Simple

D – consective 1000 apart

Oooo. Harder. No, well not really. We can do this again with a simple bit of php.

for ($c = 0; $c <=599; $c++) { if(($seriesArray[$c] + 1000 == $seriesArray[$c+1]) { echo ‘the lowest consecutive member is: ‘.$seriesArray[$c]; break; } }

This spits out the answer 249501.

So to recap my answers are as follows:

  • a) 359401
  • b) 343
  • c) 10101
  • d) 249501

Go Maths!

Enigma 1435 – A good sign

Like many people I read the New Scientist on a weekly basis. One of the things that annoys me is the weekly (usually) maths based puzzle Enigma.

This week’s puzzle is thus:

The distance between any pair of the villages Aville, Bestown, Chipping and Dreem is a whole number of miles. A signpost in each village gives the distances to the other villages, but each sign has a different number of correct distances. The signs are as follows:

From Aville

  • Bestown 7
  • Chipping 9
  • Dreem 9

From Bestown

  • Aville 8
  • Chipping 7
  • Dreem 9

From Chipping

  • Aville 8
  • Bestown 9
  • Dreem 7

From Dreem

  • Aville 7
  • Bestown 8
  • Chipping 9

I recently did a round walk, of less than 30 miles, visiting each village and ending back where I started.

List (in the order AB, AC, AD, BC, BD, CD) the distances between the villages.

This appears to be a straight forward Traveling Sales Person problem, where the person walking around travels along a simple Hamiltonian cycle. (There are a number of assumptions about the problem here – the wording of “I did a round walk,…, visiting each village..” is quite ambiguous, so a number of assumptions are necessary)

Starting with the 6 bidirectional pairs (ie. A>B == B>A), we can see that when written out no two values from the sign posts are the same. From the question we can deduce that while its impossible for both to be correct, both CAN be incorrect.

From the fact that the 4 signs can have 0,1,2, or 3 errors we can see that there are a total of 6 errors across the signs. 6 of the 12 distances are incorrect.

As the hamiltonian cycle must be LESS THAN (not less than or equal to) the only two ways to do this with the possible values from the 6 remaining values are with either a cycle of 7, 7, 7, 7, or 7, 7, 7, 8. Any more and the total becomes 30.

By elimination, we get the following values:

  • A-B = 8
  • B-C = 7
  • C-D = 7
  • D-A = 7

Once we’ve got these values all we need to do is figure out the remaining diagonal values that will satisfy the 0,1,2,3 errors condition. After testing we get the values of A-C=8 and B-D=9 that work with all the conditions.

From this, we have Aville with 3 errors, Bestown 0 errors, Chipping 1 error and Dreem 2 errors.

To get the final requested solution in the order AB, AC, AD, BC, BD, CD, we get the end solution –

8, 8, 7, 7, 9, 7

Or if you wish, here’s a diagramatic layout of the towns.

ghdjs

Oh what fun. Will this become a regular feature? Who knows? Not me. All depends if I can do next weeks really. Until then.

comics

 

Archive for comics

A Flowfield Thankyou

This is just too awesome. Thus in response, I have made this.

flowfield

Thanks Adam!

embarrassment

embarrassment

 

This is for sherski on vimeo.

its not my dream

dreamcatchers

by Demitri Martin

yourspace

myspace

i like to push other things down stairs too

down stairs

literary techniques

5th person

by Demitri Martin

no seriously, not a thing

deaf people

ive always liked midgets in ballgowns

elegant jokes

code

Archive for code

How hard could it be?

Here is an excellent article by Joel Spolsky on 5 ways to make a project fail.

I happen to particularly agree/like this from point 5:

Software development takes immense intellectual effort. Even the best programmers can rarely sustain that level of effort for more than a few hours a day. Beyond that, they need to rest their brains a bit, which is why they always seem to be surfing the Internet or playing games when you barge in on them.

So next time you see me playing a game of surfing the of internets, give me a break, it takes immense intellectual effort. Honest it does.

Laws of Technology

Clarke’s Third Law: Any sufficiently advanced technology is indistinguishable from magic.

Benford’s Corollary: Any technology distinguishable from magic is insufficiently advanced.

Raymond’s Second Law: Any sufficiently advanced system of magic would be indistinguishable from a technology.

Sterling’s Corollary: Any sufficiently advanced garbage is indistinguishable from magic.

Langford’s application to science fiction: Any sufficiently advanced technology is indistinguishable from a completely ad-hoc plot device.

… has an invalid qualified name

I like to google error messages that I encounter, as any good developer should. I googled the message “… has an invalid qualified name.”, and I got what has to be one of the most helpful reference messages ever:

XML-21017: invalid qualified name: string
Cause: The qualified name passed to a DOM function was invalid.
Action: Fix the qualified name.

Wow. Thanks. I need to fix the qualified name now do I? Thats really helpful. You really are a helpful reference aren’t you?

Google Checkout in the UK

After running successfully in the US for a number of months Google Checkout has now been opened up to UK sellers. While examining the system with a view to integrate it with the Karova Store e-commerce framework I ran up this overview of the features, the good points, the bad and the everything else.

Its only a very high level overview, but if you’re interested in it and want to quickly get an idea of what Google Checkout is and what it can do you can find it here.

If you don’t feel like reading it, I’ll sum it up. It’s good. And the engineer’s have clearly been working hard to aid easy integration from a developers standpoint. The api’s all seem very well rounded and intuitive, so much so I’m actually looking forward to getting some time free to work on the full integration with Karova Store 2.x.

Read Integrating Karova Store with Google Checkout.

pretty sweet internet, pretty sweet

filehippo

One of the problems with all this computer lark is how fast things go out of date. Take for instance Firefox. With the amount of extensions I use almost every time I start up there is a slew of update to my extensions. I like this. This is good. It keeps things up to date, and running smoothly.

What I don’t like is things that don’t automatically update, or at least don’t give me the opportunity to do it automatically. “A newer version of this software is available”. Fine, but don’t make ME go and get it.

But here’s a solution. A nifty little program from File Hippo, imaginatively called Update Checker.

Its a tiny little program that you can get here. It just quickly runs through everything installed on your system and checks them against the most recent versions. If it finds any it displays them in a browser window with links to the updates. It even does beta updates if you happen to be that way inclined.

How lovely. While its not a thing I would use on a daily basis, maybe scheduling it to run every week or so would be quite nice. If you find it of use let me know. (On my first run I had 20 updates – beat that)

strange flvplayer problems

Playing around with flv player yesterday I came across an odd problem.

Using flvplayer to play a flv file on my machine worked fine. As soon as I uploaded it to a server (infact in this case it was my localhost – but same thing really) it no longer played.

After all sorts of searches for phrases like “FLVPlayer not streaming video”, “flv not streaming online”, “problems streaming flv video”, “im bored and slightly hungry”, “why isn’t this working”, “what is the answer mr google? tell me!”, “flv player flv video streaming problems” and so on, I came across an odd thing. This is a well known problem .

Under IIS 6.0, microsoft changed the way they handle flv files. Heres the article by adobe on how to fix the problem with iis. The way to fix is to add the .flv extension as a MIME type on iis.

The way I found to do this best (as it was on my local server) was to go to IIS and then the Default Web Site, right click on properties, then go to the HTTPHeaders tab. On the bottom click on File Types and in there add the following:

Associated Extension: flv

Content Type (MIME): flv-application/oclet-stream

For all intents and purposes, this should of fixed the problem.

But it didn’t.

Here’s the markup I’m using for embeding:

<object data=”mcpassets/flvplayer/flvplayer.swf” type=”application/x-shockwave-flash” height=”600″ width=”600″>

<paramvalue=”file=assets/video/pete.flv&image=assets/video/pete_thumb.jpg” name=”flashvars” />

<param name=”movie”value=”mcpassets/flvplayer/flvplayer.swf?file=assets/video/pete.flv&image=assets/video/pete_thumb.jpg” />

<object>

Now while this showed the thumbnail, the