Category Archives: Uncategorized

Learning From Project Euler

If you’re just starting out with programming, like me, and haven’t yet checked out Project Euler and GitHub, please do. They’re not hard to get into, and I’ve found them really useful!

Project Euler is a particularly powerful impetus for you to improve on your programming skills. Like Codecademy, you start out simple and work your way up through challenges – unlike Codecademy, the challenge is actually worthwhile.

Github, meanwhile, is really useful for storing the code you’re working on and encouraging commentary/interaction with your fellow programmers. It’s also an introduction to version control, which is a useful thing to understand.

I’d urge you to listen to the people at Project Euler and avoid committing Problem answers to Github, as it kind of takes away from the challenge.

Project Euler

In the in-between, a problem with Project Euler forced me to re-design the function I built here, and I’m pretty happy with the results.

My original prime-finding function was taking well over a minute, so I had no choice but to refactor.

It’s a great demonstration of how Project Euler forces you out of your comfort zone – in my case, into Racket vectors. Even though they’re essentially the same as arrays in most other languages, something in me balked at using vectors in Racket. Something about their mutability struck me as not-right in a language so defined by its immutability.

Here’s the first draft of what I wrote, working with vectors to create a static sieve of eratosthenes of length (n):

(define (primes-to x)
  (letrec ([f (lambda (count vs n)
                  [(= n 0) (begin (vector-set! vs 0 #f) (f (+ count 1) vs (+ n 1)))]
                  [(= n 1) (begin (vector-set! vs 1 #f) (f (+ count 1) vs (+ n 1)))]
                   (if (= n x)
                       (if (< count x)
                           (if (= n count)
                               (f (+ count n) vs n)
                               (begin (vector-set! vs count #f)  (f (+ count n) vs n)))
                           (f (+ n 1) vs (+ n 1))))])

    (f 0 (make-vector x #t) 0)))

Since you can access vector members using vector-ref, and this program currently runs all the way to (= n x) – which means that we check almost every item on the list – there’s a lot of optimisation which could be done, and done profitably.

The important thing is (if (= n count), which takes away progressively larger chunks of things to check as the formula grows – I believe this puts it in O(n log n) space, or close to it. With this formula, I can check two million digits in ~6 seconds and I could cut that down substantially with some quick tweaks.

Eventually, I’ll hit a wall with the sieve of eratosthenes, and be forced to use the sieve of atkin – which I do not understand and actually dread facing. When I do have to face it, though, it will magically transform into a fun and interesting challenge. That’s the magic of Project Euler!

Last day, Capricorn-15s

Tagged , , ,

A First Experience With Open Courses

I’ve finally finished what was, for me, a fairly gruelling ten week slog.

Using Coursera, a platform offering free University-level courses to anyone who’s interested, I tried Introduction To Programming Languages as a first course. I met the requirements (just, sort of, not really), and figured “eh, it’s an introduction. How hard could it be?”

Very hard.

I made the mistake of thinking that this was going to be an introduction to the three programming languages on the course. It was actually an introduction to programming languages in general, and concepts in programming language design. I found even the first homework difficult, and struggled through much of the course. It was frustrating, and ate up almost all my free time for the entire ten weeks the course ran (and although I’ve completed the final exam, I still need to complete some peer assessments).

The lesson from this is that open courses are not an easy option, and it is probably not something that most people will be able to do in their spare time without major sacrifices. The courses can be extremely challenging at an extremely high level. It’s not simple stuff. For me, this difficulty was exactly what rendered the courses such a rewarding experience, and really re-affirmed my assumption that what I was learning was really worthwhile rather than just coding busy-work.

On that note, the lectures were top quality. Concepts were taught in a way that seemed very natural, code provided to explain ideas was very clear and useful, and the entire staff (from University of Washington) were extremely dedicated. My thanks to them. Moreover, the concepts built and fed into each other in a very subtle, unassuming way that made ideas that would have frazzled my brain at the start of the course fairly clear by the end. Professor Dan Grossman regularly interacted with and helped students in the forums, and following on from that, the community was incredible. The interaction between people who’d been programming in C for 16+ years, Haskell evangelists and complete novices (like me) was invariably friendly and invariably helpful. It was a great experience.

Just thinking about how much I learned on this course staggers me a little now. Before the course, I had no idea what thunks, streams, or mixins even were, and (as it turns out) I only had a shaky grasp of interfaces, subclassing, and data structures. It would take me twenty minutes to work out what a simple recursive function did, and twenty more to implement my own. I’m now fairly comfortable with functional programming (more comfortable than I am with OOP, in fact), I can edit SML and Ruby with confidence, and I can write programs in Racket. My understanding of Java and its seemingly arbitrary rules and regulations has improved no end, although the syntax looks a lot uglier and more verbose than it used to (and it always looked quite verbose).

In the end I think I got a grade of around 80 (scores aren’t finalised until peer assessments finish), and I would be upset with anything below 70 given the huge amount of effort I put into this course. That’s another thing about these courses – theoretically, the grade doesn’t matter, but once you’ve invested some time into them it becomes just as important as if you’d paid for the course.

I’d recommend this course to absolutely anyone interested in programming should it come up again, and I personally enjoyed my experience with Coursera immensely. I should probably note that there were a few bugs in the autograder, but that these were always found extremely quickly and dealt with almost instantly.

Thanks, Dan. Thdanks.

Tagged , , , ,

Things I Am Doing

I sometimes go quiet for fairly long stretches. Sorry about that.

If you’re interested, these are the kinds of things I tend to be doing during these long stretches. Or in this case the kind of thing I am doing right now.

Learning HTML & CSS (& Javascript)

Thanks to Codecademy, this is so easy it’s ridiculous. It eases you into the learning process as gently as a scared newborn piglet attempting to suckle from a hedgehog.

Learning Java

This is harder. The ultimate aim of this is to…

Design And Complete A Vast Non-Linear 2D RPG/Strategy Hybrid

Should take a little while.

Edit The Novel I Wrote During NaNoWriMo

Looking to focus on this during this year’s NaNoWriMo.

Getting My Poetry Published In Magazines

I have written some poems I’m happy with, so in a way I feel like I’ve ‘completed poetry’. I feel like I should push myself further here, so I’m going to.

Inventing Puns

Why was the Catholic protestor arrested?

He was being in-a-pope-riot.

Proclaiming That Science Is Badass

It really is, especially at the moment.

Life Stuff

Finding people to take my room, trying to keep up with cool games, working for a living, analysing metal until I take all the fun out of it for myself and others, basically doing enough things that take up enough time that I’ll only rarely be able to update here.

Hopefully when I do it’ll be somewhat entertaining.

…this one doesn’t count.

Excellent news from the MA in Creative Writing at Bath Spa University.

The Arc Anthology looks like it’s going to be very exciting, with poetry from published poets James Davey, Daisy Behagg, Lucy Sixsmith and Hazel Hammond, and a consistently high calibre of fiction-writing as well, including many of my favourite bloggers among their number.

ARC is very excited to announce that Brian Kimberling, who graduated from the course in 2010, has just secured a six-figure publishing deal for his book, Snapper!

Brian started writing Snapper whilst on the Masters in Creative Writing at Bath Spa. It went on to win the Janklow & Nesbit Bath Spa Prize, the annual literary prize open to graduates of the course.

The rights were sold to Tim O’Connell of Pantheon last Friday as part of a six-figure, pre-emptive two-book deal. More details to be found here.

Well done Brian!

View original post

Not Sure What To Make Of This…

Disqus screen telling me to log in in order to reach the sign out screen.

Log in to sign out.

I don’t know

%d bloggers like this: