Content tagged SICP

SICP Section 2.1

posted on 2008-08-07 20:54:02

It's taken far too long to post this up and the last four problems remain unfinished. That said, I want to get more of the solutions I've worked written up and I shouldn't have waited this long in the first place. With any luck Section 2.2 will follow within a week. I'm around half done with it and you can see some solutions here.

Report Card, Semester 1

posted on 2008-07-22 15:58:17

So, I've been trying to do this self-study thing for 30 weeks. I probably should've stepped back to evaluate my progress before now but I've allowed myself to be distracted with other things. You know, moving out, working my first full-time job, learning how to cook, clean and take care myself. That's no excuse though. Rather than beat around the bush some more let's just get to the heart of it:
"You got an F. What the hell's the matter with you? Ya big failure.
Final Grade: 20.786516853932586%
To be fair, you would've had to do 14.0 problems a week to finish the book in 26 weeks.
They are pretty hard problems. Just keep at it man. You may want to revise your strategy though."

We're 30 weeks into 2008 and I've only done 74 of the 356 problems in that legendary text, the Structure and Interpretation of Computer Programs, which was the central object of my study this semester. That's about two and a half problems a week. Not my brightest shining moment. This whole experience definitely gives me new appreciation for the people that tried to structure and/or educate me in the past. Clearly, I need one of two things:

1) A good kick in the ass to really get going.
2) A new gameplan.

Personally, I'm going to try a mix of the two. Where 1) is concerned I recently wrote a self-study program (the biggest program I've ever written, actually) to help me keep abreast of my own progress and help me chart my course a bit. Where 2) is concerned I'm going to have to start making concessions to maintain momentum and I'm not entirely comfortable with that.

What concessions do I mean? Well, some of the SICP problems are hard. Really hard. Unreasonably hard (see Exercise 4.79 at the bottom for which a good answer is "probably worth a Ph.D."). The book has it's reputation for a reason. It's a reputation of difficulty but also of enlightenment. A lot of very smart people say it's the best way to learn Computer Science and probably the best book on the subject yet written. I'm willing to take their word for it. Anyway, there are problems that I get hung up on and I haven't been letting myself move on to the next section of the book without solving all the problems in the current section. That just isn't scaling well. I'm already hung up on the last 4 problems in Section 2.1. God knows what would happen come 4.4. I'll surely never finish the thing if I don't let myself move forward.

With that in mind, a week or so ago I did let myself move forward a bit and work on Section 2.2. I've already got about a third of it done. Maybe even half. I'm worried about this because I want to stay honest. I don't want to shirk the hard stuff. I won't move past problems unless I'm really stumped and I will circle back at various points to try to work through them. Aside from SICP, I've worked on HTDP (How To Design Programs) and CA (Concrete Abstractions) as well this semester. I got an almost reasonable portion of HTDP done but next to nothing on CA. I'd really like to try plowing through as much of those three books and The C Programming Language (rocking the 1st ed.) as possible before Xmas.

Semester 3 (starting in January) I'm hoping to work on Algorithms (DPV, not CLRS), Essentials of Programming Languages (1st edition, baby!) and one of my Operating Systems texts. Of course, Discrete Math (5th ed) would be more prudent and judging by this semester this could all be revised by Xmas. Well, back to work. Happy Hacking!

HTDP Section 02

posted on 2008-05-19 03:25:27

So, I've finally gotten around to cleaning up SICP Section 1.3. It's not quite done but it's damn close. For now, I want to start posting some of the HTDP code I've been writing to get back in the hacking habit over the past few days. I also have some of Concrete Abstractions done and in my source code repository but it's nothing substantial. Without further ado, here's HTDP Section 02 (of 43!). Sections 03 and 04 will go up tomorrow. Note: I skipped HTDP Section 01 because there are no exercises or problems whatsoever.

Adulthood and Academics

posted on 2008-05-14 03:39:37

Admittedly, the title of this post is a misnomer. I'm no adult yet. I am trying my damnedest to keep this house running smoothly though. As of today I think we're up on all the utilities and I've got a Static IP here with AT&T so I can move my server at some point. Work's been going well and I'm taking MARTA in to simplify my life a bit. I'm cooking (if you can call it that) and keeping the dishes done and the house clean with regularity. I'd say I've almost settled into a groove. I say almost because the people actually staying in the house won't stabilize until after May 25th. Heck, even I'm gone from the 17th to the 24th to house sit for my parents. For the most part though I'm enjoying myself.

Additionally,  I'm way behind on programming. I know. I've had a lot going on but my progress the last month or two is still just shameful. I've started HTDP to get the juices flowing again and am already through Section 03. It's definitely more straightforward than SICP if less revelatory. I'm considering going ahead and trying to blow through HTDP completely over the next month or two. Then I could circle back to SICP and hopefully be better prepared. I haven't decided on anything yet other than tidying up the presently unadorned answers to SICP 1.3 and then posting what I've got from HTDP so far. I am more than half-way through SICP 2.1 but I'm wondering if it makes more sense to knock out HTDP considering the difference in pace between the books. I'll let you know as I move forward. I'm hoping to get a post up with some pictures of my new digs in the next week or so. Feel free to drop me a line if you'd like to swing by.

SICP Section 1.3

posted on 2008-04-01 02:31:48

At long last, I'm through Chapter 1 of SICP. I'm a bit disappointed that Closures haven't been covered yet but they're in the first few pages of Chapter 2 and I've already got a few problems solved. As a matter of fact, I finished Chapter 1 last Wednesday it just takes time to get these posts up. I have a feeling I need to go back and study those explanations of Lexical Scope in Chapter 1 though. I'll try to write more about the experience thus far in a separate post. For now, here are my results for Section 1.3.


SICP Section 1.2

posted on 2008-02-29 19:39:36

I finally finished SICP Section 1.2 last night. I'm tremendously excited because this means that next week I can start tackling Higher Order Functions and (I hope) Closures. At any rate, here is the last month's work:


Pascal’s Triangle

posted on 2008-02-07 03:25:28

A little over two weeks ago I came up against Exercise 1.12 in the venerable Structure and Interpretation of Computer Programs.


The exercise wants you to write a recursive program to compute elements of Pascal's Triangle.


This exercise has pretty much infuriated me and it's all my own fault. Upon first hearing the problem statement I got it in my head that the function should look something like "(define (pas n)...)". I always think of number series being described in terms of a single argument (i.e. the 12th element) so it seemed natural to me that the pascal's triangle function should be computed in this way even though it is not, in some sense, a traditional series.


After a while, I cracked and read the precursor text (but not the code) to Eli Bendersky's solution and noticing that he defined the function with two arguments (for columns and rows) arrived fairly quickly with that insight at what seems to be the more or less standard solution. I have had this much completed for a week but gotten stalled trying to figure out the problem of a pascal function that takes one argument.


As of today I've solved the problem though and hoped to share my results here. First, the throwaway code that ended up being good for nothing!



(define (is-one? element)
(define (is-one-iter ones count flag)
(cond ((< element 5) #t)
((= ones element) #t)
((> ones element) #f)
((= flag 1) (is-one-iter (+ ones 1) count (- flag 1)))
(else (is-one-iter (+ ones count) (+ count 1) (+ flag 1)))))
(is-one-iter 4 2 0))
;Value: is-one?

That code tests to see whether a given element equals one and it does take a single argument which is nice. I couldn't figure out a way to use it to compute the actual elements though.


After a little bit of experimenting I stumbled on this number sequence (OEIS #A080956) which when put in the following procedure would allow me to compute n from a given column and row.


EDIT: Corrected dyslexic mistake in my code (I'd replaced all instances of col with row and vice versa). See comments.



(define (n-from-rowcol row col)
(define (f x)
(- (/ (* (+ x 1) (- 2 x)) 2)))
(+ row col (f (- row 1))))
;Value: n-from-rowcol

Now all I had to do was find a way to reverse the function to give me the inputs if I gave it the output. I actually stumbled upon another number sequence (OEIS #A000124, also known as the Lazy Caterer's Sequence) which when put into the following procedure returns the correct column and row for a given element. At last, working code:



(define (pascal n)
(define (pas col row)
(cond ((= col 1) 1)
((= row 1) 1)
((= col row) 1)
(else (+ (pas (- col 1) row)
(pas (- col 1) (- row 1))))))
(define (colrow-from-n)
(define (col-iter count)
(define (f x)
(- (/ (+ (square x) x 2) 2) x))
(cond ((> (f count) n) (pas (- count 1) (- n (- (f (- count 1)) 1))))
((= (f count) n) (pas (f count) 1))
(else (col-iter (+ count 1)))))
(col-iter 1))
(colrow-from-n))
;Value: pascal

Any insights into cleaner code, better algorithms, or comparisons between the two number series are welcomed.

The Rubber Meets the Road…

posted on 2008-01-25 05:33:05

and I find the resources to read. This SICP studying is harder than I ever could have imagined. I have done approximately nothing in my math, putting me about two weeks behind tomorrow. My focus has been entirely on SICP. SICP, I'm only a few days behind on thankfully. It's really hard stuff. And as somebody noted, charmingly, at this stage it practically is math. And proof by induction, recursive functions, golden ratios and Fibonacci sequences math. Not your grandpa's arithmetic.

Anyway, I've dug up some resources hitting snags here and there. It's what I do. So far, I've found a really great SICP Wiki (but it's half Russian), and a pack of people that have studied it from the Open Courseware over the past year.

That pack is as follows:
Ken Dyck's Solutions
Peter Sheats Solutions
Chuck Hoffman's Blog
Michael Harrison's Solutions and Commentary
Ozten's Solutions and Commentary
and finally, The Lispy Solutions and Commentary which so wonderfully motivated and inspired me tonight. Particularly with regards to a remark on Section 1.1 "just lulling you into a false sense of security".

Of course, there is also the aforementioned SICP Wiki and Eli Bendersky's Blog. Long story short, I really owe it to Lispy for encouraging me. Half way through section 1.2 I was bogged down. Roughly on exercise 1.13 which apparently gave a few other people trouble too. And I felt all alone.

Anyway, I'm going to try to push my schedule back a week and see if by next Friday I can be up to lambdas and through 80 pages of Discrete Math and then continue as planned. At the very least, I've known from day one that the one thing I want most to accomplish this year is wringing as much as I can out of SICP. So if it takes the whole year just to do that, schedules be damned, so be it.

Trial by Triangle

posted on 2008-01-24 02:31:11

Today was not the easiest day. It wasn't terrible either. The news was decidedly mixed. And it's not about Dad though if you're wondering he's doing well. He's undergone chemo and lost most of his hair but he's generally upbeat and energetic.


Two things have been wearing on me today and the first is work-related. Since January 11th I've been working full time at TVS. The news was that I finally got the paperwork for my benefits package today. It's nice having benefits. Benefits are good. All the same, this meant I could start doing budgeting and working out my finances.


Finances are some scary shit. If I didn't know better I'd swear I'd die without a sizable chunk of money a year. For now I'm still staying with my parents until summer (at their behest more than mine) and I'll find a place to live then.


I really am making enough to be okay. It's just that there's not a lot on the margins. I don't want a whole bunch of stuff. I just don't want to worry about suddenly needing money for any reason.


Anyway, the other struggle has been that of the triangle. I'm getting behind on my schoolwork and hoping to catch up by/over the weekend. And I was pretty distressed because I spent like 4 hours obsessing over exercise 1.12 in SICP.


The problem is to write a procedure that computes the elements of Pascal's Triangle.


That shouldn't be a big deal, you know? But I obsessed over it. And now I've got a silly over-engineered solution that I'm more fond of than I should be. It's an interesting problem though. Hopefully I've learned something from it.


Mine still isn't quite working and I know there is a simpler way to do it. I cracked after a while and read about how one might solve it but I didn't peek at any code. Still, I'm stuck on doing it my way. I'm such a bastard. Anyway, it's coming together and I expect it'll be done by the end of the hour. It'll be in the week 2 recap for sure.


Long story short I realized what I've gotten myself into today. And it's still where I want to be. It's just that I think it's going to take more work and time than I might have been able to understand.

SICP Section 1.1

posted on 2008-01-19 03:18:23

Well, I said I would do this and I meant it. These entries will be a bit lengthy. I feel a little pain for any feeds I'm aggregated on. So, in the interest of not driving you all mad, these weekly semester updates will be behind a cut.

Spring 2008 Schedule and Syllabus

posted on 2008-01-17 03:17:24

So, I've finally gotten everything nailed down. I know what courses I'm taking, what resources I'm using, and what my schedule is.


I've decided to break my studies into 2 semesters each of which is comprised of two courses and lasts 20 weeks. The first semester started this Monday (1/14) and ends Friday (5/30). I then take the month of June off. The second semester will start Monday (7/7) and end (11/21). Having June and December off will both motivate me to push through and also allow room for slight changes in schedule.


I'll study SICP and Discrete Math with Applications by Rosen this semester. I've already started in on the SICP. Obviously I'm a little behind on the math. At the end of each week I'm planning to post a summary of exercises and notes at least for the programming courses. I don't know what I'll do on the Math course. I also haven't quite settled on whose problem sets to do. Ah, well.


Next semester it's HTDP and CTM. I'm a little freaked out looking at all this but if I try I'm bound to learn something. Wish me luck.


And here's the week by week breakdown of the first 4 weeks for each course:


discrete math: resources include lectures, problem sets, and course notes

dma - 787 pages / 20 weeks = 39.35(40) pgs/week

1 is lecture 11-01-00 and pgs.1-44 (through section 1.3)

2 is lecture 11-02-00 and pgs.44-80 (through definition 4)

3 is lecture 11-03-00 and pgs.80-119 (through chapter 1)

4 is lecture 11-06-00 and pgs.119-161 (through theorem 7)


sicp: resources include lectures, online book, course notes, problem sets, and eli bendersky's site

sicp - 610 pages / 20 weeks = 30.5(31) pgs/week

1 is lecture 1-a and pgs.1-31 (through section 1.1)

2 is lecture 1-b and pgs.31-62 (through section 1.3.1)

3 is lecture 2-a and pgs.63-97 (through section 2.1)

4 is lecture 2-b and pgs.97-126 (through section 2.2.3)


As far as my schedule goes, the plan is to work from 7am-3pm Monday through Friday, go to the gym after work on MWF, and veg on the weekends where possible. The workweek will be dedicated to my "education" of course, beyond work and exercise.

Latest Learnings: Lessig and Lisp

posted on 2008-01-16 04:34:47

So, I've been meaning to post about the things I taught myself in Montana and my course of study and a course schedule through May/syllabus but I had to recover some partitions on my desktop. My laptop also was caught between Ubuntu Hardy Alpha 2 and Alpha 3. I'm not getting into it. It's a long story. Anyway, now that all my systems are running flawlessly I'll speak a little on the aforementioned subject matter.

I have a long term plan for a course of study but no hard schedule yet. I have to divide up readings and problem sets and link them with lectures and such. I plan to have such a syllabus done and up for viewing by the end of the week. As for the long term plan of study there are 6 Programming Texts and 3 Math Texts that I'd really like to get through. If I get through the first 3 Programming Texts (or even the first 2) and 1 or 2 of the Math Texts I'd consider it a successful year. They're all fairly rigorous and I'd like to cover them in depth. Of late, I've been debating the order in which to approach the programming texts. Either SICP, CTM, HTDP or HTDP, CTM, SICP. Some of the stuff in SICP is a bit difficult and some of the stuff in HTDP is a bit easy so far. This is another thing I'm hoping to have worked out by the end of the week so that I can get going.

Once I do have a syllabus I'll post it and then post notes on readings and lectures and solutions to exercises as I go along so feel free to follow along and ask questions. You can only help me learn more. So far, I read the first 40 pages of SICP in Montana. That's Chapter 1 (of 5), Section 1.1. I've got notes typed up on the lecture and reading and most of the examples solved. I'll get those posted up by Friday as the first entry whatever my course of study turns out to be. Also, Friday I will be going to that Yeasayer concert. So far Ben Grad and Minor are talking about going too. Any more takers? Have you guys liked Yeasayer as much as I have? Isn't that Red Cave song from yesterday awesome?

Finally, here are some good Lessig quotes my readings in Montana of The Future of Ideas (Pgs. 1 - 99):

"The very idea that nonexclusive rights might be more efficient than exclusive rights rarely enters the debate. The assumption is control, and public policy is dedicated to maximizing control." - Lawrence Lessig, The Future of Ideas, Pg. 86

"Where we have little understanding about how a resource will be used, we have more reason to keep that resource in the commons. And where we have a clear vision of how a resource will be used, we have more reason to shift that resource to a system of control." - Lawrence Lessig, The Future of Ideas, Pg. 88-89

"The point is more than theoretical. In essence, the changes in the environment of the Internet that we are observing now alter the balance between control and freedom on the Net. The tilt of these changes is pronounced: control is increasing. And while one cannot say in the abstract that increased control is a mistake, it is clear that we are expanding this control with no sense of what is lost. The shift is not occurring with the idea of a balance in mind. Instead, the shift proceeds as if control were the only value." - Lawrence Lessig, The Future of Ideas, Pg. 99

Unless otherwise credited all material Creative Commons License by Brit Butler