Programmer by day, artist by night

Posts from the Stanford University Category

Professor Paul Hegarty of Stanford University teaching Developing iOS 10 Apps with Swift, from Lecture 1, graphite on copier paper, 8.5″ x 11″

The course Developing iOS 10 Apps with Swift by Stanford has been around for a while (about 6 months) free on iTunes:

Had been following the course since the Objective-C days and it’s time to take the latest version in the same tradition.

Here are the course contents based on the 17 lectures :

1. Introduction to iOS 10, Xcode 8 and Swift 3
2. MVC; iOS, Xcode and Swift Demonstration
3. More Swift and the Foundation Framework
5. Gestures and Multiple MVCs
6. Multiple MVCs, View Controller Lifecycle, and Memory Management
7. Error Handling, Extensions, Protocols, Delegation, and Scroll View
8. Multithreading and Text Field
9. Table View
10. Core Data
11. Core Data Demo
12. Autolayout
13. Timer and Animation
14. Dynamic Animation Demo
15. More Segues
16. Alerts and Action Sheets, Notifications, Application Lifecycle, and Persistence
17. Accessibility

Will publish the code like before on Github but this time will put all the projects and assignments in one repository:

So follow along, if you want, with me and feel free to point out if my code can be improved or if the projects and assignments can be done better 🙂 Good luck!

From the Course Programming Methodology CS 106A Offered at Stanford University

Having spent more hours than I am willing to admit, finally solved Karel the Robot Problem 3 (from Assignment 1).

Please don’t look at the solution until you have solved it yourself. Otherwise you will be depriving yourself of a cool mental accomplishment.

Having said that, here’s my train of thoughts as I was trying to solve the problem:

1. Thought that ignoring the checkerboard might lead to a simpler solution. Think linearly about Karel dropping beepers alternatively on each move “over a single horizontal line” till the end is reached. Later turn the horizontal line into a checkerboard. Made some progress but the solution started getting increasingly complex.

2. Realized that the core of the problem is really the turns Karel needs to make while traversing through the checkerboard. Dropping beepers at alternate locations isn’t the real problem. So I ignored the beeper issue. This lead to a cleaner solution.

3. Karel’s movement itself shouldn’t be in any if/else control statement. It makes a mess of the code because of too many if/else checks. Karel should just move forward. Then figure out which direction it should face. You can see this behavior in lines 26-29 below. Lines 31-49 shows the logic behind setting Karel’s direction.

4. Finally the beeper code is in line 17, 19. Karel moves twice in each iteration of the while loop. Line 19 checks for even-count columns in Karel’s world. Line 21 puts a last beeper for odd-count column worlds.

5. Line 15 checks for a single-count column world.

I Googled for other solutions to compare after solving the problem. Feeling happy that the solution below is 50 lines of code. If you can think of a simpler solution then please let me know.

 * File:
 * ----------------------------
 * When you finish writing it, the CheckerboardKarel class should draw
 * a checkerboard using beepers, as described in Assignment 1.  You
 * should make sure that your program works for all of the sample
 * worlds supplied in the starter folder.

import stanford.karel.*;

public class CheckerboardKarel extends SuperKarel {

	public void run() {
		if (frontIsBlocked()) turnLeft();		
		while (frontIsClear()) {
			if (noBeepersPresent()) putBeeper();
			if (frontIsClear()) {
				if (noBeepersPresent()) putBeeper();
	private void moveKarelForward() {
	private void setKarelsDirection() {
		if (facingEast()) {
			if (frontIsBlocked()) {
		} else if (facingWest()) {
			if (frontIsBlocked()) {
		} else if (facingNorth()) {
			if (rightIsBlocked()) {
				if (leftIsClear()) {
			} else if (leftIsBlocked()) {

Testing Checkerboard Karel in different worlds: