Prime Factorisation

Project Euler rocks. Someone showed me what it was all about a few days ago. Basically it’s a collection of questions that can be answered with an integer. The idea is to write efficient algorithms to calculate this answer in the programming language of your choice. My choice should be obvious by now ;)

Anyway, one of the questions was “Find the 10001st prime”. I decided to handle it this way:

class Integer
  def prime?
    factorise.first == self
  end
end

In other words, attempt to factorise the Integer. If its first (and thus, only) prime factor is the Integer itself, it is prime. Else, it isn’t. With this method, test every Integer from 2 onwards for primality, until the list of found primes is 10001 items long.

So all I needed to do was write the factorise method, which would have to return an Array of prime factors.

Read More »

Deep Thought

puts !?*?!?#:%%%+%?%#{"%c"%(?/+?@)}?%?"+%#!#*(?)-?()#"

Look at this baby. Try and feed it to Ruby and be amazed. My syntax highlighter can’t even handle it :D

Mikoangelo from #ruby-lang crafted it in a good five minutes, and it took me about five times longer to decipher it again :) I’ll break it down now, because, well, I have nothing better to do. Figuring it out on your own is much more fun though!

Some features it (ab)uses:

Read More »

The Power of Javascript

I came across this presentation on infoQ.com yesterday, about the power of Javascript. I’d never heard of Glenn Vanderburg before, but he does a good job keeping things interesting for the whole whopping 56 minutes :)

He mentions some interesting details about the history of the language that I hadn’t picked up from Douglas Crockford’s “You think you know Javascript” series (which you can view here, amongst a lot of other JS-related videos that I’ve yet to watch… I don’t think I’ll be bored today ;) ). He also looks into a few design flaws, and what jQuery and Prototype do to handle them. And he mentions an article by Paul Graham who claims that “Succinctness is power”. I haven’t read it yet, but I think I’m going to do so right now :)

Definitely worth watching if you have some spare time!

Musings on Combinatorics and Set Theory

… just kidding ;)

These are a few methods I wrote for the Rudoku project, mainly to work with arrays of arrays representing sets (most of them assume that the arrays contain only unique elements).
I’m going to dump them here for future reference. Told you this was a pastebin :P

If anyone can suggest any performance / coding style improvements, please, go ahead!

Read More »

Hi!

Hello there.

This is where I dump code. A glorified pastebin, this is.

Not a blog. I don’t like blogs.

At least, I think it isn’t a blog. I shall resist the temptation to describe my life in minute detail, or try to. It’s not very interesting, and even if it was you probably couldn’t care less.

The default Wordpress theme drives me up the wall, so I made my own. It wasn’t as tedious and enerving as I’d expected, despite WP 2.5 coming out a few hours before I finished it :)

The picture in the header is Canary Wharf in London, I believe. I really like it, which is why it’s currently taking up half of your browser’s viewport.

Comments about the design (or about anything else in fact) are welcome :)

Sorry about the URL by the way. Can’t be bothered to get a new domain specifically for this, so I’m reusing an old one.

This is just a test for the syntax highlighting plugin:

class Object
  def in?(collection)
    collection.include?(self)
  end
end

looks about right :)