Cs 3s????

<p>Not just the books, but also download and install the Scheme and Python language interpreters on your computer so that you can do the exercises in the books.</p>

<p>wait, so i signed up for 2 units of cs3s…should i still take this or not?</p>

<p>All you really need from CS3s/l is to know how to do recursion. If you understand that idea then you are good to go for CS61A. CS61A is mostly rough because they expect you to understand recursion from day 1. Just try to do some research on wikipedia and google or from books, etc.</p>

<p>Scheme and python are really similar. I’m not sure how this will format, but the first recursive function you will all learn is probably will be one that computes the factorial of a number. ( 0! = 1, 1! = 1, 2! = 2, 3! = 6 … )</p>

<p>The old language, Scheme:</p>

<p>(define (factorial n)
(if (<= n 1)
n
(* n (factorial (- n 1)))))</p>

<p>The new language, Python:</p>

<p>def factorial(n):
if n <= 1:
return n
else:
return n*factorial(n-1)</p>

<p>Notice the similarities in syntax (even if you have no idea what is going on). If you were to take CS61A in Python after CS3S in Scheme, chances are you won’t have a huge problem transitioning.</p>

<p>EDIT: formatting is really bad, you’ll learn that in Python, whitespace is not something you can ignore. Similarly, in Scheme, invoke the left-parenthesis with caution.</p>

<p>You probably want the Python example formatted like this:</p>

<p>


def factorial(n):
    if n <= 1:
        return n
    else:
        return n*factorial(n-1)

And here it is in a Python interpreter:


$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.</p>

<br>
[QUOTE=""]


<blockquote>
<blockquote>
<p>def factorial(n):
...     if n <= 1:
...         return n
...     else:
...         return n*factorial(n-1)
... 
factorial(1)
1
factorial(2)
2
factorial(3)
6
factorial(4)
24
factorial(5)
120


</p>
</blockquote>
</blockquote>

[/QUOTE]
<br>

<p>Now find the bug.</p>

<p>Yeah sorry for the white space problems.</p>

<p>And just because I’m curious, was the bug you’re pointing out that the code returns an incorrect value for negative inputs?</p>

<p>The obvious bug is that 0! is conventionally defined as 1, but the function given above returns 0. A one character change will fix it for the 0 case.</p>

<p>Of course, if you want to be even more careful, you would want it to return an error if a value other than a non-negative integer is given. (The use of more advanced mathematics to generalize factorial to other inputs would not be too relevant for an introductory computer science course.)</p>

<p>you could try out out malab too (9 series i think?) or e7 too (though might be harder)</p>

<p>who even uses scheme anymore? all the computation/neuro labs ive tried to get into seem to like matlab experience more</p>

<p>^^Jeezum crow…I hope you guys were just showing off.</p>

<p>^ I think you are expected to be able to read/write a code similar to what ucbalumnus posted on day one of CS61A.</p>

<p>i’m getting a no pass in this class, i procrastinated a lot of work.</p>

<p>Lol. I fail. Yeah, it should be return 1, not return n… .__. </p>

<p>And no, by the time you’re through with CS61A, factorial should be intuitive to you. It’s the “hello world” of recursion. I made a very careless mistake. </p>

<p>If you don’t understand it now, don’t worry. That’s why you take the class in the first place. :)</p>

<p>@Ankur: Did you have programming exp. before taking it?</p>

<p>haha no worries^^ i took the self-pace version frosh first semester with 17 other units and got an np lol (i switched to p/np after realizing i wouldnt pass due to procrastination too with those damn quizzes). take it again later as 3L…MUCH better.</p>

<p>@w4c: I don’t think will they offer 3L anymore. I guess now the only options are CS10, CS3S, and CS61A.</p>

<p>Okay so I have no programming experience whatsoever! Will I be okay if I directly take CS 61A?</p>

<p>^ Most likely you will have trouble getting an A, but a B is very possible. This is just based on my friends that have taken the class. About half of my friends had prior experience, and many of these students got As in 61A, and the other half, with no experience, struggled to maintain B’s.</p>

<p>You aren’t expected to know anything in the first day of class, they teach it to you :slight_smile:
But you are expected to pick things up really quickly.</p>

<p>I would say getting an A is definitely possible with a little work.</p>

<p>knitknots, nah, the class is easy as hell if you stay on track, but I can’t motivate myself to do it.</p>

<p>What other classes can I take to make up for this np? CS61A? I think I have a thorough grasp of scheme after taking this class and some knowledge about recursion.</p>

<p>waiting4college, are you applying to med school btw?</p>