Mathematics, philosophy, code, travel and everything in between. More about me…

I write about

English | Czech
Choose your language. I write in English, but I translate many of my articles to Czech as well. Zvolte si jazyk. Píšu anglicky, ale řadu svých článků překládám i do češtiny.

Dividing Time

Long bus rides are boring. Way boring. Unless you happen to like mathematics and there is a digital clock on the bus.

The blinking colon looks as if it were inviting to divide the hours by the minutes, and the clock offers a new problem every minute. The division is very simple at 10:10, 14:20, 21:03 and so on. However, when prime numbers enter the scene (11:17, 13:07, 17:37,…) the division becomes a race – how many decimal places can you make before the relentless time serves you a new problem?

I played this little game together with my friend during a long bus trip to London. Even then we were wondering how would a chart of our results look. The higher the minute, the smaller is the resulting fraction. This dependency is “reset” every hour, though. In addition, each new hour gradually increases the fraction.

The problem is ideal for gnuplot, an excellent program for generating plots of all kinds. I kept wondering about the chart until I wrote the following script:

#!/bin/bash

data=$(mktemp)

for ((hr = 0; hr <= 23; hr++)); do
	for ((min = 0; min <= 59; min++)); do
		if [ $min = '0' ]; then
			div='1/0'
		else
			div=$(echo "scale=3; $hr/$min" | bc | sed 's/^\./0./');
		fi
		echo "$hr:$min $div" >> $data;
	done;
done

echo "
set terminal png size 530,350
set output 'timeDivision.png'
set xdata time
set timefmt '%H:%M'
set format x '%H'
set xtics 3600
set ytics 1
set yrange [0:24]
plot '$data' using 1:2 title 'hr/min' with lines
" | gnuplot && display timeDivision.png

rm $data

When executed, this script will generate and display a file named timeDivision.png. The expected chart then looks like this:

The time division chart

Finally, a link to my favorite comic. The difficulty of our tiny division is really laughable in comparison with Factoring the Time :-).

July 7, MMVIII — shell.