├── .DS_Store ├── README.md └── chapters ├── chapter-1 ├── chapter-1-summary.md └── solutions │ ├── 1-1 A and B.jpg │ ├── 1-2 How Many bits.jpg │ └── Chapter 1 Exercises 1.1a-1.2a.jpg ├── chapter-2 ├── Exercise-2.14.md ├── Exercise-2.3.md ├── chapter-2-summary.md ├── exercise-2_4.md └── interpreter question ├── chapter-3 ├── computing_ch3_notes_exercise_3.4.md ├── exercise_3.1.md ├── exercise_3.10.md ├── exercise_3.11.md ├── exercise_3.2.md ├── exercise_3.3.md ├── exercise_3.9.md └── images │ ├── Ex3.2a.png │ ├── Ex3.2b.png │ ├── Ex3.2c.png │ ├── Ex3.2d.png │ ├── Ex3.2e.png │ ├── Ex3.2f.png │ └── Exercise3.1.png ├── chapter-4 ├── chapter-4-summary.md └── solutions │ ├── exercise_4.1.md │ ├── exercise_4.3.md │ ├── exercise_4.4.md │ ├── exercise_4.6.md │ └── exercise_4.7.md └── chapter-5 ├── images └── 5.5.png └── solutions ├── exercise_5.11.md ├── exercise_5.12.md ├── exercise_5.15.md ├── exercise_5.4.md ├── exercise_5.8.md └── exercise_5.9.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Intro to computing. 2 | 3 | This repo contains notes and solutions students reading David Evan's textbook [Intro To Computing](http://computingbook.org/). 4 | 5 | If you'd like to submit your notes on certain chapters, solutions to exercises, blog posts you've written or links to relevant articles related to the book's subject matter, please feel free to open a PR. 6 | 7 | ## Chapter 1. 8 | 9 | [Notes](chapters/chapter-1/chapter-1-summary.md) 10 | 11 | 12 | ## Chapter 2. 13 | 14 | [Notes](chapters/chapter-2/chapter-2-summary.md) 15 | -------------------------------------------------------------------------------- /chapters/chapter-1/chapter-1-summary.md: -------------------------------------------------------------------------------- 1 | # Chapter 1 summary 2 | 3 | There are two reasons why everyone should study computing: 4 | 5 | 1. Nearly all of the most exciting and important technologies, arts, and sciences of today and tomorrow are driven by computing. 6 | 7 | 2. Understanding computing illuminates deep insights and questions in the nature of our minds, our culture, and our universe. 8 | 9 | ## 1.1 Processes, procedures and computers. 10 | 11 | Computers can mechanize any intellectual activity we can imagine. 12 | 13 | Computer science is the study of information processes. A process is a sequence of steps. 14 | 15 | A **procedure** is a description of a process.A simple process can be described just by listing the steps. The list of the steps is the procedure; the act of following them is the process. A procedure that can be followed without any thought is called a mechanical 16 | 17 | For example, baking a cake or mailing a letter would both be processes. However, they involve physical things like sugar or paper, while computer science focuses on processes that involve abstract information rather than physical things. 18 | 19 | Here’s an example of a procedure (or a recipe) for baking a cake: 20 | 1. Preheat the oven to 350 degrees. F. 21 | 2. Butter a cake pans and line the bottoms with parchment paper 22 | 3. Whisk 3 cups flour, the baking powder and salt in a bowl until combined. 23 | 4. Beat 2 sticks butter and the sugar in a large bowl with a mixer on medium-high speed until light and fluffy, about 3 minutes. 24 | 25 | ...And so on. 26 | 27 | Describing processes just by listing steps like this has limitations. Natural languages are imprecise and ambiguous. We assume that whoever follows these instructions knows many things. For example, we assume the oven is plugged in and sitting on a flat surface. 28 | 29 | We could add as many details as we can to our above procedure, but the English language (and many others) is inherently vague. 30 | 31 | Another problem with this way of describing a procedure is that the size of the description is proportional to the # of steps in the process. This is fine for simple processes that can be executed by humans in a reasonable amount of time, but the processes we want to execute on computers involve trillions of steps. 32 | 33 | To program computers, we need tools that allow us to describe processes precisely. For a machine to carry out a procedure, every step needs to be described. Computers can’t rely on “common sense” (for example, knowing to turn on the oven). We need mechanical procedures that can be followed without any thinking. 34 | 35 | A computer is a machine that can: 36 | 37 | 1. Accept input. Input could be a human typing into keyboard. 38 | 2. Execute a mechanical procedure, a procedure where each step can be executed without any thought. 39 | 3. Produce output. Output could be data displayed to humans. 40 | 41 | Computers exist in many forms, but we’ll focus on universal computers, which are computers that can perform all possible mehanical computations on discrete inputs except for practical limits on space and time. If this sounds confusing to you, we’ll learn more about this later on! :) 42 | 43 | We need computers that can not only perform mechanical procedures, but do so fast. There is where ‘computing power’ comes in, a term you may have heard of. 44 | 45 | ## 1.2 Measuring Computing Power. 46 | 47 | We can measure the power of a computing machine in two ways: 48 | 49 | How much information can it process? 50 | How fast can it process? 51 | 52 | Let’s consider this first question. 53 | 54 | When we think about information, we usually mean knowledge. At the smallest level in the computer, information is stored as bits and bytes. 55 | 56 | What are bits and bytes? 57 | 58 | A **bit** is the smallest unit of information that can be stored by a computer. 59 | 60 | Eight bits grouped together is a **byte**. 61 | 62 | -------------------------------------------------------------------------------- /chapters/chapter-1/solutions/1-1 A and B.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-1/solutions/1-1 A and B.jpg -------------------------------------------------------------------------------- /chapters/chapter-1/solutions/1-2 How Many bits.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-1/solutions/1-2 How Many bits.jpg -------------------------------------------------------------------------------- /chapters/chapter-1/solutions/Chapter 1 Exercises 1.1a-1.2a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-1/solutions/Chapter 1 Exercises 1.1a-1.2a.jpg -------------------------------------------------------------------------------- /chapters/chapter-2/Exercise-2.14.md: -------------------------------------------------------------------------------- 1 | Thank you for orgnizing this, Madison. This book is a great text. 2 | 3 | 4 | Exercise 2.14 5 | a) 6 | www.virginia.edu 7 | 8 | 9 | Domain 10 | | 11 | SubDomainList 12 | | 13 | | 14 | SubDomainList.Label 15 | | 16 | | 17 | SubDomainList.Label.Label 18 | / / | \ \ 19 | | | | | | 20 | Label . Label . Label 21 | / \ | \ \ 22 | Letter MoreLetters . Letter MoreLetters . Letter MoreLetters 23 | | | \ | | \ \ \ 24 | w MoreLetters . v MoreLetters . e MoreLetters 25 | / | | | | \ \ \ \ 26 | w LetterHyphens LetterDigit E . v LetterHyphens LetterDigit E . e LetterHyphens LetterDigit E 27 | / / | | | | \ \ \ \ 28 | w LetterDigitHyphen Letter . v LetterDigitHyphens LetterHyphens . e LetterDigitHyphen Letter 29 | / | | | | | | \ \ \ \ 30 | w LetterDigit w . v Letter LetterDigitHyphen LetterHyphens . e LetterDigit u 31 | / / / / / / / / \ \ \ \ 32 | w w w . v i Letter LetterDigitHyphen LetterHyphens . e d u 33 | | / / / / / / / / \ \ \ \ 34 | w w w . v i r Letter LetterDigitHyphen LetterHyphens . e d u 35 | / / / / / / / / / / \ \ \ \ 36 | w w w . v i r g Letter LetterDigitHyphen LetterHyphens . e d u 37 | / / / / / / / / / / / / / / / 38 | w w w . v i r g i Letter LetterDigitHyphen LetterHyphens . e d u 39 | / / / / / / / / / / / / / / / / 40 | w w w . v i r g i n Letter LetterDigitHyphen LetterHyphens . e d u 41 | / / / / / / / / / / / / / / / / / 42 | w w w . v i r g i n i Letter E . e d u 43 | / / / / / / / / / / / / / / / / 44 | w w w . v i r g i n i a . e d u 45 | || 46 | \/ 47 | www.virginia.edu 48 | 49 | 50 | 51 | 52 | Exercise 2.14 B) 53 | 3) a-a.b-b.c-c is a valid Domain Name 54 | 55 | NOTE: after reviewing the answers, option 1 is also a valid domain name! I didn't think so, but it makes sense: SubDomainlist => Label => Letter MoreLetters => 't' LetterHypens LetterDigit => 't' E 'j' => tj 56 | -------------------------------------------------------------------------------- /chapters/chapter-2/Exercise-2.3.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2.3. 2 | 3 | According to the Oxford English Dictionary, Thomas Jefferson is the first person to use more than 60 words in the dictionary. Jeffersonian words include: (a) authentication, (b) belittle, (c) indecipherable, (d) inheritability, (e) odometer, (f ) sanction, (g) vomit-grass, and (h) shag. For each Jeffersonian 4 | word, guess its derivation and explain whether or not its meaning could be inferred from its components. 5 | 6 | ### Solution 7 | 8 | **Authentication**: Can be separated into components(**morphemes**) [“*authenticate*”] and [“*ion*”]. Authenticate means true or valid, -ion is a suffix denoting a condition or action. So the meaning of the new word [“Authentication”] could be inferred from the components as the act of validating. 9 | 10 | **Belittle**: Can be separated into components(**morphemes**) [“*be*”] and [“*little*”], can be inferred to a degree- I think. To me, I take [“*be*”] as a command from someone or an act and [“*little*”]- something small. Combined it could be an act of regarding something small or with lesser value(small could mean lesser value), this is a bit close to its original meaning of regarding something or someone as unimportant. 11 | 12 | **Indecipherable**: In-decipher-able; three components(**morphemes**). [“*Able*”] here means ability, [“*decipher*”]- to read and [“*-in*”] as a prefix could mean [“*in, on or not*”]. In this case, not is the only reasonable meaning. Therefore, the new word Indecipherable could be inferred as not able to read-(a combination of the definitions of the components). 13 | 14 | **Odometer**: When sifted will produce components [“*Odo*”] and [“*meter*”]. [“*Odo*”] is one of those words that are just used and don’t really have meanings, but we could still get an idea of what odometer means from the second component [“*meter*”]- meaning distance or instrument used in measuring distance, and probably with experience of other words bearing meter. For example barometer, speedometer. However, we may not get the full meaning. 15 | 16 | **Sanction**: Can be filtered to produce [“*sanct*”] and [“*-ion*”]. The prefix ***-ion*** was talked about earlier , but the other word sanct is a Latin word, and so it could be hard guessing the meaning of this new word or maybe impossible as the word sanct itself means holy and is not in any way relating to punishment or penalty which is the meaning of sanction. 17 | 18 | **Vomit-grass**: I feel this is a figurative expression, that could mean spewing out thoughts or feelings that have been kept in one for a considerable amount of time and then trying to think through them, maybe one at a time; from the concept of ruminant animals that have four chambers of the stomach and after having chewed a lot of grass initially and are settled they spew it out as start rechewing in bits, in a relaxed mode. I haven’t seen this word in any dictionary yet. 19 | 20 | **Shag**: This is primitive. Cannot be inferred from split components because it’s in it’s smallest meaningful unit. 21 | 22 | -------------------------------------------------------------------------------- /chapters/chapter-2/chapter-2-summary.md: -------------------------------------------------------------------------------- 1 | # Chapter 2 summary 2 | 3 | Language is a tool for communication, probably the most common. Language is used to communicate between: 4 | 5 | 1. Two humans or more. 6 | 7 | 2. A network of computers. 8 | 9 | 3. A human and a computer. 10 | 11 | 4. And I like to think between animals too. 12 | 13 | ## 2.1 Surface Forms and Meanings. 14 | 15 | A language is a set of surface forms and meanings, and a mapping between the surface forms and their associated meanings. 16 | 17 | Surface forms could be characters, pictures ...And the rest. 18 | 19 | For example a baby is communicated with mostly with pictures and videos, :coffee: <= could mean tea time. So a language is all about 20 | passing a message. 21 | 22 | In the earliest of years when civilization was still at it's minimal, surface forms were sounds-if you watch documentaries or NatGeoWild you would have seen some of these surface forms as some native communities still use these communication styles in hunting. 23 | 24 | There are a whole lot of surface forms some of which are drum beats,pictures, or hand gestures(for those that are familiar with soccer, an offside refree indicates an offside by stretching forth his flag- comunicating to the refree). 25 | 26 | **Natural Language**: spoken by humans is very complex and evolves as time goes on. 27 | 28 | In computing the surface forms focus are text which is in a linear sequence of characters. 29 | **String** is the name given to these set of characters.***string*** is a sequence of zero or more characters which is drawn from a finite set of characters known as ***alphabet*** {a,b,...,k,...,z}. 30 | 31 | #### In ***strings*** capital letters, numerals and punctuation marks are also needed. 32 | 33 | Communication systems involving humans are imprecise and would vary based on the interpretation of the interpreter(human that is being communicated with). Mr Y and Mrs U may disagree on the actual meaning of :coffee:, Mr Y may take it as coffee and Mrs U as tea. 34 | 35 | Communication systems for computers demand precision: we want to know what our programs will do, so it is important 36 | that every step they make is understood precisely and unambiguously. 37 | 38 | In Computing a useful language must be able to express *infinitely* many different meanings-must be able to generate new surface forms([strings]) and guess their meanings. 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /chapters/chapter-2/exercise-2_4.md: -------------------------------------------------------------------------------- 1 | # Exercise 2.4: Embiggening your vocabulary 2 | 3 | I thought it would be fun to all have a go at inventing some new words and start using them (and maybe one of them will make it to step c and get into Merriam-Webster!) 4 | 5 | ## New word ideas: Add a section with your name as an H3 and your word ideas 6 | 7 | ### Dominic Duffin 8 | 9 | Kilonickel, meganickel, giganickel, teranickel, petanickel: words measuring how much confidence you have that your code will work - if you have a nickel of confidence it might not, but if you have a petanickel of confidence you're pretty sure it will. (If you were at a certain CodeBookClub meeting you should get where this comes from 😉). 10 | -------------------------------------------------------------------------------- /chapters/chapter-2/interpreter question: -------------------------------------------------------------------------------- 1 | Hi everyone, 2 | 3 | Working through the Scheme exercises in the book, it's hard to find a good compiler/interpreter to use. 4 | The closest out of the few I tried was the Dr. Racket that the book recommends. I set it to 5 | the Racket language set to Scheme mode. I can't get a lot of the basic Scheme examples in the book to work properly. 6 | Any recommendations for what you are using to work through examples? 7 | 8 | Here's the Dr. Racket docs: https://docs.racket-lang.org/guide/syntax-overview.html 9 | It's pretty close, but definitely not enough to just type the book examples in and have them work. 10 | 11 | Thanks, 12 | Anken 13 | -------------------------------------------------------------------------------- /chapters/chapter-3/computing_ch3_notes_exercise_3.4.md: -------------------------------------------------------------------------------- 1 | computing_ch3_notes_exercises.md 2 | 3 | ***Notes*** 4 | 5 | Compiled programs are faster => translation happens while program is running so interpreter is slower 6 | 7 | Compile programs show error 8 | 9 | 10 | ***Exercises** 11 | Exercise 3.4 is super-extra 12 | 13 | Exercise 3.4: 14 | 15 | Unstated but possibly related: 16 | Distance = Rate * Time 17 | 1 Meter = ~39.37 inches 18 | 19 | Stated: 20 | Light Travels at 299,792,458 meters per second 21 | 22 | Processor Speed is gigahertz (GHz), 1,000,000,000 hertz 23 | Herts means once per second, so 1 GHz means the processor executes 1,000,000,000 cycles per second 24 | 25 | My machine has a processor has a speed of 1.8 GHz 26 | 1,800,000,000 cycles per second 27 | 28 | In inches, how far does light travel during the time it takes the processor in my computers to execute one cycle. 29 | 1,800,000,000 cycles per second 30 | 299,792,458 meters per second 31 | 32 | Convert speed of light from meters to inches: 33 | Converting the speed of light from meters to inches: 34 | ~11,802,852,677.17 Light Speed in Inches Per Second 35 | 36 | If my computer completes 1,800,000,000 cycles per second and light travels at 118,101,829,071.46 inches per second, how far does light travel - in inches - in the time it takes my computers to complete one cycle? 37 | 38 | I'm assuming the computational time is linear; that we we can figure out the fraction of a second it takes to complete one cycle from the 1.8GHz speed - 1,800,000,000 cycles per second 39 | 40 | If 1,800,000,000/1 = 1/x, then: 41 | (x)1,800,000,000 = 1 42 | the time it takes to complete one cycle is 1/1,800,000,000 43 | 44 | If light travels at 11,802,852,677.17 inches per second and my computer process one cycle in 1/1,800,000,000, then 45 | then light will travel inches 11,802,852,677.17*1/1,800,000,000 in the time it takes my computer to complete on cycle. 46 | 47 | 11,802,852,677.17*1/1,800,000,000 = ~6.55 inches 48 | 49 | DANG! OK, the scheme representation 50 | (* 11,802,852,677.17 (/ 1 1800000000)) 51 | 52 | Scheme representation, including the conversion from meter to inches 53 | (* (* 299792458 39.37008) (/ 1 1800000000)) 54 | 55 | 299792458 39.37008 56 | 118,102,069,054.85664 57 | 11,802,852,677.17 58 | 59 | 60 | Exercise 3.5: 61 | (define (cube x) (* x (* x x))) 62 | 63 | 64 | -------------------------------------------------------------------------------- /chapters/chapter-3/exercise_3.1.md: -------------------------------------------------------------------------------- 1 | ## Exercise 3.1 2 | 3 | *Note:* In the book, triangles are used instead of showing the complete parse tree for nested application expressions. I don't know how that works in markdown, so I use `<>` 4 | 5 | *Expression* 6 | | 7 | *ApplicationExpression* 8 | | | | 9 | ( *Expression* *MoreExpressions* ) 10 | | | 11 | *PrimitiveExpression* *Expression* *MoreExpressions* 12 | | | | 13 | **+** *PrimitiveExpression* *Expression* *Expression* 14 | | | | 15 | **100** *ApplicationExpression* *ApplicationExpression* 16 | <> <> 17 | **(* 5)** **(+ 5 5)** 18 | 19 | And in DrRacket: 20 | 21 | ![Exercise3.1](/images/Exercise3.1png) 22 | 23 | **Note:** When evaluating the above with the DrRacket IDE, it's important to have `lang Scheme` stated at the top of the document. Otherwise, we run into the error: 24 | 25 | Module Language: only a module expression is allowed, either 26 | #lang 27 | 28 | -------------------------------------------------------------------------------- /chapters/chapter-3/exercise_3.10.md: -------------------------------------------------------------------------------- 1 | ## Exercise 3.10: 2 | 3 | Define a procedure, bigger-magnitude, that takes two inputs, and outputs the value of the input with the greater magnitude (that is, absolute dis- tance from zero). For example, (bigger-magnitude 5 −7) should evaluate to −7, and (bigger-magnitude 9 −3) should evaluate to 9. 4 | 5 | ## Solution: 6 | 7 | I just ended up using the function I wrote for absolute value as a helper function. 8 | 9 | (define (absvalue num) 10 | (if (< num 0) 11 | (- num) 12 | num 13 | )) 14 | 15 | and put it all together here: 16 | 17 | (define (bigger-magnitude x y) 18 | (if 19 | (> (absvalue x) (absvalue y)) 20 | x y) 21 | ) -------------------------------------------------------------------------------- /chapters/chapter-3/exercise_3.11.md: -------------------------------------------------------------------------------- 1 | ## Exercise 3.11: 2 | 3 | Define a procedure, biggest , that takes three inputs, and produces as output the maximum value of the three inputs. For example, (biggest 5 7 3) should evaluate to 7. Find at least two different ways to define biggest , one using bigger, and one without using it. 4 | 5 | ## Solutions: 6 | 7 | 1) Using if else: 8 | 9 | (define (biggest a b c) 10 | (if (> a b) 11 | (if (> a c) a c) 12 | (if (> b c) b c) 13 | ) 14 | ) 15 | 16 | 2) Using bigger 17 | 18 | - Helper function here: 19 | 20 | `(define (bigger a b)(if (> a b) a b))` 21 | 22 | (define (biggest a b c) 23 | (bigger a (bigger b c)) 24 | ) -------------------------------------------------------------------------------- /chapters/chapter-3/exercise_3.2.md: -------------------------------------------------------------------------------- 1 | ## Exercise 3.2 2 | 3 | **a)** `1120` 4 | 5 | - I assumed this would simply return the value. 6 | - In DrRacket: 7 | 8 | ![Exercise3.2a](/chapters/chapter-3/images/Ex3.2a.png) 9 | 10 | **b)** `(+ 1120)` 11 | 12 | - Without anything to add to that `+` primitive expression, I would get back the 1120. 13 | 14 | ![Exercise3.2b](/chapters/chapter-3/images/Ex3.2b.png) 15 | 16 | **c)** `(+ (+ 10 20) (* 2 0))` 17 | 18 | - For this one, I approached it following the orders of operations from grade school. The inner parenthesis would go first, with 10 being added to 20 to make 30. And 2 to be multipled by 0, to get zero. These values are then added according to outer level `+`, to get 30. 19 | 20 | ![Exercise3.2c](/chapters/chapter-3/images/Ex3.2c.png) 21 | 22 | **d)** `(= (+ 10 20) (* 15 (+ 5 5)))` 23 | 24 | - Now, taking a gander at prior notes within the textbook, I assumed that `=` sign asks whether the evaluated sums from inner parentheses are equal. `+ 5 51` is 10, which is multiplied by the `* 15` to get 150. And `(+ 10 20)` would just be 30. So, no. They are not equal. 25 | 26 | DrRacket's answer (*drumroll...*): 27 | 28 | ![Exercise3.2d](/chapters/chapter-3/images/Ex3.2d.png) 29 | 30 | *Note:* The interpreter spits out an anticlimactic `#f` which apparently means False. Some extra reading was found here: [CS#431: Scheme Basics](https://courses.cs.washington.edu/courses/cse341/02wi/scheme/basics.html). 31 | 32 | **e)** `+` 33 | 34 | - I honestly didn't expect anything to come out of this, maybe a keyword requiring me to peruse the Scheme Basics once more. I was wrong. 35 | 36 | DrRacket's answer: 37 | 38 | ![Exercise3.2e](/chapters/chapter-3/images/Ex3.2e.png) 39 | 40 | **f)** `(+ + <)` 41 | 42 | - For this one, I tried to be intuitive about what the procedure was trying to evaluate. `+` and `+` together are not lesser than nothing. Maybe equal, but that would require me to deep dive into what equality actually means in Scheme. 43 | 44 | DrRacket's answer: 45 | 46 | ![Exercise3.2f](/chapters/chapter-3/images/Ex3.2f.png) -------------------------------------------------------------------------------- /chapters/chapter-3/exercise_3.3.md: -------------------------------------------------------------------------------- 1 | ## Exercise 3.3 2 | ### Using DrRacket to evaluate Scheme expressions 3 | 4 | #### A) Seconds in a year: 5 | 6 | `(* 365 (* 24 (* 60 60)))` 7 | 8 | #### B) Seconds I've been alive: 9 | 10 | `(* 32 (* 365 (* 24 (* 60 60))))` 11 | 12 | Or, using a definition: 13 | 14 | `(define (secs-lifetime age) (* age (* 365 (* 24 (* 60 60)))))` 15 | 16 | #### C) Fraction I've been in school: 17 | 18 | Function definition: 19 | 20 | `(define (frac-school age years) (/ years age))` 21 | 22 | That returns a fraction. Using the following to give a decimal equivalent, I can see that I spent over half my life in school: 23 | 24 | `(exact->inexact (frac-school 32 18))` -------------------------------------------------------------------------------- /chapters/chapter-3/exercise_3.9.md: -------------------------------------------------------------------------------- 1 | ## Exercise 3.9: 2 | 3 | Define a procedure, absvalue, that takes a number as input and produces the absolute value of that number as its output. For example, (ab- svalue 3) should evaluate to 3 and (absvalue −150) should evaluate to 150. 4 | 5 | Using built in function: 6 | 7 | `(define (absvalue x) (abs x))` 8 | 9 | Using if-else procedures: 10 | 11 | (define (absvalue num) 12 | (if (< num 0) 13 | (- num) 14 | num 15 | )) 16 | 17 | **Explanation**: 18 | 19 | If incoming `num` is lesser than 0, as expressed `(if (< num 0)` then return `num`. Otherwise return the `num` made negative with `(- num)` -------------------------------------------------------------------------------- /chapters/chapter-3/images/Ex3.2a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-3/images/Ex3.2a.png -------------------------------------------------------------------------------- /chapters/chapter-3/images/Ex3.2b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-3/images/Ex3.2b.png -------------------------------------------------------------------------------- /chapters/chapter-3/images/Ex3.2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-3/images/Ex3.2c.png -------------------------------------------------------------------------------- /chapters/chapter-3/images/Ex3.2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-3/images/Ex3.2d.png -------------------------------------------------------------------------------- /chapters/chapter-3/images/Ex3.2e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-3/images/Ex3.2e.png -------------------------------------------------------------------------------- /chapters/chapter-3/images/Ex3.2f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-3/images/Ex3.2f.png -------------------------------------------------------------------------------- /chapters/chapter-3/images/Exercise3.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-3/images/Exercise3.1.png -------------------------------------------------------------------------------- /chapters/chapter-4/chapter-4-summary.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-4/chapter-4-summary.md -------------------------------------------------------------------------------- /chapters/chapter-4/solutions/exercise_4.1.md: -------------------------------------------------------------------------------- 1 | # Exercise 4.1 2 | 3 | ## For each expression, give the value to which the expression evaluates. Assume _fcompose_ and _inc_ are defined as above. 4 | 5 | a. ((_fcompose square square_)3) 6 | 7 | ### Solution a 8 | 9 | This application expression (_fcompose square square_) evaluates to a procedure that composes _square_ w/_square_ (multiplying the input by itself 4 times). Applying this procedure to **3** evaluates to **81**. 10 | 11 | b. (_fcompose_(__lambda__(_x_) (_*x_ 2)) (__lambda__(_x_) (_/x_ 2) )) 12 | 13 | ### Solution b 14 | 15 | This evaluates to an identity procedure for numerical inputs. This produces a procedure which accepts a number as its input, which in turn applies a procedure that multiplies by **2** to the result of a procedure that divides the input number by **2**. 16 | 17 | c. ((_fcompose_(__lambda__(_x_) (_∗x_ 2) ) (__lambda__(_x_) (_/x_ 2)) ) 1120) 18 | 19 | ### Solution c 20 | 21 | This applies the identity procedure from the previous example to 1120, so the result is 1120. 22 | 23 | d. ((_fcompose_(_fcompose inc inc_)_inc_)2) 24 | 25 | ### Solution d 26 | 27 | The inner application expression, (_fcompose inc inc_), evaluates to a procedure that takes a numerical value as its input and outputs the result of incrementing it twice. The next expression, (_fcompose_(_fcompose inc inc_)_inc_), composes with another inc procedure, resulting in a procedure that adds **3** to its input. Applying this procedure to **2** results in the value of **5**. 28 | 29 | -------------------------------------------------------------------------------- /chapters/chapter-4/solutions/exercise_4.3.md: -------------------------------------------------------------------------------- 1 | # Exercise 4.3 2 | 3 | ## Define a procedure `fcompose3` that takes three procedures as inputs, and produces as output a procedure that is the composition of the three input procedures. 4 | 5 | Given that the following have already been defined: 6 | 7 | `(define (square x) (* x x))` 8 | 9 | `(define (cube x) (* x x x))` 10 | 11 | ### A) once without using fcompose: 12 | 13 | (define ((threeFunctions func1 func2 func3) input) 14 | (func3 (func2 (func1 input))) 15 | ) 16 | 17 | 18 | ### B) using fcompose: 19 | 20 | (define (fcompose3 func1 func2 func3) 21 | (lambda (input) (func3 (func2 (func1 input)))) 22 | ) 23 | -------------------------------------------------------------------------------- /chapters/chapter-4/solutions/exercise_4.4.md: -------------------------------------------------------------------------------- 1 | # Exercise 4.4 2 | 3 | ## Define a f2compose procedure that composes two procedures where the first procedure takes two inputs, and the second procedure takes one input. 4 | 5 | (define (f2compose func1 func2) 6 | (lambda (x y) (func2 (func1 x y))) 7 | ) -------------------------------------------------------------------------------- /chapters/chapter-4/solutions/exercise_4.6.md: -------------------------------------------------------------------------------- 1 | # Exercise 4.6 2 | 3 | ## Define a recursive procedure,gauss-sum, that takes a number n as its input parameter, and evaluates to the sum of the integers from 1 to n as its output. For example, (gauss-sum 100) should evaluate to 5050. 4 | 5 | (define (gauss-sum n) 6 | (if (= n 1) 1 7 | (+ n (gauss-sum (- n 1)))) 8 | ) 9 | -------------------------------------------------------------------------------- /chapters/chapter-4/solutions/exercise_4.7.md: -------------------------------------------------------------------------------- 1 | # Exercise 4.7 2 | 3 | ## Define a higher-order procedure, accumulate, that can be used to make both gauss-sum (from Exercise 4.6) and factorial. The accumulate procedure should take as its input the function used for accumulation (e.g., ∗ for factorial,+ for gauss-sum). 4 | 5 | (define (accumulate f) 6 | (lambda (n) 7 | (if (= n 1) 1 8 | (f n ((accumulate f) (- n 1))))) 9 | ) 10 | -------------------------------------------------------------------------------- /chapters/chapter-5/images/5.5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madisonkanna/intro-to-computing/159dc95a99392d7328cea77749c887b7e4e08311/chapters/chapter-5/images/5.5.png -------------------------------------------------------------------------------- /chapters/chapter-5/solutions/exercise_5.11.md: -------------------------------------------------------------------------------- 1 | # Exercise 5.11 2 | 3 | ## Define a procedure is-list? that takes one input and outputs true if the input is a List, and false otherwise. 4 | 5 | (define (is-list? p) 6 | (if (null? p) 7 | true 8 | (if (pair? p) 9 | (is-list? (cdr p)) 10 | false)) 11 | 12 | ) 13 | 14 | *Explanation*: 15 | - If null, return `true`. 16 | - If there is a pair, recursively call `cdr` on the list until it is null, inevitably becoming `true`. Basically, `[1 2 3 4]` becomes `[2 3 4]` and then `[3 4]`. 17 | -------------------------------------------------------------------------------- /chapters/chapter-5/solutions/exercise_5.12.md: -------------------------------------------------------------------------------- 1 | # Exercise 5.12 2 | 3 | ## Define a procedure list-max that takes a List of non-negative numbers as its input and produces as its result the value of the greatest element in the List 4 | 5 | 1) Brute force method: 6 | 7 | (define (list-max p) 8 | (if (null? p) 9 | 0 10 | (if (> (list-max (cdr p)) (car p)) 11 | (list-max (cdr p)) 12 | (car p) 13 | )) 14 | ) 15 | 16 | 2) Using previously declared `bigger` method 17 | 18 | (define (bigger a b) (if (> a b) a b)) 19 | 20 | (define (list-max2 p) 21 | (if (null? p) 22 | 0 23 | (bigger (car p) (list-max2 (cdr p)))) 24 | ) -------------------------------------------------------------------------------- /chapters/chapter-5/solutions/exercise_5.15.md: -------------------------------------------------------------------------------- 1 | # Exercise 5.15 2 | 3 | ## Define a procedure list-last-element that takes as input a List and outputs the last element of the input List. If the input List is empty, list-last- element should produce an error. 4 | 5 | (define (lastGuy p) 6 | (if (null? p) 7 | (error "Index Out Of Range") 8 | (if (null? (cdr p)) 9 | (car p) 10 | (lastGuy (cdr p)))) 11 | ) 12 | 13 | (lastGuy (list 4 2 0 69)) -------------------------------------------------------------------------------- /chapters/chapter-5/solutions/exercise_5.4.md: -------------------------------------------------------------------------------- 1 | # Exercise 5.5 2 | 3 | ## Give an expression that produces the structure shown below. 4 | 5 | ![Exercise5.5](/images/5.5png) 6 | 7 | (define thing 8 | (cons 1 (cons (cons 2 3)(cons 4 (cons 5 6)))) 9 | ) -------------------------------------------------------------------------------- /chapters/chapter-5/solutions/exercise_5.8.md: -------------------------------------------------------------------------------- 1 | # Exercise 5.8 2 | 3 | ## Define a procedure that constructs a quintuple and procedures for selecting the five elements of a quintuple. 4 | 5 | Using the original built in procedures, I can use `cons`, `car`, and `cdr` to build this procedure. 6 | 7 | (define (make-quint a b c d e) 8 | (cons (cons a b)(cons (cons c d) e)) 9 | ) 10 | 11 | *NOTE: For odd numbered collections, it is easier to make the first cell a pair using the cons procedure, while the second cell could be the scalar type*. 12 | 13 | The individual lookups: 14 | 15 | (define (quint-uno t) (car (car t))) 16 | (define (quint-dos t) (cdr (car t))) 17 | (define (quint-tres t) (car (car (cdr t)))) 18 | (define (quint-quatro t) (cdr (car (cdr t)))) 19 | (define (quint-cinco t) (cdr (cdr t))) 20 | 21 | -------------------------------------------------------------------------------- /chapters/chapter-5/solutions/exercise_5.9.md: -------------------------------------------------------------------------------- 1 | # Exercise 5.9 2 | 3 | ## Another way of thinking of a triple is as a Pair where the first cell is a Pair and the second cell is a scalar. Provide definitions of make-triple, triple- first, triple-second, and triple-third for this construct. 4 | 5 | Triple Definition: 6 | 7 | (define (trip-scal a b c) 8 | (cons (cons a b) c) 9 | ) 10 | 11 | Lookup Functions: 12 | 13 | 14 | (define (triple-first t) (car (car t))) 15 | (define (triple-second t) (cdr (car t))) 16 | (define (triple-third t) (cdr t)) 17 | --------------------------------------------------------------------------------