Added Octave solution from danielfmt.