Learning to Code: Week 5 – Game of Fifteen


  • Finished questions.txt for Game of Fifteen
  • Implemented init, draw, search, legalmove functions in my Fifteen.c program


  • Continuing work on Fifteen.c
  • Implemented swaptile function.
    • I forgot to change the location of the blank tile so it wasn’t working at first.
    • That was an easy fix and now the game seems to be complete except I need to make the won function work.
    • Also I had the search function be int search(int tile) when it actually doesn’t need to return anything so I changed that to void.
    • Not sure what I was thinking yesterday. It just needs to search, not return.
  • Worked on won function for a long time. I understood the implementation easy enough, just kept running into small errors and mistakes and it took a lot longer than I though to get it right!
  • I didn’t implement it this way, but I did see a cool little algorithm to determine that the tiles are in fact in the correct place on StackExchange afterwards: http://cs50.stackexchange.com/questions/1317/pset3-won-function-works-only-with-3×3-board-where-am-i-wrong/1320#1320
  • So the number at position board[i][j] should be equal to ((d*i) + (j+1)). That’s pretty cool.
    • I don’t think it makes much difference, but all I did was add a check to see if the counter was correct AND if the final tile was zero.
    • Both conditions had to be true to consider the game won.
  • See my solution in action below!

Game of Fifteen


Didn’t get much of anything done today, had a powerlifting meet. However, Jeff was kind enough to link this place in Atlanta called GreaterSum. It is a curriculum and internship/apprenticeship to create developers.

They seem to have coaching services that has code reviews and an apprenticeship that doesn’t pay much, but does allow for earning money while learning!

I will be attending their June 23rd workshop that is an introduction to Javascript.


  • My Grokking Algorithms book arrived. I started reading it. So far I’m on chapter 2.
    • Chapter 1: Binary search and Big O notation and Traveling Salesman problem.
    • Chapter 2: Arrays and Linked lists. Selection sort.
    • Chapter 3: Recursion
  • All the examples in the book are written in Python and so far I can already tell by trying to rewrite the examples in C that Python is a much easier/cooler language!
  • So for instance I’ve noticed so far that you don’t need to end a line with a ; nor do you need to use { } at all!
    • Also in a for loop you can just say for i in range(1, len(arr)) instead of for (int i; i < sizeofarray, i++).
    • Much less typing involved!
  • I just read python doesn’t use arrays, but instead just lists? Like linked lists or? What’s the difference?


  • Grokking Algorithms:
    • Chapter 4 QUICKSORT: Divide and Conquer, Quicksort, brief look at Inductive Proofs, Big O notation revisisted, Mergesort vs Quicksort, Avg Case vs Worst Case
    • Chapter 5 HASH TABLES: Hash functions, Use cases, Collisions, Caching, Performance, Load Factor

4.1 Recursive Sum Function in C

4.2 Recursive Counting Function in C (used repl.it)

4.3 Recursive Max Function in C

  • The standard C library already has a quicksort function called qsort!
  • How does quicksort differ from mergesort? (answered 3 pages later in book)


Wasn’t able to get much done today at all.

Discovered website: http://codepad.org/

A few books to add to my reading list:

  1. C Programming Absolute Beginner’s Guide (3rd Edition)
  2. C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast!
  3. C by Example (Cambridge Computer Science Texts)


Study resources: https://github.com/dargaCode/WebDevStudyResources


  • Watched Week 4 Lecture 1
    • How to swap variables without using a temporary placeholder.

Why does the above work though?

  • CS50’s getString() function only returns the ADDRESS LOCATION of the first letter in memory, and not the actual string.
    • So comparing strings to each other will never be the same.
    • So far have been using variables to store strings, but from now on we will use char*
  • Podcast: http://softwareengineeringdaily.com/category/podcast/ (It’ll go over my head I’m sure)
  • Watched Week 4 Lecture 2
    • Struct = custom data type! Cool.
    • Strcmp = string compare function already in C.
    • To pass address of variables into a function you have to use &. Example: swap(&x, &y)