### Monty Hall anyone?

#### Ξ November 23rd, 2012 | → 1 Comments | ∇ Coding, Geeky, Maths, Programming, Research|

I won’t detail the so called ‘Monty Hall Problem‘ here: if you don’t know about it already, you’ll find more detail (than you’d probably like) here.

Anyway, the MHP is one of my favourite Conditional Probability problems (I’m a lecturer in this branch of mathematics) as it’s a nice example of how computing – via a Monte Carlo Simulation - is useful in testing such a hypothesis (by the way, Monty has no relation to Monte).

And so .. to code! Now, I’m no expert in Python, and so please feel free to abbreviate/re-write/deride this effort at writing a simulation: I’m using Python with a version >3 here.

As it is, this effort  plays 10,000 ‘games’ – and its default strategy is that the player always chooses to swap doors. To change that to having the player stick with their original door, comment out this line by prefixing it with a ‘#’.

`    (playerDoor, ) = list(set(doors) - set([playerDoor, hostDoor])`

Here’s to code (copy it to a file called monty.py. Once you’ve python installed, run it using python monty.py)

`import random`
`def playGame(carsWon):`
`    doors = [1,2,3]`
`    carDoor = random.choice(doors) playerDoor = random.choice(doors)`
`    # The host opens a different door to reveal a goat (always able to do this).`
`    hostDoor = random.choice(list(set(doors) - set([carDoor, playerDoor])))`
`    # ~~~~ To stick, just comment out the next line of real code with a #`
`    # ~~~~ Player chose to swap doors.`
`    (playerDoor, ) = list(set(doors) - set([playerDoor, hostDoor])`
`    if playerDoor == carDoor: carsWon += 1`
`    return carsWon`
`# The program's entry point is here.`
`carsWon = 0`
`for games in range(1000): carsWon = playGame(carsWon)`
`print("The player won the car " + str(round(carsWon / (games / 100))) + "% percent of the time.")`

I must say that, even though I know more or less nothing about Python, it’s a succinct language.

Anyone fancy coding this in something like ML, Haskell or Scala?  I’m too embarrassed to post my versions here!

### Editors!

#### Ξ January 10th, 2011 | → 0 Comments | ∇ Mumble|

I’ve been pondering editors lately, and how crude they still are.  For example, that all the web authoring tools that I know of/use essentially require you to textually specify your css styles.  Why can’t you, say, colour the color[sic] of some style in, um, the colour you’d like?

E.g., h1 { color; } instead of using #f5a323 or whatever?

And I’m sure there’s lively debate on this somewhere – why use different syntax in css files and html files? Or, if you really have to, why not have your wizzy development tool manage that for you, e.g., you write <h1> in your stylesheet, and *it* converts this to h1{color:#ff0000; } - or actually, why not just write h1?  Or why edit a stylesheet at all – create a truly intelligent editor that you just *write* in!  You use whatever tools it provides to create your page(s), and *it* not *you* works out what’s a style and should go in your css.  For example, most web-developers don’t use tables any more – they use divs instead. Ok, why not *still* insert a table in your document, and have your intelligent editor implement it as a set of divs?  It seems to me that if you have to edit the code that the tools aren’t up to the job (remember, you’re only creating a document for goodness sake)!

Shouldn’t web-development (page design/layout) be as simple as Word Processing is in Word? Think about it – it’s been a very long time since we’ve had to mark up our documents (goodbye Wordstar), and I wonder how long it will be until we find ourselves doing the same for the web.

Maybe it’s me, and I’m just not using the tools correctly? For example, I note that Microsoft’s Expression Web 4 has, in design view (html or wysiwyg), extra panels to create and apply styles – and it’s got a wysiwyg look.  But, you know what; I reckon if I start playing about with those that it’ll end in grief!  An ‘old dog’ indeed – or perhaps a wise one?

Of course, one of the problems is the browser!  As in how each does its own thing when it comes to layout … you can see how Word – being in sole control of how ‘Word things look’ has a relatively easy time of it.  So, before I get back to editors, this leads me on to another question that’s been nagging me for years: why don’t we have one rendering engine?

Imagine the likes of Microsoft, Google Mozilla getting together to jointly develop a single rendering engine; and not just them – why not have that an open group, that any interested party could join.  The result and aim would be to create a single parser and rendering engine that renders exactly the same on devices with the same capabilities (colour depth, pixel count etc).  I’ve never understood why this hasn’t (yet) happened – I mean, haven’t you seen all that …

<!–[if IE 6]>
<script src=”/javascript/ie6.js” type=”text/javascript”></script>
<![endif]–>
<!–[if IE 6]>
<![endif]–>
<!–[if IE 7]>

<![endif]–>

… and that’s just for Microsoft!  Doesn’t it a) annoy you, b) cause you a lot of work?  Fact: there’s over 3.5 million Google results for browser detection

And anyway – why do the likes of Google, Microsoft and Mozilla (want to) spend gazillions of dollars doing their own thing, and then give the product away for free?  Yes, competition is great, but it’s not (currently) like Word – a cash cow product.  Why not join forces – give us a single standard browser, save yourselves heaps of cash, and make web development much simpler?

But back to editors, as it’s not just web editing tools that annoy me. I spend most of my time editing code – *real* code; you know, C++ etc. Now, here’s a question – why can’t I put what’s referred to as ‘rich content’ in my code?  For example, say you’ve coded up an algorithm that you first designed and then documented using a mixture of pictures, words and perhaps a small test harness.  Why shouldn’t you embed these into your live code – so that the documentation is stored with the actual implementation?  Could be there as a link; could optionally be unfolded in-line … a picture is worth a thousand words!

We’ve only recently got a folding editor in Microsoft’s Visual Studio – and I remember seeing my first one of those over 25 years ago.  How long before code editors catch-up to the likes of Microsoft’s Word: insert a table, picture, footnotes, … whatever makes your own and your colleaques’ life easier.

### Wolfram|Alpha

#### Ξ June 5th, 2009 | → 1 Comments | ∇ Software, Technical, Writing|

Thought it might be interesting to post these here. A two part article on Wolfram|Alpha I did for Computer Weekly [WARNING: may contain traces of coin tossing references].

Here’s a pdf of the first bit, and here’s a link to the edited version on Computer Weekly’s website.

And – wait for it …

Here’s a pdf of the second bit, and here’s a link to the edited version on Computer Weekly’s website.

Just in case you do compare the version, I should add that I did some minor edits after they were sent in.

### Not Much Use – IMHO!

#### Ξ May 14th, 2009 | → 1 Comments | ∇ Geeky|

I’ve been doing a little free web-development for some pals of mine, and, in the course of that, trying to get their website towards the top of all search-engines’ results.

So I was interested when a few days ago they had a call from a company that claimed that given a few keywords, they could guarantee to get them at the top of Google’s search results.

Hmmm, interesting!

When I told my pals that I doubted the credibility of such a claim [I got starry-eyed stares when I tried to explain to them the why of this], I thought I’d best have a look at what this company was offering.

In a nutshell, this company has got a Google AdWords account, and in using it, they will, for a few pounds, place you at the top of a Google search – you know, in those ‘Sponsored Link’ bits.

Ok, so what’s the problem with that?

1.

Well they’re charging £20 per month – which is just enough to have most people say ‘well it’s not that much’ [and sign-up], yet either over or under what placing a top-result will actually cost you.

If you don’t know, Google ads ‘pay’ [Google] and ‘cost’ [you] whenever someone clicks them.  How much?   It depends upon a figure that you’ll have to agree with Google [it depends upon other bidders], and that fits within your budget – so here we’re talking about £20 per month apparently.

So what if you spend all your budget?  Well, you disappear from the results … rather, you slide to the place where Google’s PageRank algorithm would normally place you [which may be nowhere of course!]

So this company hopes that to place you will cost maybe a penny per click, and that for your 20 quid they’ll have some left over at the end of the month to pocket for themselves [that’s 2,000 people clicking through - so they probably will!].  But what if you go ‘over budget’?   Well, I assume they’ll either get you to stump up a bit more, or simply hope that you don’t notice your sudden disappearing act!

2.

Well, there must be a lot of people that do, because that’s Google main source of revenue I believe!

Personally however, I rarely click them – for one thing, they’re mostly sat off to the right-hand side of the search results, so I don’t see them [I assume that the best payers are the ones that appear at the top of the search results – rather than towards the right-hand side].

But the main reason I don’t click them is because Google’s PageRank works very well, i.e., websites that rank highly via PageRank are normally worth looking at – as they’re effectively being voted for by others that link to them [see the link I just used above - well, according to Google, I've just voted for the webpage that explains PageRank].   However, is that true when someone pays to get themselves at the top of the results?  Probably not!  After all, if they were actually first-rate – worth looking at – wouldn’t they get there by themselves – through their own merit, osmosis – call it what you will? I think so.

The result is that the more savvy person will often not rate/trust a paid-for link – or at least not as much as one that makes it to the top through its own merit.

3.

Well, maybe lots of people/maybe no one:

You’ll see it if:

1. the paying customer’s monthly budget hasn’t been used up when you conduct your search;
2. IF – and only if – you use Google!

Yup – no one will see it it they don’t use Google – perhaps they use Yahoo, or some other search-engine [Ask.com, A9.com, Live.com, …] – no-Google = no-Where to be seen.

### More Probability – HTH vs. HTT

#### Ξ May 8th, 2009 | → 5 Comments | ∇ Maths, Oxford|

Imagine tossing a fair coin successively, and waiting until the first time a particular pattern appears; say HTT. For example, if the sequence of tosses was HHTHHTHHTTHHTTTHTH, the pattern HTT would first appear after the 10th toss.

Ok, now let’s take two such patterns – HTT and HTH.  Given both these sequences, and a lot of trials [where you conduct this, "it first appears when" experiment, and then average the number of tosses], is it more likely that you’ll:

• hit HTT in less tosses than HTH;
• hit HTH in less tosses than HTT;
• find that the number of tosses is the same?

Most people [many mathematicians amongst them] will pick the third option.  Surely, any such pattern is equally likely to show up in some yet to be discovered average number of tosses!

Actually, it’s not the case – that they’re equally likely. In reality the average number of tosses required to see HTH is 10, whilst for HTT it’s 8! How can that be???

Let’s see why.

Note that HTH overlaps itself, i.e., if you got HTHTH you’ll find that you’ve got two occurrences of the pattern in only five tosses, i.e., HTHTH and HTHTH. Ah, so doesn’t this sound like HTH is more likely then, rather than the other way around?

Well, with HTT there isn’t such an overlap – and it turns out – perhaps unintuitively – that that’s important; in a way that leads to HTH‘s downfall. So, let’s run a couple of experiments to see how this works.

Let’s go looking for HTH

Best scenario:

 Toss Result Comment H 1st token in our pattern excellent start! T 2nd token quite excited! H 3rd token We won!

Second best scenario:

 Toss Result Comment H 1st token in our pattern excellent start! T 2nd token quite excited! T Bugger! Now we’ll need to continue tossing the coin until we see an H; as that’s the first token in our sought-after sequenc

Now let’s go looking for HTT

Best scenario:

 Toss Result Comment H 1st token in our pattern excellent start! T 2nd token quite excited! T 3rd token We won!

Second best scenario:

 Toss Result Comment H 1st token in our pattern excellent start! T 2nd token quite excited! H/H Bugger! However, and this is the important bit, at this stage we don’t need to toss the coin again in order to get to find our starting token – we just threw it – an H!

If you doubt any of this, here’s a little simulator I wrote [CoinToss.zip contains CoinToss.exe].

### XBox 360 Networking/Internet Access Made Easy

#### Ξ May 3rd, 2009 | → 4 Comments | ∇ Geeky, Microsoft, Mumble, Rant|

I hate gaming/gamers!  Probably because A) I can’t see the point [read a book, go for a walk, ...], and B) because two people I [thought I] knew very well are very sadly addicts – one for The Sims [or practically anything else that might distract them from normality/life], and the other for the World of Warcraft [where she's a kiss-ass Elf, or some such shite!].  Oh, and C), my twelve-year-old son also plays too much!  Sad individuals indeed.  I truly can’t see the point.

Anyway, rant over, my son received a one month’s free trial on XBox [Saddoes] Live – or some such thing – and asked me if I could get his XBox 360 to connect to the Internet.  As he’s in a room where there’s no wired network point, this meant doing it via a wireless connection.

So, on checking out the various sockets on the back of the 360 box, I tried connecting the thing using a LinkSys USB wireless adapter I had laying around. It didn’t work, and upon further reading, I’m led to believe that one requires a special Microsoft adapter.

Now for the good news … if you’ve a wireless laptop, that also has a wired network-interface, there’s a workaround:

1. Connect your laptop to the Internet, via its built-in wireless;

2. Connect your XBox to your laptop, via a standard network cable [one is supplied with an XBox 360];

3. Bridge the laptop’s wired and wireless connections.

So, here’s the steps I went through on my ThinkPad [with XP installed]:

1. Boot/connect the machine to the network, via its wireless;

2. Connect the XBox to the ThinkPad’s wired network interface using a standard network cable;

3. Open your laptop’s Network Connections [Start | Control Panel | Network Connections];

4. Select both the wireless and wired connections;

5. Right-click on the selected connections, and select Bridge

Here’s the result:

And that was it:  son-networked, playing even more games … hmmmmm – did I do the right thing?

#### Ξ April 26th, 2009 | → 0 Comments | ∇ Coding, Geeky, Software|

There are a few websites that really piss me off – in that I cannot get Firefox to remember my username/password on them.  Ok, I understand why they’ve taken steps to prevent one from doing so, but, as I’m quite confident that I’ve secured my saved passwords, it pisses me off.

Anyway, here’s how to fix the ‘problem’.

1. Locate Firefox’s installation folder. Normally that’s C:\Program Files\Mozilla Firefox

2. Navigate to the components folder.

3. Open nsLoginManager.js in an editor.  As Notepad won’t do really, do this instead [if you've a proper editor, just go to step 4]:

3a) Select  Start | Run

3b) Enter cmd <enter or Ok>

3c) type cd C:\Program Files\Mozilla Firefox\components <enter>

3e) Go to step 4.

4. Find this:

```    /*
* _isAutoCompleteDisabled
*
* Returns true if the page requests autocomplete be disabled for the
* specified form input.
*/
_isAutocompleteDisabled :  function (element) {
if (element && element.hasAttribute("autocomplete") &&
element.getAttribute("autocomplete").toLowerCase() == "off")
return true;

return false;
},```

5. Change it to this:

```    /*
* _isAutoCompleteDisabled
*
* Returns true if the page requests autocomplete be disabled for the
* specified form input.
*/
_isAutocompleteDisabled :  function (element) {
return false;
},```

6. Save the file [if you're following the 3x) steps above, select File | Exit, and when asked if you want to save the edited file, answer Yes.  To close the command prompt, enter exit <enter>].

Note that you might first have to change the file’s security permissions to do this [you DO if the save fails].  E.g., in Vista I had to A) right-click on the file [e.g., in Explorer] B) select Properties | Security. B) select Edit. C) select your username, D) change the persmissions to include Write access.

And you’re done – either start, or close/re-start Firefox!

n.b. If you want to know ‘why’ this works, see http://www.w3schools.com/tags/html5_input.asp – then autocomplete, disabled

Basically, by making these changes you’re saying that any element may be ‘auto completed’; so if an input field on a page includes <input autocomplete=”off” … />, when Firefox checks, the field will appear to be marked autocomplete=”on” instead.

### Who’s Got the Most Temp Files then?

#### Ξ April 21st, 2009 | → 4 Comments | ∇ Coding, Geeky, Microsoft, Programming, Research|

For ages, at every boot, I’ve run a small program called TempClean: all this really does is to clear my Temp folder of stuff that’s left over by programs that don’t clear up after themselves [like a man].  Ok, so it does a little bit more than that [unlike a man] – but that’s its main function.

Anyway, I’d be really interested in knowing how much litter [unwanted files] you have on your Windows machine, and so rather than ask you run the real TempClean [it doesn't have an installer - just save it somewhere and run it!] – which you might be unsure/wary off – here’s a small VBScript ‘script’ so that you can find 0ut for yourself. BTW, this doesn’t remove anything!

Here’s the code:

```dim fso
dim fld
dim fle
dim l

set fso = CreateObject("Scripting.FileSystemObject")

set fld = fso.GetSpecialFolder(2)

wscript.echo "Your Temp folder is set to: " & fld.path

sub walk(fld)

wscript.echo vbCrLf & "Looking in: " & fld.path

if fld.files.Count > 0 then

for each fle in fld.files

wscript.echo vbTab & "Found: " & fle.name

l = l + fle.size

next

else

wscript.echo vbTab & "No files found"

end if

for each fld in fld.SubFolders

walk(fld)

next

end sub

walk(fld)

wscript.echo vbCrLf & "The total bytes taken up by your temp files is: " & l```

All you need to do to run this is:

• save it as, say, tempfiles.vbs;
• run it from a Command Prompt [I'll assume you know how to open a Command Prompt, unlike a woman, to quote Colin Hay "or a woman, if you are one" ... ask a man"].

For example, if I’d saved it to my root folder on C, I’d run it like this, in a DOS/Command prompt:

`C:\cscript tempfiles.vbs`

BTW, cscript is a Microsoft VBScript interpreter that you’ll almost certainly have on your machine already.

Note again that running this script doesn’t remove anything – it just reports what you’ve got hanging around, and that’s taking up space unnecessarily.  And, on that last bit, you might like to output the results of running this to a file – else the output might disappear off the top, never to reappear!

You could do that like this:

`C:\cscript tempfiles.vbs > dump.txt`

The > redirects the output into a file call dump.txt.  So you can then open dump.txt in Notepad and have a look at what you’ve got hanging around – which you might find A) interesting, and B) a lot!!

BTW, if you’d like to remove these temporary files, you can just add either these two lines after the l = l + fle.size, e.g.

```l = l + fle.size

on error resume next

fso.deletefile fle```

Or, if you want to do a proper job [like a woman], download and run the real program [link to TempClean above].

Please post up your results, from whichever method, and in summary preferably!

### Eclipse, CDT, MinGW and no WinMain@16

#### Ξ April 8th, 2009 | → 14 Comments | ∇ Coding, Geeky, Programming|

Been playing around with Eclipse today.

It’s been a long time since I last used it, and I’m pretty pleased with all the improvements that have been made to it since I last looked.

However, that said, I did spend about an hour trying to resolve an error in a simple ‘Hello World’ type C project. The error was:

/mingw/lib/libmingw32.a … undefined reference to `WinMain@16′

The test file was simply:

#include

int main(void)
{
puts(“Boo”);

return 0;
}

I googled for the solution [as you do], and tried all manner of things suggested, including having to add libraries and linker/compiler flags. Nothing helped.

However, in playing around, I noticed that I hadn’t saved my source file; test.c file. Surely it can’t be anything as silly as not doing that? Surely the Eclipse IDE will automagically save my file before running the compiler?

You’ve guessed the answer already haven’t you! Yup, on saving the file, and THEN selecting Project | Build All, everything worked! Duh!

P.S. the above applies to version: 3.4.2 Build id: M20090211-1700. And with MinGW installed.

### Livescribe Smartpen – 2Gb Model

#### Ξ March 31st, 2009 | → 1 Comments | ∇ Geeky, Software, Technology|

So, I’m a bit of a gadget freak, but not the type that would buy any gadget – simply because it seems, um, cool [Mmmm].

I saw Livescribe’s Pulse SmartPen on a ‘must have’ list I stumbled upon; and, as my partner and I are both academics – and as such, both ‘send’ and ‘receive’ lectures/talks, we thought it worth investigating, and, to cut a boring story short, we decided [well she did – she’s got the money!], to buy one – the BIG 2Gb model.

Unfortunately, Livescribe – who offer the best price on their own products [duh!] – don’t ship outside of the USA. Something you only discover once you’ve got into the ordering process; once it’s in your ‘cart’. So, suggestion to Livescribe – perhaps make this ‘crystal’ on the initial Buy page?

After shopping around, we found that a lot of places in the UK were ‘out of stock’, yet ‘expecting delivery soon’ – which means, IMHO, avoid like the plague! If a website doesn’t say something’s in stock, one should move along.

We eventually went and found the 2Gb model on bitesizedeals.co.uk and, ordered the 2GB Bundle for £199 – saving £50 apparently. Which, if really true, is a great deal!

A couple of days later, our Livescribe arrived in a very big box.

The box contained:

• 2Gb Pulse Smartpen [in a smaller box (above)]
• 5 x 200 sheet notebooks [dot paper], college-ruled, and colour coded
• Smartpen case
• 2 x 3 black fine point ink cartridges + 1 stylus cartridge
• Demo card and interactive stickers
• Interactive Getting Started Guide

Note there’s no software provided – other than what’s resident in the pen of course. For the PC/Mac side of things you go and get the Livescribe Desktop software as a download.

The install of that was smooth, and the application looks and feels very professional.

I like software to be VERY intuitive [as I’m pretty sure you do], and so I never read a manual, unless I just can’t progress through simply figuring it out. I’ll have more on this aspect of the desktop software later.

When the pen was first attached, I went and found ‘Check for Updates’, and there were lots:

Sorry that’s a little small, but to get an idea of how many there are, notice the size of the scrollbar on the right of the list.

However, this is good news! I.e., it’s nice to know [or at least suspect] that Livescribe are keen to improve their product; and, as they do that, issue lots of updates. Of course, one could also take another view: that Livescribe ship buggy software – that is problematic, been reported n times, and, as a result, have been forced to make a very large number of changes to its product!  I never tried the pen with whatever versions of things it came packed with [so can’t comment on whether it seemed buggy at all], but I take the former of the two views expressed above.  And hey, why would you want to use a product’s software ‘as is’ when there are updates available; which will surely only improve things?

Anyway, the update was smooth.

So, now to try it!

The pen comes with a tutorial/quick-start thingmy which was well worth working through – and I won’t describe it here, and instead show you a picture of me working through it!

The tutorial was easy to follow, smooth, and, I think, pretty much walked you through everything you need to know to get ‘fully functional’.

Be sure to watch the videos of how the pen and the software works here – use the thumbnails at the bottom of the page to walk-through more-or-less everything to do with this gadget.

Ok, so in summary, the pen is awesome!  A truly remarkable and wonderful tool that I would recommend purchasing to anyone that takes notes.

But …

Criticisms:  I have but 3 [so far].

1. The desktop software is, IMHO, not *that* intuitive – and I still find my self clicking on non-functional items – and/or ‘right clicking’ on things to bring up a context-menu that simply don’t exist.  For example, to remove an item from the desktop software, or the pen, you have to highlight the item and then use the top-level menu to select the deletion option.  This really should be on a menu accessed via right-clicking on an item.

The desktop software seems well written, i.e., it’s ultimately functional, but, for me, well, it just doesn’t really satisfy.

2. It seems to me that there is an obvious missing feature.  You can tansfer your files to your Livescribe Desktop, and from there transfer them to your shared space on Livescribe’s own website via Livescribe Online [a really cool feature].  However, you cannot transfer files *back* to the pen once they’ve been moved off of it!  And that’s just dumb!

Ok, so with a 2Gb pen it might be a rare event – to move things off to make space – but, if you do, you’ll be stuck with never being able to use your hand-written notes with the pen ever again.  A few other people have noted their own surprise at this missing feature on Livescribe’s forum pages, and it seems that it might yet appear at some future date.  And that would be great!

3. Livescribe Technical Support seem to take around 24 hours to respond to queries.  Ok, so I only had two ‘trips’ to the support email address, but that was what I found – it’s sloooow!