From 562a9a52d599d9a05f871404050968a5fd282640 Mon Sep 17 00:00:00 2001 From: elioat Date: Wed, 23 Aug 2023 07:52:19 -0400 Subject: * --- js/games/nluqo.github.io/~bh/ssch14/number-name | 91 +++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 js/games/nluqo.github.io/~bh/ssch14/number-name (limited to 'js/games/nluqo.github.io/~bh/ssch14/number-name') diff --git a/js/games/nluqo.github.io/~bh/ssch14/number-name b/js/games/nluqo.github.io/~bh/ssch14/number-name new file mode 100644 index 0000000..bac8cd1 --- /dev/null +++ b/js/games/nluqo.github.io/~bh/ssch14/number-name @@ -0,0 +1,91 @@ +

+ +

+ + +Simply Scheme:Project: Spelling Names of Huge Numbers + + +Simply Scheme: +Introducing Computer Science 2/e Copyright (C) 1999 MIT +

Project: Spelling Names of Huge Numbers

+ +
+cover photo + +
Brian +Harvey
University of California, Berkeley
+
Matthew +Wright
University of California, Santa Barbara
+

+
Download PDF version +
Back to Table of Contents +
BACK +chapter thread NEXT +
MIT +Press web page for Simply Scheme +
+ +
+ +

+ + +

Write a procedure number-name that takes a positive integer +argument and returns a sentence containing that number spelled out in words: + +

> (number-name 5513345)
+(FIVE MILLION FIVE HUNDRED THIRTEEN THOUSAND THREE HUNDRED FORTY FIVE)
+
+> (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)
+
+ +

There are some special cases you will need to consider: + +

    Numbers in which some particular digit is zero +
    Numbers like 1,000,529 in which an entire group of three digits is zero. +
    Numbers in the teens. + +

+ +

Here are two hints. First, split the number into groups of three digits, +going from right to left. Also, use the sentence + +

'(thousand million billion trillion quadrillion quintillion
+  sextillion septillion octillion nonillion decillion)
+
+ +

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 FIFTEEN +given the argument 15. + +

To work top-down, start by writing number-name, freely assuming the +existence of whatever helper procedures you like. You can begin debugging +by writing stub 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: + +

> (number-name 1428425)                      ;; intermediate version
+(1 MILLION 428 THOUSAND 425)
+
+ + +

+ + +


+

(back to Table of Contents)

+BACK +chapter thread NEXT + +

+

+Brian Harvey, +bh@cs.berkeley.edu +
+ + -- cgit 1.4.1-2-gfad0