11 ms·
I have a 48SX. I never seriously got into programming it, but I did do one program that I was inordinately pleased with. I wanted a calendar, and found one onl
by tzs 9y ago
I have a 48SX. I never seriously got into programming it, but I did do one program that I was inordinately pleased with.
I wanted a calendar, and found one online but it was very slow. It was written entirely in the User RPL. So I wrote my own, also entirely in RPL, but managed to get it fast enough that there was no perceptual difference between its speed and the speed of assembly language calendars.
I got the speed by managing to do almost all of the formatting, which was the slow part, using User RPL string functions, which were all internally implemented as highly optimized assembly.
I'd start with these two strings (spaces replaced with _ for clarity):
days = "__1__2__3 ... _29_30_31"
pad = "_____________________" (that's 21 spaces)
Then I'd calculate
s = number of days month is shorter than 31 days, and
d = day of week of 1st day of month (Sunday == 0, Monday == 1, ...).
Shorten the days string by 3 * s, and prepend 3 * d spaces on front of days (which can be obtained by taking an appropriate substring of the pad string). Finally, append the pad string to days.
Display a header line:
"_Su_Mo_Tu_We_Th_Fr_Sa"
Now take the first 21 characters of days and display them on the next line under the header, then the next 21 characters on the next line, and so on for 5 lines, and that's your calendar.
This could probably be improved a bit by starting with a days string that has 18 spaces in front and 12 spaces at the end. Then you just have to possibly replace some numbers with spaces if the month is shorter than 31 days, and then use the day of the 1st to choose where you start taking the 21 character substrings from.
- taneq 9y agoThere's a much under-rated rush that comes with your first real optimisation job. Mine was with a program to simplify square roots into surds - we'd had the lesson on them in year 10, then been given a sheet of about 100 different square roots to simplify. It was repetitive grunt work and so I wrote a program to do it. The first version worked, but was too slow (it simply tried number from 0 to N/2, checked if it was square, then checked if it was divisible) so I did the obvious thing and instead only checked square numbers, taking it from O(N) to O(SQRT(N)). Simple enough but it made me happy. :)