Artificial Intelligence

Spring 2020 -- Peter Brooks

The (ever-changing) Syllabus and readings

Sudoku warmup, due Thurs, 2/27 midnight Sudoku swapped elements.  Intstructions are here. Program tester will be up shortly.
AI topics/news Here's a link to The Batch -- a very good newsletter on current AI topics. A lot of information digested by that organization headed by famed AI researcher Andrew Ng.
Presentations will start in 2 weeks (March 9) Post your topic at least one week in advance of your presentation. Also, first poster on a topic gets it (but there are so many, don't worry).
Sudoku! Here is the format we'll be using.
AI Summer camp The following has come wizzing into my mailbox: announcement of an AI summer camp here in NYC.
Exercise in creating classes, due Sun, 2/16, midnight  Create a program, called MakeFriends, that can be called from the command-line as:
$ python  input-filename  output-filename
which will take commands in the inputfile and write its answers to the output file. 
Here are the details, some of which have changed (2/14, 12:20AM)
Sample of a class Here a Stack (last-in-first-out) class in a notebook.  Download and try it out and understand it.
Here is a much more complicated list -- a singly-linked ordered list -- to show a more involved use of classes with Nodes.
Presentations You (solo) or y'all (duo) will be giving a full-period presentation later in this semester.  Here is a signup sheet.  Next to your name, indicate with "y" or  "n" whether you'll be presenting with a partner, and if so, who.
Homework: reading and writing CSV files by Tues night (2/11)

In a Jupyter notebook, create a function called DoIt(alist=None), that either takes a list as a parameter, or if no list is available, uses sys.argv as the list for incoming arguments (sys.argv will be used when you extract this code from the notebook and run it on the command-line).  The incoming arguments are: 

  1. the name of the program (any name will do, this is ignored)
  2. the name of an input CSV file
  3. the name of an output CSV file

So, when you supply a list to DoIt(), it must contain 3 elements, above.

Create an input text file for testing.  The file should have any number of lines. Each line will have a sequence of string elements separated by commas.  Each line will have one or more positive integers and possibly other elements.  For each input line, write a line out to the output file the number of positive integers and their sum, separated by a comma.  If the input line contains nothing, no output line should be written.

So, if the input file contained:

the output file should contain:

Assuming that your program is called, you should be able to call it with the 2 arguments of input and output filenames from the command line.

Testing your program on the homework server...

1) Upload your program (.py file) to the homework server slot "CSV-test".
2) Go to View Homework and press the Test Program button.
3a) If your program fails with an error message, fix it and resubmit
3b) If your program fails with a message about incorrect output, then read the requirements of the program above VERY CAREFLLY, and see if you can figure out why and fix and resubmit.

Reading files Reading files is simple in Python -- open with f=open(filename,'r') -- provided you can access the directory (requires authentication in Colab), and you can navigate to it.

Here's a notebook describing the file-reading procedures in Colab: File_Reading_2.ipynb. Here's a file called afile.csv.  Download the notebook and the file, and upload them into Colab.  Create a notebook that reads the file and print it out.
Monkeys and Typewriters The real experiment.  With the published result.  And, of course, there's a Wikipedia article.
Monday, Feb. 3: Learn about... Python Classes Yes, you can program classes and instances in Python, except it's a lot less bossy than Java.  Here's my quick intro to Classes.ipynb (download).
First homework, due Mon, 2/3  midnight Here's a notebook talking about an old math problem, and asking you how to solve it in a variety of ways, numerically.  Fill in the notebook with your answers and submit it to the homework server.
Python review notebooks Download these 2 notebooks, and load them either into your own laptop version of Jupyter or upload them to your Google drive, and open them there with Colab.  These are reviews and review exercises. Do them.  You'll need the ideas therein. 


You might was to sneak a look at how these notebooks are written internally (JSON format).  Of course, I don't think they're ever written directly by humans.
Python!  Jupyter Notebooks! We'll be using Python in this class.  Feel free to forget the arcane details of Java, but retain at least some knowledge of classes.

Learn about Jupyter Notebooks using Google's free Colab environment here.  And/or you can use Jupyter notebooks by downloading and installing the huge Anaconda distribution from here.

If you've never been introduced to Python or are pretty rusty, take a look at's suggestions for learning.  If you're willing to read, I recommend Head First Python.  Also CodingBat for quickie exercises.

Learning Python resources:
My Python cribsheet
Python topic explanations from Intro-2
Excellent Python function/method guide (for v. 2.7 but almost everything is still true in 3.x)
Richard Gruet's Python page This is my standard quick-reference for Python.  It's the first place I go to for a quick look at the operators and methods of built-in datatypes.  I often have this up in a different browser tab with programming.   Although it's only really accurate for v. 2.7.x, there is very little difference between this and 3.6.x (and anyway, the 3.6.x+ compiler will warn you if you have sinned).
First task: fill out your Profile on the Homework server.
  1. Go to the main class link page (
  2. Click on the Homework/Grade server link
  3. Choose the Profile menu item
  4. Choose your period and name
  5. Log in with your OSIS number as your password
  6. Fill out your email address and preferred first name only, DO NOT CHANGE YOUR PASSWORD YET.
  7. Save: (Change Profile button)...
  8. (optional, but recommended): now you can change your password for this Homework server, if you want.
  9. REMEMBER this password!
Help from Mr. Brooks Feel free to come and see me during periods 5, 6, or 7 in room 301 (just walk in) or by appointment beforehand just after school also in room 301.
Sending email to Mr. Brooks:
Send mail to:

You MUST include your name in the subject line or body of the message, otherwise I won't know who it's from.
Stuyvesant bell schedule  
Homework/grade server  
Support Wikipedia