I present a program for determining the primality of a number on the HP 35s Programmable Calculator. Whilst this is not a particularly interesting algorithm, it should be noted that this implementation only uses the stack – no registers or variables are used whatsoever. The program uses a total of 4 entries in the stack, of which typically only one or two are directly accessible at any point in time.

The program is also intended to be relatively short. Whilst faster or shorter implementations are certainly feasible, the objective with this implementation was to use the stack exclusively, whilst not being completely naive.

The algorithm is as follows:

  1. Copy the candidate prime (x) to all levels of the stack
  2. Check if x is even – if it is, the number is not prime (An additional check should be performed to check if the candidate is 2, which is prime).
  3. Calculate the square root of x. Take the integer portion only.
  4. If the integer portion result is not odd, round to the next highest odd number. Let this be (y)
  5. If the remainder of x divided by y is 0, the number is not prime. Display the canidate x and the found factor. This will be the highest factor the candidate is divisible by. End.
  6. Decrease y by 2.
  7. If y is greater than 1, repeat step 5.
  8. The number is prime, no factors could be found. Restore x to the first position on the stack.

Few things to note:

  • Complexity of this algorithm is O(√x/2)
  • Despite the limited size of the stack, the expensive task of calculating the composite ceiling is only performed once.
  • The largest factor of the number, as well as the original number to be tested, are preserved in the stack upon conclusion of the program.
A001  LBL A
A002  ENTER
A003  ENTER
A004  ENTER
A005  2
A006  RMDR
A007  x=0?
A008  GTO A037
A009  R↓
A010  √x
A011  IP
A012  ENTER
A013  ENTER
A014  2
A015  RMDR
A016  1
A017  +
A018  +
A019  1
A020  x=y?
A021  GTO A032
A022  R↓
A023  RMDR
A024  x=0?
A025  GTO A034
A026  LASTx
A027  2
A028  -
A029  x<>y
A030  R↓
A031  GTO A019
A032  PRIME
A033  RTN
A034  LASTx
A035  x<>y
A036  R↓
A037  NOT PRIME
A038  RTN

Tags: , , , ,

Albany Wind Farm

Tags: , ,

Everyone who has ever had the pleasure of using SQL*Plus knows how tedious it can be. A seemingly genuine relic of the 80s, some would find it difficult to believe that Oracle intended SQL*Plus to be an improvemnt over its earlier “User Friendly Interface”, or UFI.

One of my main gripes with SQL*Plus is the complete lack of command history or recall. If a mistake is made entering a command, the command must be retyped again from scratch. Obviously this is not great for productivity, but it is an improvement over UFI’s behaviour of automatically rolling back an entire transaction whenever a command failed. Someone at Oracle, it seems, is a masochist.

Fortunately, the command-line interface in SQL*Plus can be easily improved using a nice utility called RLWrap written by Hans Lub (hlub@knoware.nl) amongst others. RLWrap intercepts terminal IO performed by an arbitrary application and replaces it with a readline interface. For those unfamiliar with readline, it’s a library that provides rich editing features for command lines, including autocompletion, command history and EMACS bindings – in other words, many things that are missing in SQL*Plus! It’s used by many programs, including the BASH shell.

Read the rest of this entry »

Back in 2002 I wrote a little assembly program  for a first year Microprocessors course at uni. The program is a MS-DOS TSR (remember those?) that provides a simple timer facillity. Given that, only ten years later, the majority of applications are hosted “in the cloud” using managed code, I thought it would be interesting to reflect on the differences in approach…

Download Source Code
Download Executable

The program is broken up into three main components: The Installer, which initializes the TSR, the Keyboard Handler, which intercepts keystrokes used for starting, stopping and resetting the timer; and the clock tick handler, which is reponsbile for updating the timer display at periodic intervals.

Read the rest of this entry »

The Road – Nick Cave and Warren Ellis
Happy - Machine Translations
Way To NormalBen Folds
In The Court of the Crimson King (24-bit Remaster) – King Crimson
Good News for People Who Like Bad News – Modest Mouse
Radio KAOS - Roger Waters
Jupiter One – Jupiter One

P1010217

If you’re looking for instructions on how to repair a Roland JV-80, I have developed a guide that steps you through basic repairs. Whilst it’s no substitute for a manual, hopefully this will guide user’s through the basics of disassembly, key repair, checking for glue, replacing the backup battery etc. Read the rest of this entry »

Tags: , , , , ,

Lionel Richie at NIB Stadium (Courtney McAllister)

As the first instalment of Live at Bulwer St, I am pleased to present a 30 minute bootleg of Lionel Richie’s 2011 Perth Concert. Performed at NIB Stadium on the 6th of April it was the last show of his Australian tour, attracting over 10,000 Perth fans.  Guy Sebastianwas also present to perofrm “All Night Long”.

This was an absolutely blistering gig which was tight and very well performed. The seating plan of NIB Stadium was different to the typical configuration used for concerts of this sizem which meant that my usual vantage points for capturing a good booyleg were comprimised.

The bootleg recording features a selection of Lionel’s hits, including “Endless Love” where he tells the audience that he asked Diana Ross to join him in Perth, but “who needs Diana”. At this point he enlists the help of the 5,000 odd women in the audience to fill in.

Incidentally, I left the gig about right before the end of the encore. Whilst walking down the back of the oval, where noone was around, the fence is opened by two security guards and out emerges a black Audi with Lionel and Guy in the back seat. Perhaps because I was wearing a suit jacket, the security guards did nothing to move me away, and when Lionel drove out he thanked the guards for their help. Class, pure class. I must have been a meter away when this happened.

Live @ Bulwer St – Lionel Richie

Read the rest of this entry »

  • Radiohead: Codex
  • Hauschka: Morning at the Park
  • Arcade Fire: The Suburbs
  • Ben Folds: Lonely Avenue
  • Phillip Glass: Einstein on the beach (Knee 5)

Some random photos from the Gorillaz concert in Perth at the Burswood Dome on 6 December 2010. Yes, they’re crap quality; unfortunately they’re actually stills taken from video, but due to the extreme volume the video was unusable.

Read the rest of this entry »

One of the principal limitations of Oracle XE is that the total size of your database cannot exceed 4GB. Whilst this should be ample in most situations, this limitation can often arise when you least expect it. You’ll know when you’ve reached the limit as Oracle will produce the following error:

ORA-12952: The request exceeds the maximum allowed database size of 4 GB

Read the rest of this entry »

« Older entries