The only way to learn a new programming language is by writing programs in it.
— KERNIGHAN & RITCHIE, The C Programming Language (1988)
Contents
- Typewriter
- Hello, World
- Even or Odd
- Union
- Intersection
- Reserved Words
- Expressions
- Terminology
- Stacks
- Two Queues
- The Josephus Problem
- Cards
- Tall Objects
- Power Outage
- Shapes
- Green Snake Red Snake
Exercise Sets
- Typewriter
- Make a typewriter.
- Hello, World
- Create a program that prints the words "hello, world".
A JavaScript “Hello, World!” Hat Trick
/** A hat trick is the achievement of a positive feat three times. * @see https://en.wikipedia.org/wiki/Hat-trick */ (function helloWorldHatTrick() { "use strict"; const HELLO_WORLD = "hello, world"; alert(HELLO_WORLD); // 1st console.log(HELLO_WORLD); // 2nd document.getElementsByTagName("body")[0].innerHTML = HELLO_WORLD; // 3rd })();
- Create a program that prints source code for a program that prints the words "hello, world".
- Create a program that prints the letters in the string "hello, world". Print each letter of the string on a separate line. After each letter, print a space followed by the character’s Unicode value in parentheses followed by a newline character.
A JavaScript Solution
"use strict"; printCharactersAndUnicodeValues("hello, world"); function printCharactersAndUnicodeValues(s) { const win = new PopUpWindow("300", "250"); const n = s.length; // number of characters in s for (let i = 0; i < n; i++) { win.println(s[i] + " (" + s.charCodeAt(i) + ")"); } } function PopUpWindow(width, height) { const win = window.open("", "", "width=" + width + ",height=" + height ); const doc = win.document; this.print = function(s) { doc.write(s); } this.println = function(s) { doc.write(s + "<br>"); } }
- Create a program that prints the words "hello, world".
- Even or Odd
- Compose a program that indicates the parity of one or more inputs by outputting whether each expected input is an even or odd integer or neither.
A Simple Java Parity Program
public class Parity { public static void main(String[] args) { try { final int n = Integer.parseInt(args[0]); final String parity = n % 2 == 0 ? "Even" : "Odd"; System.out.print(parity); } catch (Exception e) { System.out.print("undefined"); } } }
A Variegated Java Parity Program
public class Parity { private static final String EVEN = "Even", ODD = "Odd"; private static String variation1(int n) { return n % 2 == 0 ? EVEN : ODD; } private static String variation2(int n) { if (n % 2 == 0) return EVEN; return ODD; } private static String variation3(int n) { if (n % 2 == 0) return EVEN; else return ODD; } private static String variation4(int n) { if (n % 2 != 0) return ODD; else return EVEN; } private static String variation5(int n) { if (n / 2 == n / 2.0) { return EVEN; } else { return ODD; } } public static void main(String[] args) { String parity = "undefined"; try { int m, n = Integer.parseInt(args[0]); try { m = Integer.parseInt(args[1]); System.out.print("variation" + m + ": "); } catch (Exception e) { m = 1 + (int)(Math.random() * 5); } switch (m) { case 1: parity = variation1(n); case 2: parity = variation2(n); case 3: parity = variation3(n); case 4: parity = variation4(n); case 5: parity = variation5(n); } } catch (Exception e) { /* do nothing */ } System.out.println(parity); } }
A Simple JavaScript Parity Program
function parity(x) { if (!Number.isInteger(x)) return undefined; else if (x % 2 == 0) return "Even"; else return "Odd"; }
A Multifaceted JavaScript Parity Program
/** A Multifaceted JavaScript Parity Program * Indicates the mathematical parity of its inputs. * Outputs whether each input is an even or odd integer or neither. * * @author: John P. Spurgeon * @param args The inputs. * <p> * If the value of args is null: First, the program runs a series * of tests starting with a smoke test followed by a series of * unit tests. The unit tests validate functions in a set of * functions that may be used to determine whether an integer is * even. Next, the program prompts the user for inputs, evaluates * the inputs, outputs a report, and asks the user whether to * repeat the process. Finally, the program returns a reference * to itself.</p> * <p> * If the value of args is undefined: The program prompts the user * for inputs, evaluates the inputs, outputs a report, and asks the * user whether to repeat the process again. The program terminates * when the user presses a Cancel button, either when prompted for * inputs or when asked whether to repeat the process. The value * returned is undefined.</p> * <p> * If the value of args is not null and is not undefined: The program * outputs a string of characters: each character indicates whether * the corresponding input is even, odd, or neither. Multiple inputs * may be provided as separated arguments or as one or more arrays of * arguments. In any case, a continuous string of parity "bits" is * returned, where each bit indicates even, odd, not an integer, or * out of range.</p> */ const parity = (function main(args) { "use strict"; const ODD_PARITY_BIT = "1", IS_ODD = "is odd"; const EVEN_PARITY_BIT = "0", IS_EVEN = "is even"; const NOT_INTEGER_SYMBOL = "n", NOT_INTEGER = "is not an integer"; const OUT_OF_RANGE_SYMBOL = "r", OUT_OF_RANGE = "is out of range"; const INPUT_PROMPT = "Enter integers separated by spaces."; const ASK_AGAIN = "Again?"; // Functions that return true if the value of n is an even integer and // false if n is an odd integer. If n is not an integer, the value // returned may vary from function to function for a given value of n. const IS_EVEN_FUNCTIONS = Object.freeze([ (n) => (n % 2) === 0, (n) => Number.isInteger(n / 2), (n) => Number.isInteger(n * 0.5), (n) => (n << 31) === 0, (n) => (1 & n) === 0, (n) => (-2 | n) === -2, (n) => (0xfffffffe | n) === (0xfffffffe >> 0), (n) => (1 ^ n) === ((n >> 0) + 1) ]); if (args === null) { smokeTest(); IS_EVEN_FUNCTIONS.forEach(testIsEvenFunction); promptPrintRepeat(); return main; } else if (args === undefined) { promptPrintRepeat(); } else { return getParityBits(arguments); } /***************/ /* Subroutines */ /***************/ function getParityBits(args) { let bits = ""; const len = args.length; for (let i = 0; i < len; i++) { const val = args[i]; if (Array.isArray(val)) bits += getParityBits(val); else if (!Number.isInteger(val)) bits += NOT_INTEGER_SYMBOL; else if (Math.abs(val) > Number.MAX_SAFE_INTEGER) bits += OUT_OF_RANGE_SYMBOL; else bits += isEven(val) ? EVEN_PARITY_BIT : ODD_PARITY_BIT; } return bits; } function isEven(value) { if (!Number.isInteger(value)) return undefined; const f = getRandomElement(IS_EVEN_FUNCTIONS); return f(value); } function getRandomElement(array) { const n = array.length; const r = Math.random() * n; const i = Math.floor(r); return array[i]; } function promptPrintRepeat() { let input = undefined; while (input !== null) { input = prompt(INPUT_PROMPT); if (input !== null) { const values = []; input.split(" ").forEach(function(s) { values.push(toNumberOnlyIfIsInteger(s)); }); alert(getParityReport(values)); if (!confirm(ASK_AGAIN)) return; } } } /** Given a value s, returns n, the output of parseFloat(s), only * if n is deemed to be an integer by Number.isInteger AND n and s * are judged to be equal by the == operator; otherwise, returns s. */ function toNumberOnlyIfIsInteger(s) { const n = parseFloat(s); return (Number.isInteger(n) && (s == n)) ? n : s; } function getParityReport(values) { let report = ""; values.forEach(function(n) { const bit = getParityBits([n]); const phrase = parityBitToString(bit); report += n + " " + phrase + ".\n"; }); return report; } function parityBitToString(bit) { switch (bit) { case EVEN_PARITY_BIT: return IS_EVEN; case ODD_PARITY_BIT: return IS_ODD; case OUT_OF_RANGE_SYMBOL: return OUT_OF_RANGE; case NOT_INTEGER_SYMBOL: return NOT_INTEGER; } } /******************/ /* Test Functions */ /******************/ function smokeTest() { const expectedBits = "0101010101"; const actualBits = main([0, 1, 2], 3, [4, [5, 6]], 7, 8, [9]); if (actualBits !== expectedBits) { console.info("Actual bits: " + actualBits); console.info("Expected bits: " + expectedBits); throw Error("Failed smoke test."); } else console.info("Passed smoke test."); } function testIsEvenFunction(ief) { const MAX_INTEGER = Number.MAX_SAFE_INTEGER; const MAX_INTEGER_IS_EVEN = false; const MIN_INTEGER = -MAX_INTEGER; const MIN_INTEGER_IS_EVEN = false; const TIMER_NAME = "Total Test Time"; const UPPER = 1000; let testsPassed = 0; console.info("Testing " + ief); console.time(TIMER_NAME); try { testFunction(ief, 1, false); testFunction(ief, 0, true); testFunction(ief, MAX_INTEGER, MAX_INTEGER_IS_EVEN); testFunction(ief, MAX_INTEGER - 1, !MAX_INTEGER_IS_EVEN); testFunction(ief, MIN_INTEGER, MIN_INTEGER_IS_EVEN); testFunction(ief, MIN_INTEGER + 1, !MIN_INTEGER_IS_EVEN); testFunction(isEven, NaN, undefined); testFunction(isEven, undefined, undefined); testFunction(isEven, null, undefined); testFunction(isEven, Math.PI, undefined); testRange(ief, UPPER); } finally { console.timeEnd(TIMER_NAME); } console.info("Passed " + testsPassed + " unit tests."); /* Subroutines */ function testFunction(f, input, expectedOutput) { const actualOutput = f(input); if (actualOutput !== expectedOutput) { console.error("function: " + f); console.error("input: " + input); console.error("expected: " + expectedOutput); console.error("actual output: " + actualOutput); throw Error("Test failed."); } else { testsPassed++; } } function testRange(f, upper) { let expected = true; for (let i = 0; i < upper; i++) { testFunction(f, i, expected); testFunction(f, -i, expected); expected = !expected; } } } // testIsEvenFunction })(null); // main
A Java Parody Program
from Valley Catholic School’s 2018 production of “May The Farce Be With You”/** "May The Farce Be With You" * @see https://www.dramaticpublishing.com/may-the-farce-be-with-you */ public class MayTheFarceBeWithYou { /** If args[0] (the expected input) is a base 10 * integer between -(2^31) and 2^31-1 inclusive: * prints "Even" if the integer is even, or * prints "Odd" if the integer is odd. Otherwise, * prints: * * E-I-E-I-O * (Evaluates Idealistic Electronic Integers Only) */ public static void main(String[] args) { try { // When the following statement is evaluated, // an exception will be thrown if args is null // or args.length is 0, or args[0] cannot be // interpreted as a base 10 integer between // -(2^31) and 2^31-1 inclusive. int n = Integer.parseInt(args[0]); if (Parody.isEven(n)) System.out.println("Even"); else System.out.println("Odd"); } catch (Exception e) { Parody.main(null); // "E-I-E-I-O\n" System.out.println( "(Evaluates Idealistic Electronic Integers Only)" ); } } } class Parody { private static final String INTEGER = "I", EVEN = "E", ODD = "O", O = new String("O"); private static boolean traceSteps = false; private static void trace(String s) { if (traceSteps) { System.out.print(s); System.out.print(s.equals(O) ? "\n" : "-"); } } private static boolean getAnswer(double a, int b) { boolean c = (a - b) == 0; trace(c ? EVEN : ODD); // "E-" or "O\n" return c; } public static boolean isEven(int n) { trace(INTEGER); // "I-" Double a = n / 2.0; int b = a.intValue(); return getAnswer(a, b); } public static boolean isEven(double n) { Double a = n / 2; int b = a.intValue(); return getAnswer(a, b); } /** Prints "E-I-E-I-O\n". */ public static void main(String[] args) { traceSteps = true; isEven(0d); // "E-" isEven(0x8000_0000); // "I-E-" isEven(0b0111_1111_1111_1111_1111_1111_1111_1111); // "I-O\n" } }
- Create a program that outputs "Even" if the number of inputs to the program is even or "Odd" if the number of inputs is odd.
- Create a program that takes a list of strings as inputs:
- If the first string is "Even", then the program should output the strings provided as input that have an even number of characters.
- If the first string is "Odd", then the program should output the strings provided as input that have an odd number of characters.
- If the first string is neither "Even" nor "Odd", then the program should output all of the input strings.
- The program should output a comma-separated list of strings on one line. Terminate the list with a newline character. Do not put a comma after the last string in the list.
- Create a program that takes a list of strings as input and outputs the sum of the lengths of the strings with an even number of characters on the first line of output followed by the sum of the lengths of the strings with an odd number of characters on the second line of output.
- Create a program that takes a pair of integers as input and outputs "Even" if the product of the integers is even or "Odd" if the product of the integers is odd.
Make sure your program outputs the correct answer for all possible combinations of inputs when each input is within the range of integers that your program will accept. You may determine what range of inputs your program will accept; try to make the range as large as possible given any constraints that are imposed by the data types your program uses.
Ponder This Java Program
public class TickTock { private static boolean isEven(double value) { double remainder = value % 2; return remainder == 0; } private static boolean isEven(long value) { double remainder = value % 2; return remainder == 0; } private static void longShot(long middle, int n) { long value = middle - n; int iterations = (2 * n) + 1; for (int i = 0; i < iterations; i++) { long sum = value + i; System.out.print(value + " + " + i + " = "); System.out.print(sum + " ("); System.out.print( isEven(sum) ? "Even" : "Odd" ); System.out.println(")"); } } private static void doubleTrouble(double middle, int n) { double value = middle - n; int iterations = (2 * n) + 1; for (int i = 0; i < iterations; i++) { double sum = value + i; System.out.print(value + " + " + i + " = "); System.out.print(sum + " ("); System.out.print( isEven(sum) ? "Even" : "Odd" ); System.out.println(")"); } } public static void main(String[] args) { final double MAX_SAFE_DOUBLE_INTEGER = Math.pow(2, 53) - 1; final long MAX_LONG_INTEGER = Long.MAX_VALUE; int n = args.length > 0 ? Integer.parseInt(args[0]) : 2; if (n < 2) n = 2; System.out.println("Long Shot"); longShot(MAX_LONG_INTEGER, n); System.out.println("\nDouble Trouble"); doubleTrouble(MAX_SAFE_DOUBLE_INTEGER, n); } }
- Create a program that takes a single string as input. Print the characters in the string with even Unicode values on the first line of output;
print the characters in the string with odd Unicode values on the second line of output.
- Each line of output should consist of a comma separated list of values, and each value in the list should be a character followed by a space followed by that character’s Unicode character code in parentheses. Do not put a comma after the last item in the list.
- Output the characters in alphabetical order.
- Do not output the same character more than once.
- Create a program that takes two integers, lower and upper, as input and prints, on the first line of output, each integer that is greater than or equal to lower and less than upper that has an even number of 1s in the base 2 representations of the number; on the second line of output, the program should print each integer that is greater than or equal to lower and less than upper that has an odd number of 1s in the base 2 representations of the number. On each line of output, print the base 10 representations of the integers as a comma-separated list of values in order from smallest to largest. Do not print a comma after the last number in either list prior to printing a newline character.
- Compose a program that indicates the parity of one or more inputs by outputting whether each expected input is an even or odd integer or neither.
- Union
- Create a program that takes two arrays of elements, a and b, as input and outputs an array of distinct elements that are in either a or b.
A JavaScript Solution
"use strict"; getUnionOf(["I", "love", "you"], ["You", "love", "me"]); function getUnionOf(a, b) { return removeDuplicatesAndSort(a.concat(b)); } function removeDuplicatesAndSort(a) { a = a.sort(); const n = a.length; // number of element in a const d = []; // distinct values array (initially empty) for (let i = 0, j = -1; i < n; i++) { const e = a[i]; // element of a at index i if (j < 0 || d[j] !== e) { j++; d[j] = e; } } return d; }
- Create a program that takes two arrays of elements, a and b, as input and outputs an array of distinct elements that are in either a or b.
- Intersection
- Create a subroutine that takes two arrays of strings, a and b, as input and outputs a comma-separated list of distinct strings that are in both a and b.
A JavaScript Solution
// This solution requires an implementation of removeDuplicatesAndSort. // See Union. (function main(args) { "use strict"; const a = [ null, [], ["I", "love", "you"], ["You", "love", "me"], ["Won't", "you", "say", "you", "love", "me", "too"] ]; const n = a.length; for (let i = 0, testNum = 0; i < n; i++) { for (let j = i; j < n; j++) { const output = ++testNum + ". " + stringifyIntersectionOf(a[i], a[j]) + "\n" + ++testNum + ". " + stringifyIntersectionOf(a[j], a[i]) + "\n" + ++testNum + ". " + stringifyIntersectionOf(a[i], args) + "\n" + ++testNum + ". " + stringifyIntersectionOf(args, a[j]) + "\n"; console.log(output); } } })(prompt().split(" ")); function toCSV(a) { return (a === null || a === undefined) ? "undefined" : "{" + a.toString() + "}"; } function stringifyIntersectionOf(a, b) { const c = getIntersectionOf(a, b); return "The intersection of " + toCSV(a) + " and " + toCSV(b) + " is " + toCSV(c) + "."; } function getIntersectionOf(a, b) { if (a === null || a === undefined || b === null || b === undefined) return undefined; a = removeDuplicatesAndSort(a); b = removeDuplicatesAndSort(b); return getDuplicates(a.concat(b)); } function getDuplicates(a) { a = a.sort(); const n = a.length; // number of strings in a const d = []; // duplicate values array (initially empty) for (let i = 0, j = 1, k = -1; j < n; i++, j++) { const e = a[j]; // element of a at index j if (a[i] === e) { if (k < 0 || d[k] !== e) { k++; d[k] = e; } } } return d; }
A Java Solution
import java.util.Arrays; class ArrayOfStrings { public static boolean contains(String[] a, String s, int i, int j) { while (i < j) if (s.equals(a[i++])) return true; return false; } public static String[] copyOf(String[] a) { final int n = a.length; final String[] copy = new String[n]; for (int i = 0; i < n; i++) copy[i] = a[i]; return copy; } public static String toCSV(String[] a) { if (a == null) return "undefined"; String csv = "{"; final int n = a.length; if (n > 0) { csv += a[0]; for (int i = 1; i < n; i++) { csv += "," + a[i]; } } return csv + "}"; } } public class ArraysOfStrings { /** Returns strings that are in both a and b. * @param a an array of strings. * @param b an array of strings. * @return an array of alphabetically sorted distinct strings, each * of which is a and b, assuming a and b are both arrays of * strings. If either a or b is null, then the method returns * null. A string is considered to be in a or b if the string's * sequence of characters matches the sequence of characters of * one or more of the strings that comprise a and b. */ public static String[] getIntersectionOf(String[] a, String[] b) { // If either a or b is null, then we return null, thereby // terminating the algorithm, to indicate that the intersection of // a and b is undefined. if (a == null || b == null) return null; // We want b to be the biggest array, i.e. to have the longest length. // If b is not the biggest, then swap a and b. if (a.length > b.length) { String[] tmp = a; a = b; b = tmp; } // We don't want this method to produce side effects, such as // changing the order of the elements of a. But we need to work // with the elements of a in sorted order. Therefore, we replace // a with a copy of a and sort the elements of the copy. a = ArrayOfStrings.copyOf(a); Arrays.sort(a); // Now we establish the lengths of a and b. We assert that the // length of a will be less than or equal to the length of b. final int n = a.length, m = b.length; assert n <= m; // We will use a temporary array (called indices) to hold the // indices of values that comprise the intersection of a and b. // Since the intersection of a and b cannot be greater in // size (i.e. length) than the smallest array, and since we don't // yet know how many elements are in the intersection, we create // the array indices such that it can hold up to n elements, // where n is the length of the smallest array. final int[] indices = new int[n]; // Now we add the indices to the array called "indices", being // careful not to add the index of two elements with the same // value, i.e. the same sequence of characters, twice. (This is // where it's helpful to have the elements of a in sorted order.) int j = 0; String current, previous = null; for (int i = 0; i < n; i++) { current = a[i]; if (i > 0 && current.equals(previous)) continue; if (ArrayOfStrings.contains(b, current, 0, m)) indices[j++] = i; previous = current; } // At this point, the value of j will be the number of elements // in the intersection of a and b. Now we can create a array of // strings called "intersection" that is just the right size to // hold the strings that belong to the intersection of a and b. assert j >= 0 && j <= n; final String[] intersection = new String[j]; // Finally, we use the first j values of "indices" to populate // "intersection" with strings. The we return the value of // "intersection". for (int i = 0; i < j; i++) { final int k = indices[i]; assert k >= 0 && k < n; intersection[i] = a[k]; } return intersection; } /** Returns a string describing the intersection of a and b. * @param a an array of strings. * @param b an array of strings. * @see #getIntersectionOf(String[] a, String[] b). * @see ArrayOfStrings#toCSV(String[] a). */ public static String stringifyIntersectionOf(String[] a, String[] b) { final String[] c = ArraysOfStrings.getIntersectionOf(a, b); return "The intersection of " + ArrayOfStrings.toCSV(a) + " and " + ArrayOfStrings.toCSV(b) + " is " + ArrayOfStrings.toCSV(c) + "."; } public static void main(String args[]) { String[][] a = { null, {}, {"I", "love", "you"}, {"You", "love", "me"}, {"Won't", "you", "say", "you", "love", "me", "too"} }; final int n = a.length; for (int i = 0, testNum = 0; i < n; i++) { for (int j = i; j < n; j++) { final String output = ++testNum + ". " + stringifyIntersectionOf(a[i], a[j]) + "\n" + ++testNum + ". " + stringifyIntersectionOf(a[j], a[i]) + "\n" + ++testNum + ". " + stringifyIntersectionOf(a[i], args) + "\n" + ++testNum + ". " + stringifyIntersectionOf(args, a[j]) + "\n"; System.out.println(output); } } } }
- Create a subroutine that takes two arrays of strings, a and b, as input and outputs a comma-separated list of distinct strings that are in both a and b.
- Reserved Words
- Create a program that prints the reserved words of a programming language that is specified by a string provided as the input to the program:
- Print the words as a comma-separated list of values. Separate each adjacent pair of words using a comma followed by a space, and terminate the list with a new-line character.
- Print the words in alphabetical order.
- If the input is the string "Java", print the 50 reserved words of the Java programming language. Capitalization matters. The words are case-sensitive. Exclude the words true, false, and null, which are literal values.
- If the input is the string "JavaScript", print the 64 reserved words of the JavaScript programming language as of ECMAScript 6. Capitalization matters, and the words are case-sensitive.
- Extend the program you created in part a of this set of exercises so that it prints the reserved words of one or more programming languages when three inputs are provided:
- Print the words in alphabetical order, as a comma-separated list of values.
- You may assume the first and third inputs will either be the string "Java" or the string "JavaScript".
- You may assume the second input will either be the string "&&" or the string "||".
- If the second input is "||", then print the reserved words that are reserved words in either the programming language specified by the first input or the programming language specified by the second input.
- If the second input is "&&", then print the reserved words that are reserved words in both the programming language specified by the first input and the programming language specified by the second input.
- Do not print the same word or phrase twice.
- Extend the program you created in part b of this set of exercises so that it also supports the following languages and reserved words:
- Support the language "Python" and the 31 reserved words listed at https://docs.python.org/2.5/ref/keywords.html.
- Support the language "C89" and the 32 reserved words listed at https://en.wikipedia.org/wiki/C_(programming_language)#Reserved_words.
- Support the 21 reserved words listed at https://www.lua.org/manual/5.1/manual.html#2.1 in section 2.1 for the language "Lua".
- Extend the program you created in part c so that it supports an arbitrary number inputs (language identifiers separated by operators). Perform "&&" operations before performing "||" operations; otherwise, perform operations from left to right.
- Create a program that prints the reserved words of a programming language that is specified by a string provided as the input to the program:
- Expressions
- Compose a program that evaluates expressions.
- Terminology
- Create a program that prints definitions or descriptions corresponding to a list of words or phrases provided as the input to the program.
- If no words or phrases are provided (i.e. the input list is empty), then print all of the definitions or descriptions your program knows.
- For each word or phrase in the list, the program should print a description or definition of the word or phrase.
- Indicate whether the word or phrase being defined or described is a noun, pronoun, adjective, determiner, verb, adverb, preposition, conjunction, or interjection.
- Along with each description or definition, clearly identify the source of the description or definition. If the definition or description is in your own words, give yourself credit. (Do not plagiarize.)
- If a word or phrase in the list is not in the program’s vocabulary, then the program should indicate that no description or definition is available for that particular word or phrase.
- Include the following words in your program’s vocabulary: word, phrase, description, definition, vocabulary, grammar, noun, pronoun, adjective, determiner, verb, adverb, preposition, conjunction, interjection.
- Include the following phrase in your program’s vocabulary: part of speech.
- Create a program that prints definitions or descriptions corresponding to a list of words or phrases provided as the input to the program.