One nice feature of Piazza is that you can embed syntax-highlighted code by enclosing code between <pre></pre> tags, or $\LaTeX$ expressions by enclosing the formula between ${\tt $$\ $$}$ tags.
I have semi-automated the most annoying parts of the initial setup.
~adanner/public/bin/init46 cd cs46 git status git add homework/wk1/hw01.tex git add labs/wk1/power.py git commit -m "my first commit" git pushThe equivalent to handin is git push, but push only pushed things that have been committed and commit only commits things that have been added. You should only submit source code. Do not submit files that can be autogenerated/compiled. I have set up a .gitignore file to ignore the most common auto-generated files for this course, but feel to add to this list if needed. Use git status to determine if you need to do something
$ git status # On branch master # Untracked files: # (use "git add..." to include in what will be committed) # # homework $ git add homework/wk1/hw01.tex $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <<file>..." to unstage) # ... $ git commit -m "msg" $ git status # On branch master # Your branch is ahead of 'local/master' by 1 commit. # $ git push $ git status # On branch master nothing to commit (working directory clean)
The cs46/examples folder links to a public folder where I will occasionally post examples, homeworks, or starting point code for lab. The init script has already copied over stuff for this week, and in the future we will copy additional files out of this directory.
$ python power.py 3 '' 'a' 'b' 'c' 'ab' 'ac' 'bc' 'abc' $ python power.py 1 '' 'a'
import sys print "command: ", sys.argv[0] if len(sys.argv) < 2: print "Usage %s <n>" % sys.argv[0] sys.exit(1) n=int(sys.argv[1]) print nThe function ord(let) returns the integer ASCII value of character let; the function chr(val) returns the ASCII character with integer value val. Note ord(chr(val))==val and chr(ord(let))==let. You can construct a set of n letters using the following snippet
def shiftLet(ch, num): return chr(ord("a")+num) n=int(sys.argv[1]) alpha=[] for i in range(n): alpha.append(shiftLet("a",i))If L1 and L2 are two lists, you can combine the two sets using either L3=L1+L2 or L1.extend(L2). The first example makes a new list L3, while the second modifies L1 by appending all elements in L2
Use strings to represent elements of the power set. Instead of writing {a, b, c} you can just use 'abc'
Sometimes it might be helpful to copy a list. Use the string slicing operator l[:] to do this, e.g.,
l=range(5) l2=l #this probably doesn't do what you want l.append(10) print l print l2 #------------ l=range(5) l2=l[:] #OK l.append(10) print l print l2
Don't loop over a list that you are modifying inside the loop. This is weird, and often wrong, e.g.,
l = range(5) for i in l: l.append(2*i) #wee infinite loop #--better, non-infinite solution below -- l = range(5) newL = [] for i in l: newL.append(2*i) l.extend(newL)