teaching machines

CS 330 Lecture 3 – $h3||

January 27, 2013 by . Filed under cs330, lectures, spring 2013.

Agenda

TODO

Perry’s stages of intellectual development

  1. Dualism. The world is black and white. A is right, and B is wrong. iPhones are phat.
  2. Multiplicity. Rightness is just an opinion each person holds. Others feel differently. Phones are stupid.
  3. Relativism. What is right is often backed by reason, evidence, and personal experiences. My iPhone is more than cool; it’s a product of fine engineering and aesthetic sensitivity.
  4. Commitment. We form our identity using reason, evidence, and experience—tolerating others who have done the same. We recognize our fallibility and adjust when new information comes along. My iPhone is cool, but those Androids have some cool features too.

On shells

Question

What is better? Linear search or binary search?

Code

LineN.java

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class LineN {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new File(args[0]));
    int targetLine = Integer.parseInt(args[1]);

    int i = 0;
    while (in.hasNextLine()) {
      ++i;
      String line = in.nextLine();
      if (i == targetLine) {
        System.out.println(line);
      }
    }
  }
}

linen.php

#!/usr/bin/env php5
<?php
/* print_r($argv); */
$file = $argv[1];
$targetLine = $argv[2];
system("sed -n '$targetLine p' $file");
?>

fixext

#!/usr/bin/env zsh

ext=$1
shift

for file in $*; do
  mv $file ${file:r}.$ext
done

TLDL

Haiku

I have a sickness
I’m real allergic to mice
And it’s terminal