A Teacher looks at Advent of Code 2016 #1

I recently posted about Advent of Code - a series of programming problems relseased one a day. While they vary in terms of level of difficulty, a number of them make nice problems for introductory to mid level programming classes.

I thought I'd share some of my thoughts on a few of them starting with the first problem from this years competition.

Take a minute to read it over.

At first glance, it might seem to a young programmer that this problem requires a two dimensional array - all about (x,y) coordinates but then there's a problem - there are no limits on coordinates and we can't make an unlimited size array.

After thinking a bit, hopefully the programmer realizes that all they need to do is keep track of the how the (x,y) location changes over time. In the solution below, we start at (0,0) and count the steps as we update two variables x and y.

When we finish processing the moves, we have our current location in (x,y) and we have the number of steps taken to get there.

The solution below hsa a couple of niceties that a beginning programmer might not know or use (and I'm not arguing that what's written is superior in any way, it's just what I ended up writing).

I make use of tuple destructuring:

x,y = (0,0)

which assigns x to the first item in the tuple and y the second. I used that a number of times

I also use a list I call dirs to hold dx and dy values for the four direcitons:

dirs=[(0,1),(1,0),(0,-1),(-1,0)]

This made it easier to to update the location based on the 4 directions. I could also have just used if statements.

Here's all the code:

x,y = (0,0) # assume our starting location is 0,0

# we start with d=0 -> facing north
# as we turn left or right, we can just increment or decrement d
# and dirs[d] will give us the appropriate dx and dy to update
# our locatoin for the next step
dirs=[(0,1),(1,0),(0,-1),(-1,0)]   
d=0

# This is only needed for part 2  - We track visited locations
# by adding them to the dictionary. If we try to add a location
# that's already been visited we know that we've found our final 
# location
# locs={}  # uncomment this line for part 2


totalsteps=0
for i in l:

    # the first char in i is the direction to turn in (L or R)
    # the rest represents the number of steps.
    dir=i[0]
    steps=int(i[1:])

    if dir=="L":
	d = (d+1)%4
    else:
	d = (d-1)%4
    (dx,dy) = dirs[d]
    for i in range(steps):
	(x,y) = (x + dx, y + dy)
	totalsteps=totalsteps+1

	# Uncomment this block for part 2
	# each time we have a new location, see if it's already in
	# locs, if it isn't, add it.
	# if it is, we're visiting somewhere twice so we're done.
	#if ((x,y) not in locs):
	#    locs[(x,y)]=1
	#else:
	#    print((x,y))
	#    print(abs(x)+abs(y)) # the answer
	#    sys.exit(0)
	#    break


print(x,y)
print(abs(x)+abs(y)) # the answer

Overall, a nice little problem for beginning and intermediate students.

Using Emacs - 24 - Org Capture 2

Not much in today's actual post. The video is a continuation of the last one on org-capture.

The video goes over how I set things up to pop up a new frame to do a capture even if emacs isn't on screen (as long as it's running) by hitting F1. I would have preferred to bind to C-c c - the same as within emacs but I havn't figured out how to do that in Ubuntu or Mint Linux yet.

Here's the elisp code for the configuration file to do the heavy lifting. I can't for th elife of me remember who's blog I found it on. If anyone knows, please leave a comment - I'd like to give credit where credit's due:

(defadvice org-capture-finalize 
    (after delete-capture-frame activate)  
  "Advise capture-finalize to close the frame"  
  (if (equal "capture" (frame-parameter nil 'name))  
    (delete-frame)))

(defadvice org-capture-destroy 
    (after delete-capture-frame activate)  
  "Advise capture-destroy to close the frame"  
  (if (equal "capture" (frame-parameter nil 'name))  
    (delete-frame)))  

(use-package noflet
  :ensure t )
(defun make-capture-frame ()
  "Create a new frame and run org-capture."
  (interactive)
  (make-frame '((name . "capture")))
  (select-frame-by-name "capture")
  (delete-other-windows)
  (noflet ((switch-to-buffer-other-window (buf) (switch-to-buffer buf)))
    (org-capture)))

The command I bind to the keyboard shortcut in my window manager:

emacsclient -ne "(make-capture-frame)"

There will be a third capture video in a few weeks where I'll talk about scheduling and agendas. Right now, I'm playing with org-gcal to sync with my Google calendar and want to figure out a config I'm happy with before making that video.

Advent of Code 2016

Once again, it's time for Advent of Code - a series of small programming problems released once a day.

I wrote a bit about it last year and you can still find last years problems here.

It's only day three but so far, all of the problems look really nice for students in APCS-A or any similar intro course. I'm thinking of looking at a couple of the problems this week with my class at Hunter.

I didn't think about this much last year but one thing I really like about the competition is that each problem comes in two parts. You're first presented with the problem and the input and once you put in the correct answer, you're presented with part two.

This can be annoying at times, particularly when it requires a large code rewrite but it also means that well designed, not too specific solutions are rewarded.

It's not quite the same as changing the specs on a project mid way but it does encourage thinking about more than just solving a super specific problem.

Check out Advent of Code and see if it's something you or your classes might enjoy.

Selling out or getting a seat at the table

The other day, a friend posited a question on Facebook (paraphrased):

If called upon, would you take a job in an administration who's policies you strongly disagreed with?

Would you go work for an administration that you reviled in order to get a seat at the table? To try to affect change from the inside or would you consider yourself a sellout or worse, publicly promote positions you disagree with.

Tough question.

The original question implied national level positions. I've never and will never breath such rarefied air but I have had such experiences closer to ground level, both with DOE projects and also in conversations with some charter chains.

My take?

Anyone that knows me knows that I've had various dealings with the NYC DOE and also knows that those dealings never resulted in outcomes I was happy with. Over my time at Stuy, I had many philosophical differences with Tweed (a common nickname for the NYC DOE as they're housed in the old Tweed courthouse) and these were times where I tried to play nice to have a seat at the table.

Once I was at a meeting that also included a number of tech industry heavy hitters. After the meeting, one came over to me. He knew me by having worked with my former students. I knew him by reputation. He asked "do they really want our thoughts on this or are we just here so that they can do what they wanted in the first place and then parade us out to say that they consulted experts in the tech industry?" I honestly didn't know at the time but I had my doubts as to the DOE's sincerity in being open to either my views or this CTO's As it turned out, they just did want to parade us. Later in the process, I was told in a back room that it would be wise of me not to publicly voice my thoughts about the direction of one particular project.

So there you have it. I was given a seat at the table but only as long as my views mirrored the views of those in power. Not really much of a seat.

I've also sat down with some charter chains - chains that I've been more than happy to denounce publicly. Why did I take the meetings? Mostly to find out if I was mistaken in my position and if so, maybe I could help them. Every time I've had such a meeting, however, I've left the table with my feelings unchanged and knowing that I would never willingly help them as I felt their practices were harmful to kids.

In one case, I took the seat but failed to affect change. In the other I refused the seat. I'll always take a meeting and I'll always work with someone who wants to help kids and who has an open mind but I've found that the more powerful the player, at least in education, the more likely they are to just want confirmation of their own bias.

You might get a seat at the table but you also might end up lending your reputation to a cause you don't believe in.

Using Emacs - 23 - Org Capture 1

Org mode has an amazing feature - org-capture. I only started using it recently but it's really awesome.

What took me so long?

Probably that the manual seemed a little intimidating.

It really isn't hard, though. Combined with what I'll go over in the next video and post (and a future one for Google calendar sync) it's what I use for:

  • recording blog ideas
  • managing bookmarks
  • taking short Notes
  • managing my calendar.

I use the binding:

(global-set-key (kbd "C-c c")
       'org-capture)

By default, running org-capture brings up a form to capture a "task" but things get really cool when you start making your own capture templates. With capture templates, you can speed up recording information and then tell org-mode to store it where you want it.

Here are my template settings.

(setq org-capture-templates
      '(("a" "Appointment" entry (file  "~/Dropbox/orgfiles/gcal.org" "Appointments")
	 "* TODO %?\n:PROPERTIES:\n\n:END:\nDEADLINE: %^T \n %i\n")
	("n" "Note" entry (file+headline "~/Dropbox/orgfiles/notes.org" "Notes")
	 "* Note %?\n%T")
	("l" "Link" entry (file+headline "~/Dropbox/orgfiles/links.org" "Links")
	 "* %? %^L %^g \n%T" :prepend t)
	("b" "Blog idea" entry (file+headline "~/Dropbox/orgfiles/i.org" "Blog Topics:")
	 "* %?\n%T" :prepend t)
	("t" "To Do Item" entry (file+headline "~/Dropbox/orgfiles/i.org" "To Do Items")
	 "* %?\n%T" :prepend t)
	("j" "Journal" entry (file+datetree "~/Dropbox/journal.org")
	 "* %?\nEntered on %U\n  %i\n  %a")
	("s" "Screencast" entry (file "~/Dropbox/orgfiles/screencastnotes.org")
	 "* %?\n%i\n")))

Let's look at the Blog entry:

("b" "Blog idea" entry (file+headline "~/Dropbox/orgfiles/i.org" "Blog Topics:")
 "* %?\n%T" :prepend t)

It's a list with a bunch of options. The first string b is the key to type to select this template, Blog idea is the actual name for this template.

The next item, entry describes the type of template you're creating. entry says you're going to create an org node with a headline which can then be added to an org-file. You can also have your template create things like an org list item a checkbox checkitem or even plain text. You can see the full set of options here.

Next, in parentheses, you have the target - where to store the captured info. The Blog idea template says file+headline followed by a filename in quotes and a headline in quotes. This says to store the new org heading you're capturing in the file "~/Dropbox/orgfiles/i.org" under the heading "Blog Topics:" Contrast this to the appointments template which just specifies file and a filename. The appointments template will just append the new appointment to its specified file whereas Blog idea will prepend (due to the :prepend option at the end of the template) to the "Blog Topics:" heading in i.org.

After this we have the actual template: "* %?\n%T" - the %? and %T are placeholders for substitutions. The %T prompts for a date with a timestamp and the %? is where to leave the cursor for final input before saving the capture.

Finally, :prepend and other options can be found at the above link.

All the substitutions can be found in the docs.

Once you've set up your templates, it's quick and easy to capture information.

This video shows the basics. The next one shows how to pop up a capture even when you're not in emacs and how I use org-capture to maintain my web bookmarks.

More information on capture templates can be found here.

Inverted Index Project

I haven't spoken much about the class I've been teaching this semester. It's an intro CS course - a programming heavy intro. I decided to use Python with a transition at the end to C++. The transition is to mirror Hunter's normal first CS course that ends with a C++ intro to prepare the students for next semester's CS course which is a more intense OOP class using C++ - the language we use in our core courses.

Throughout the semester I've tried to use a variety of interesting application areas so as to try to give the students some idea of the possibilities that studying CS will open up for them.

After covering Python dictionaries and lists I thought we'd play by building an inverted Index.

The basic idea is to map a set of words back to source files. For example, given the following four one line files:

files     contents
file.01     if you prick us do we not bleed
file.02     if you tickle us do we not laugh
file.03     if you poison us do we not die and
file.04     if you wrong us shall we not revenge

You could build a data structure mapping each word back to the file(s) that contain it (partially shown here),

Word   Files containing It's
if   file.01 file.02 file.03 file.04
you   file.01 file.02 file.03 file.04
prick   file.01
us   file.01 file.02 file.03 file.04
do   file.01 file.02 file.03

You can, of course, store more information - how many times a word appears in a file, where it appears, etc.

This is a fairly easy structure to build. A dictionary where the keys are the words in the file and the values are lists of the documents containing the words.

  inverted_index = {
      'if' : ['file.01','file.02','file.03','file.04'],
      'you' : ['file.01','file.02','file.03','file.04'],
      'prick' : ['file.01'],
      'us' : ['file.01','file.02','file.03','file.04'],
      'do' : ['file.01','file.02','file.03'],
      ...
}

In addition to letting us work with dictionaries and lists, we can also review file access and even the python CSV module if we want.

We can immediately write simple queries – "what document(s) contain the word 'prick,' but things get more interesting if you write functions to perform and and or queries - "what document(s) contain the words 'prick' or 'do'" for instance.

Why are we building this (besides as a data structure and programming exercise)? I've seen a number of references to using an inverted index when building a web search engine. In fact, I think that's something you do early on in the Udacity Mooc. I just wanted to play with information retrieval.

I remembered that there was a collection of information, including last statements from executed offenders in Texas. Someone conveniently converted it into a Google Spreadsheet. The format's a little different from our simple four file example but then there's more data. It's straightforward enough to download the spreadsheet as a CSV file and then read it with a Python program that builds it into an inverted index.

Now we have some interesting data to play with.

How many offenders used words like "sorry" or "apologize?" How about references to religion? We can do all sorts of and and or queries.

We just played with this a bit but I could see all sorts of explorations. What about taking some great work of literature and turning it into an inverted index by chapter. You could query characters or certain words and see where and when they appear in the book. A new and different way of exploring literature.

So, there you have it - an interesting little project we played with this past semester. We did it in an intro Python course but I could see it as an interesting project in AP CS A using hashmaps and lists.

Evaluate teachers like they do in the real world

This old article has been reposted a few times in my circles over the past few weeks http://educationnext.org/facadeofexcellence/. It's from 2003 and complains about the lack of flexibility schools had back then with regard to hiring and salary. The article is old and out of date and the seniority system no longer holds for hiring but it does for lay offs. The salary scale from back then, though, is still in place.

My friend Alex asked my thought about how we might deal with evaluating teacher quality. I thought I'd share them here.

Alex listed a number of commonly tried and suggested options on teacher evaluation and why they're all flawed.

I haven't asked Alex's permission so I won't post his list and comments here. Instead let's start with the boogeyman those that attack public education always trot out – tenure.

Let's get a couple of things straight - tenure is not a job for life. For K12 teachers, it's the right to due process. That means you can't be fired without cause.

I hear the free market capitalists out there already – "in the real world, you're an at will employee, why do teachers need this due process?" - I'll get to that down below. For now, let's look at a few points on tenure:

First - you can fire a tenured teacher, you just have to document your case. This means that the supervisor has to actually do their job.

Next - people can complain about rubber rooms and the time it takes to fire one of these tenured teachers. That's because the DOE won't hire sufficient hearing officers. In a recently resolved case, a friend of mine - a terrific AP was finally returned to her post after she was railroaded on false charges. She was in the rubber room for years. The DOE kept delaying the process – all she wanted was to go to "trial" since everyone knew she'd be exonerated - the fact that she was up on charges at all speaks to why teachers need tenure.

Next - teachers don't grant tenure, the administration does. Why are all these horrible teachers being granted tenure? Stories abound of administrators granting tenure to bad teachers so long as they transfer to another school - who's to blame here?

Finally, the contract that establishes tenure is jointly negotiated by the teachers union and the city - no one ever seems to complain about the city.

Next, let's talk about bonuses and competition. People in the business world take the false assumption that everyone thinks, acts, and feels like they do. Here's a surprising fact – teachers aren't in it for the money. Sure, we'd like to make a little more - perhaps enough to actually live in a decent apartment and not need a second job to make ends meet - but no one went into teaching to get rich. Teachers are in it to uplift ALL their students and their school as a whole.

Now let's look at the model currently in vogue - value added measures. Besides the fact that they're arbitrary and don't work (see this post and this one) they're nothing like how people are evaluated in the real world.

How are people evaluated in regular jobs? As far as I know, they're evaluated by their managers and bosses - possibly also by their peers.

Funny thing - that's how teachers used to be evaluated before all this nonsense brought about by the "reformers." Of course, no one will admit to this.

Did this system work? For the most part, but not entirely. Why were there problems? Because, unlike a business, principals are not necessarily incentivized to have the best teachers.

Schools and principals are evaluated on ridiculous metrics - the same standardized tests they use to evaluate teachers. To look at a small piece – to graduate high school, kids need to pass at least one math regents and pass three years of math classes. To be "college ready" a student still only needs to pass one math regents and take at least one year of geometry or trig.

This means that as far as math is concerned, a principal is incentivized to have a math department that can get their kids through the algebra regents. Here's how this frequently plays out. The kids take algebra over two years and then passes the exam. The kids take geometry as their third year. They don't have to pass the regents, but it appears that in order to increase a student's chances of passing that exam, classes don't teach proof - the most important and hardest part of the class. Why not? Because it's easier to pass the exam by learning most of the other stuff.

Here we have a school where the incentive is to hire teachers that can teach to the algebra regents and that's about it.

That's at a school with a low performing population. In a higher performing school, the kids will do well on the standardized tests regardless of teacher quality so there's no incentive to hire the best. Even if that's what they want to do, there's no way to know if they're actually doing it.

Back to why teachers need due process. Since principals aren't held accountable in any reasonable way, teachers can't be. The end result is that teachers are subject to abuses by principals. I myself was once brought up on bogus charges raised by a principal (not a Stuy one) who wanted to make trouble. Without due process, I would be out of a job. So would many others.

The answer? To me it's figure out how to hold principals accountable. In Alex's Facebook post he mentions evaluation by college and workforce success but that has a slow feedback loop. The truth is, education does have a slow feedback loop. Schools, however, exist for along time and principals should have tenure periods of more than just a couple of years.

My feelings? Why not look at graduates succeeding in college or on the tax rolls? This wouldn't be perfect but it would be a start. While NY can't count on private universities sharing accurate information in a timely manner there should be a way of tracking if a high school graduate is enrolled in a SUNY or CUNY one, two, three, or four semesters after graduation. Create a baseline for a school and start from there.

If principals were actually accountable in a reasonable way they'd have incentive to have the best teachers. Then we can get back to the old system which was indeed the way the "real world" works.

Using Emacs - 22 - emacsclient

Another quick hit today.

This video is really setting the stage for hte next two, where I talk about org-mode capturing.

Today, we're demoing the use of the emacs server and client.

Back in the old days, emacs took a LOOONG time to load. A complex conviguration could take on the order of 10 to 20 seconds. This resulted in people loading emacs at the start of the day and leaving it up forever. While load times aren't much of an issue anymore, it's still nice to leave emacs around all the time.

That's where running emacs as a server comes in.. I set up a keyboard shortcut my window manager to run:

emacsclient -a "" -c

Rather than trying to run emacs, this tries to connect to an already running emacs server. The -c creates a new frame. Instead if you use -t it will open emacs in the terminal. The *-a ""* tells emacs to run itself as a server (daemon) if it isn't already running.

Later on, running emacsclient -c will very quickly bring up a new frame to the server.

In addition to instant loading, Running emacs this way has the advantage, or some may say disadvantage of keeping buffers around forever since you just keep emacs up and running.

Using Emacs - 21 - web mode

Quick post today.

The video goes over web-mode - my preferred weapon for html and all the goodies you embed in an html file.

It's multi-modal so it acts sensibly regardless of wether you're editing html, css, javascript or even templates in a single file.

Note: In the video, web-mode wasn't automatically inserting quotes. I had to set hte following variable to fix this:

(setq web-mode-enable-auto-quoting t)

Giving the final configuration I'm currently using:

  (use-package web-mode
    :ensure t
    :config
	 (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
	 (setq web-mode-engines-alist
	       '(("django"    . "\\.html\\'")))
	 (setq web-mode-ac-sources-alist
	       '(("css" . (ac-source-css-property))
		 ("html" . (ac-source-words-in-buffer ac-source-abbrev))))

(setq web-mode-enable-auto-closing t)
(setq web-mode-enable-auto-quoting t)) ; this fixes the quote problem I mentioned

The web-mode documentation has more information including a nice chart of all the key bindings.

Using Emacs - 20 - yanking

Today's video is a bit of a follow up on the last one as well as a few miscillaneous configuration.

We got some comments on alternate ways to load a file if it exists - it's always cool to see how different people end up doing similar things.

We then talk about three little configurations. Two I found out about reading Jon Sander's (jcs) blog Irreal. Jon's blog is a terrific source of emacs info - if you don't subscribe, you should.

I go over using counsel for working with the kill-ring. The command counsel-yank-pop acts as a replamcement for yank-pop and it lets you easily yank anything from the kill ring - not just the most previously killed/whacked piece.

You just hit M-y and then either keep hitting it or use up and down to select what you want to yank.

Here's the original post from Irreal: http://irreal.org/blog/?p=5707.

I then briefly talk about smoothing things over between the system clipboard and the kill ring, also from Irreal: http://irreal.org/blog/?p=5702.

Finally, I talk about auto-revert-mode - this monitors files on your file system and when they change, they reload your buffer. I find this very useful to keep multiple machines in sync when I'm working with files in a could based filesystem like Dropbox or Owncloud.


Enter your email address:

Delivered by FeedBurner

Google Analytics Alternative