[Icarus Productions] - Click for main page The team Projects Articles Features
The list of the winners of the contest which ended 05/02/99:

Place Name Score Sum
1. Jeff Hellrung 350 350
2. Jonah Cohen 406 406

This ZIP contains all the solutions sent in. Be aware of the fact that some may not work! These were the problems to be solved:

Optimization: Size

Unless otherwise specified, all strings are Z-strings.


Number Spellout

Input:HL free space
BCDE = number between 0 and 999999999
Output:BCDE will contain a 32 bit number (LSB in E, MSB in B) with at most 9 decimal digits (you may assume this), which should be spelled out, according to the rules below. The string should be created at HL, which will point to enough free memory for the correct answer. The string should terminate with a null byte. When the routine is done, HL should point to the beginning of the string (ie, HL should be preserved).
Special:You may not use any temporary memory! You'll have to include any temporary space in the program code itself.

Rules for spelling

  • Spelling for ones: zero, one, two, three, four, five, six, seven, eight, nine
  • Spelling for teens: ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen
  • Spelling for tens: twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety
  • Spelling for hundreds: hundred, thousand, million
  • A white blank should separate each of the numbers above, except between ones and tens, where are hyphen ('-') should be used.
  • No pluralization should be done.

Input:BCDE = 50312
Output:HL -> "fifty thousand three hundred twelve"

Input:BCDE = 198000
Output:HL -> "one hundred ninety-eight thousand"

Input:BCDE = 10000000
Output:HL -> "ten million"

Input:BCDE = 123456789
Output:HL -> "one hundred twenty-three million four hundred fifty-six thousand seven hundred eighty-nine"

Hint and advice


This page has a simple algorithm (in Java) for the spellout procedure.

Extracting digits

The following piece of code will extract the last digit in BCDE and store it in A, while at the same time dividing BCDE with ten. Please note that you do not have to use this routine! If you do, the size will count.

; Input:    BCDE = 32 bit
; Output:   BCDE = BCDE/10, A = BCDE mod 10

 push hl
 xor a 
 ld hl,$200A 
 sla e
 rl d
 rl c
 rl b
 cp l
 jr c,ESkip
 sub l
 inc e
 dec h
 jr nz,ELoop
 pop hl

Defining 32 bit numbers

The following simple macro can be used to store a 32 bit number in two 16 bit registers.

#define ld_bcde(x) ld bc,(x)>>16 \ ld de,(x)&$FFFF
Page last updated on Mon May 17 00:17:10 1999 E-mail us!Top of page