about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/ssch14/number-name.html
diff options
context:
space:
mode:
Diffstat (limited to 'js/games/nluqo.github.io/~bh/ssch14/number-name.html')
-rw-r--r--js/games/nluqo.github.io/~bh/ssch14/number-name.html91
1 files changed, 91 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/~bh/ssch14/number-name.html b/js/games/nluqo.github.io/~bh/ssch14/number-name.html
new file mode 100644
index 0000000..bac8cd1
--- /dev/null
+++ b/js/games/nluqo.github.io/~bh/ssch14/number-name.html
@@ -0,0 +1,91 @@
+<P>
+
+<P>
+<HTML>
+<HEAD>
+<TITLE>Simply Scheme:Project: Spelling Names of Huge Numbers</TITLE>
+</HEAD>
+<BODY>
+<CITE>Simply Scheme</CITE>:
+<CITE>Introducing Computer Science</CITE> 2/e Copyright (C) 1999 MIT
+<H1>Project: Spelling Names of Huge Numbers</H1>
+
+<TABLE width="100%"><TR><TD>
+<IMG SRC="../simply.jpg" ALT="cover photo">
+<TD><TABLE>
+<TR><TD align="right"><CITE><A HREF="http://www.cs.berkeley.edu/~bh/">Brian
+Harvey</A><BR>University of California, Berkeley</CITE>
+<TR><TD align="right"><CITE><A HREF="http://ccrma.stanford.edu/~matt">Matthew
+Wright</A><BR>University of California, Santa Barbara</CITE>
+<TR><TD align="right"><BR>
+<TR><TD align="right"><A HREF="../pdf/ssch14.pdf">Download PDF version</A>
+<TR><TD align="right"><A HREF="../ss-toc2.html">Back to Table of Contents</A>
+<TR><TD align="right"><A HREF="recur-patterns.html"><STRONG>BACK</STRONG></A>
+chapter thread <A HREF="../ssch15/adv-recur.html"><STRONG>NEXT</STRONG></A>
+<TR><TD align="right"><A HREF="http://mitpress.mit.edu/0262082810">MIT
+Press web page for <CITE>Simply Scheme</CITE></A>
+</TABLE></TABLE>
+
+<HR>
+
+<P>
+
+
+<P>Write a procedure <CODE><A NAME="g1"></A>number-name</CODE> that takes a positive integer
+argument and returns a sentence containing that number spelled out in words:
+
+<P><PRE>&gt; (number-name 5513345)
+(FIVE MILLION FIVE HUNDRED THIRTEEN THOUSAND THREE HUNDRED FORTY FIVE)
+
+&gt; (number-name (factorial 20))
+(TWO QUINTILLION FOUR HUNDRED THIRTY TWO QUADRILLION NINE HUNDRED TWO
+ TRILLION EIGHT BILLION ONE HUNDRED SEVENTY SIX MILLION SIX HUNDRED
+ FORTY THOUSAND)
+</PRE>
+
+<P>There are some special cases you will need to consider:
+
+<P><P><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Numbers in which some particular digit is zero
+</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Numbers like 1,000,529 in which an entire group of three digits is zero.
+</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Numbers in the teens.
+
+</TABLE><P>
+
+<P>Here are two hints.  First, split the number into groups of three digits,
+going from right to left.  Also, use the sentence
+
+<P><PRE>'(thousand million billion trillion quadrillion quintillion
+  sextillion septillion octillion nonillion decillion)
+</PRE>
+
+<P>You can write this bottom-up or top-down.  To work bottom-up, pick a subtask
+and get that working before you tackle the overall structure of the
+problem.  For example, write a procedure that returns the word <CODE>FIFTEEN</CODE>
+given the argument <CODE>15</CODE>.
+
+<P>To work top-down, start by writing <CODE>number-name</CODE>, freely assuming the
+existence of whatever helper procedures you like.  You can begin debugging
+by writing <EM>stub</EM> procedures that fit into the overall program but
+don't really do their job correctly.  For example, as an intermediate stage
+you might end up with a program that works like this:
+
+<P><PRE>&gt; (number-name 1428425)                      ;; intermediate version
+(1 MILLION 428 THOUSAND 425)
+</PRE>
+
+
+<P>
+
+
+<HR>
+<P><A HREF="../ss-toc2.html">(back to Table of Contents)</A><P>
+<A HREF="recur-patterns.html"><STRONG>BACK</STRONG></A>
+chapter thread <A HREF="../ssch15/adv-recur.html"><STRONG>NEXT</STRONG></A>
+
+<P>
+<ADDRESS>
+<A HREF="../index.html">Brian Harvey</A>, 
+<CODE>bh@cs.berkeley.edu</CODE>
+</ADDRESS>
+</BODY>
+</HTML>