
for python 3, you have to download python3.10 or later
http://www.python.org/download/
http://www.upriss.org.uk/python/session1.html

zeromq for python3:
# (Windows or OS X)
pip install --wheel pyzmq
# or
easy_install pyzmq
# or (pretty much anywhere)
pip install pyzmq
# or

Also you have stateasy.ppt

then
python -m pip install pyzmq

Use the editor idle.

idle hello.py
can run it within idle by using import or from the shell:
basics.py (1000 ways to print hello world)
bomb.py (for loops) -- find out which one is buggy
Do this by creating a file bombtest.py in idle starting with num=5
and then keep testing it as you add in more code. Why does it mess up
on Solution 4 (side effect of solution 3).

---- above is first day

name.py
convert.py -- currency
phrase.py (string analysis) -- shows functions too
cat.py
loops.py
wrongLoops.py (sanity check, can you spot the bug)
height.py
	Assignmet: ten questions ten.py
	Assignment old: piglatin
ten.py
	Assignment: Do the game of 10 questions for a number between 1 and 1000.
Is the number equal, greater than, or less than x?
People have to answer something like "equal, less, greater"
Initially, lower bound is 1 and upper bound is 1000.
Each time you get an answer, you either raise the lower bound
or lower the upper bound.
If the respondent is inconsistent, tell them that they are lying.
But be nice about it.

Advanced students: allow the respondent to lie once.
You still get the number.
Give the binary representation of the number.
Is the first bit 1, next bit...
Error correcting code ideas.

--- above is second day

zoo.py -- arrays
simpsons.py -- dictionaries


parsingInput.py -- teaches pretty advanced stuff
filein.py
	Assignment: read in a file and repeat every line twice
	number the output lines
fileinmapy.py -- mapping the lines
fileinmapy2.py -- mapping pairs and list comprehensions

--- above is third day

Efficiency

Show fib.py and fibfastloop.py -- notion of efficiency

Assignment: best change problem
Explain but then students code
coins2.py -- for three denominations

Assignment: 
You are in charge of designing the denominations of coins.
However, we're going to do this for old English pounds which were
worth 240 pence.
You have made a study of the subpound
prices and have determined that each multiple
of 5 cents price is N times
as likely
as a non-multiple of 5 pence.
For example, if N = 4,
then 15 pence is four times as likely to be the price as 43 pence.
But any 5 pence multiple is equally likely as any other 5 pence multiple
and ditto for the non-5 pence multiples.
The N will be given in class and your programs will have 2 minutes
to solve the following problem:
(N will be 1 or greater but may not be an integer.)

Your first job is to design a set of 4 coin denominations such that
the expected number of coins required to give
exact change for a purchase is minimized
given these constraints.
This is called the Exact Change Number.
Using the U.S. denominations, the Exact Change Number for
43 pence can be realized by one quarter, one dime, one nickel,
and three pennies, thus giving a total of 6.

For Abu Dhabi:
Works with python3:

Statistics:
there are python 3 versions
differencebetweenmeans_sig.py
differencebetweenmeans_conf.py 


differencebetweenmeans_conf.py
differencebetweenmeans_sig.py
Diff2MeanSig.py	
Diff2Mean.vals
CorrelationConf.py*  CorrelationSig.py*  Correlation.vals


--- above is fourth day

randomness:

quidditch.py -- good intro to picking from a pool 
knap.py -- this gives you the basic read of the knapsack data

-- below uses numpy so need python2.7 
knapgenetic.py -- my solution; but could get over 600

--- above is fifth day

python3 urlfetch.py
python3 urlfetch2.py
or (I think better)
python3 urlsoup.py
  Assignment is to get the text of the weather forecast

=== UNUSED
A command line argument will deliver search results in response to that
criterion.
simplehtml.py -- opens a url
===

==== Now do some work in python 2 (look for scrape and scrapefinal)


Assignment: Scrape the site
https://data.cityofnewyork.us/Health/DOHMH-New-York-City-Restaurant-Inspection-Results/xx67-kt59

and find all the restaurants in Brooklyn that have critical problems
and map them.

======
This works for python2 and python2.7, but not python3

fusionsearcher.py
fusionsearcher2.py windsurfing

Assignment: A simple web search engine operating system.
Take the fusionsearcher and create a while loop
so that unless the user says he/she is done, the 
fusionsearcher  will search google and find and number each result.
It's a simple operating system because it dispatches based on input.

Maybe ask the user whether he/she liked the result.
Depending on the answer, send out a new query.
fusionsearcher3.py  
User can answer two ways: yes or no.

======

http://cs.nyu.edu/cs/faculty/shasha/papers/flask.zip

Can only be done using python 2.7 (directory is flask.d)

Download and unzip and go through the slides and the README together.
Do the examples as you go.

pip install flask



Assignment: Design a website having any functionality that you choose.
For example, an e-commerce website, a social network website,
a betting (for points, not money) website.
You will present it to class.


---- machine learning
infogain.ppt
dtree.ppt

cd scikit_machinelearn.d
Use python2.7 for this

http://cs.nyu.edu/cs/faculty/shasha/papers/scikitexamp.zip

you can find here sample scikit learn code:
http://scikit-learn.org/stable/auto_examples/mixture/plot_gmm.html

And here the main function:
http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html

---- Essence of interprocess communication:

python3 zmqclient_py3.py
python3 zmqserver_py3.py

NOT THIS:
Then look at push pull architecture also in python2.d folder
zmqmanagerworkerREADME, zmqmanager.py, zmqworker.py
In that, a manager can distribute tasks and then ask for responses.

Now look at auctionzmq.d
which has the client server for auction. Show the determinebid
function.



All you need to do is modify the function determinebid.
The idea is that players are bidding for items of
different types. The first player
who obtains all needed items while staying within budget wins.
In each bidding round, players determine a bid and send it in.
(If two highest bids are the same, then first one received gets it.)
Each player is told who received the item and for how much.
If you win the item in a round, then you pay that amount.
Otherwise, you pay nothing.
Using this information, determine what to do next. There is a comments
in the client code that say: DO SOMETHING HERE

That is what you do.
There are two versions you send: 1 vs. 1 mode.
melee mode (3 or 4 or 5 bidders).


UNUSED:
server_python3.py
auctionbotclient_python3.py
auctionhumanclient_python3.py

python3 server_python3.py
python3 auctionbotclient_python3.py
python3 auctionbotclient_python3.py







Interprocess communication game.
You are given 50 units.
There are four triplets of  items.
They will come up in random order.
You will bid for items.
Whoever wins the bid gets the item
If someone gets a triplet earlier than another item, then that person wins.
So there will be a server (the auctioneer), two or more clients.
Auctioneer receives bids and tells the clients who wins or loses.


For NYU Wash Sq:

Mastermind like game: guess the four numbers in order.
Each number is a single digit.
The numbers can be repeated.
Server returns number in correct position and numbers that are present
but incorrect position.
Do it for 5 positions.
Write this as a client server application. We will have an architecture
team that will display the board and receive the positions
from both clients.

The following code does not work but might be helpful.
mastermindserver.py
mastermindclient.py

--- above is seventh day
--- above is eighth day

For Abu Dhabi: probably not since we are using scikit learn.

dectree.py -- shows how to compute information gain etc.
Assignment:
gendata_fordectree.k 
python dectreeformerstud.py
file MakeATree.orig
target column target


==== END HERE

If you really want to suffer through nodejs,
look at:

nodejs.d/app2b.d
or 
nodejsaccessdatabase.zip

==== 

Possible final assignment: given a query with two arguments. The first argument 
is the keyword you're searching for (could be in quotes).
The second is in one of three categories: location, person, dog.
Your job is to open a web page having that keyword and an appropriate topic.
Or you return the answer -- could not find page with X category.
I will issue 5 queries.
For example:

python categoryassignment.py jemma person -- should return website
about a member of the Redgrave family

python categoryassignment.py jemma dog -- should return "could not find page with dog category and jemma as keyword"

python categoryassignment.py jemma location -- should return website 
about the Bunga river


guessing.py (binary search) -- skip
matrix2.py (matrices and movement) -- skip
gameOfLife.py -- skip


cardClass.py -- how classes look -- skip

arabic.py -- skip

arabic2.py -- language exercise. Assignment is to generalize
this as far as it will go. -- skip


Of course in our test, we will look at something other than 'jemma'

Resources that may be helpful.
Look at eliza.py and the split command.
Then the in command.
my father got angry with me

Look also at some kind of thesaurus
like http://www.visualthesaurus.com/
to get animals that are dogs, professions having to do with humans,
etc.



http://www.boddie.org.uk/python/HTML.html




german.py -- example of dictionary obsolete
simpsons.py -- example of dictionary

Assignment: an engaging Eliza program: see notes of oct 26 and oct 28 2009

discuss local and global variables.
screengame.py: print screen and print out letter; screen changes
a simple game that stops if you hit an obstacle

Assignment: game of your choosing

dectree2.py: computes entropy and conditional entropy
k dectree generates a tree in tmpinput and a result in tmpoutdectree
That works on MakeATree.orig and produces tmpoutdectree which you can show.
gendata.k can generate data for an exercise

Assignment: Determine decision tree to conclude whether sick or not 

Or better: a single person game where someone uses the arrow keys
to avoid obstacles that come from the top.
You are timed.

Sudoku game solver.

Sudokill maybe.


Need some examples of recursion
fib.py
piglatin.py
multidim.py

threader.py


From shasha@access1.cims.nyu.edu  Mon Nov 30 16:15:38 2009
Received: from mx.cims.nyu.edu (mx.cims.nyu.edu [128.122.80.107])
	by mail.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id nAULFcKs007318
	for <shasha@mail.cims.nyu.edu>; Mon, 30 Nov 2009 16:15:38 -0500 (EST)
Received: from access1.cims.nyu.edu (access1.cims.nyu.edu [128.122.49.15])
	by mx.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id nAULFaWO016335
	for <shasha@cs.nyu.edu>; Mon, 30 Nov 2009 16:15:37 -0500 (EST)
Received: from access1.cims.nyu.edu (localhost [127.0.0.1])
	by access1.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id nAULFaKR011965;
	Mon, 30 Nov 2009 16:15:36 -0500 (EST)
Received: (from shasha@localhost)
	by access1.cims.nyu.edu (8.13.8+Sun/8.13.8/Submit) id nAULFa8w011964;
	Mon, 30 Nov 2009 16:15:36 -0500 (EST)
Date: Mon, 30 Nov 2009 16:15:36 -0500 (EST)
From: Dennis Shasha <shasha@courant.nyu.edu>
Message-Id: <200911302115.nAULFa8w011964@access1.cims.nyu.edu>
To: abk235@nyu.edu, ck1247@nyu.edu, dlc333@nyu.edu, jas1026@nyu.edu,
        jh2674@nyu.edu, lad393@nyu.edu, ld969@nyu.edu, lsl278@nyu.edu,
        mjk474@nyu.edu, msm452@nyu.edu, my719@nyu.edu, sh1759@nyu.edu,
        shasha@cs.nyu.edu, tz348@nyu.edu, yas225@nyu.edu
Subject: description of the final assignment
X-Scanned-By: MIMEDefang 2.58 on 128.122.80.107
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (mx.cims.nyu.edu [128.122.80.107]); Mon, 30 Nov 2009 16:15:37 -0500 (EST)
Content-Length: 138


Writing a program to create a decision tree based on
a set of data (called MakeATree) and you're laying out that
tree in outline format.


===== webpy, probably obsolete
Web backends 101:
*To install web.py (assuming unix or mac):*
$ sudo easy_install pip
$ sudo pip install web.py

On Windows machines:
Install easy_install:
http://www.varunpant.com/posts/how-to-setup-easy_install-on-windows
(You might need to restart your computer after messing with the PATH and
PYTHON_HOME variables for it to take effect)
$ sudo easy_install pip
$ sudo pip install web.py

On Windows machines, connect to the webpage w/ 127.0.0.1:8080 not 0.0.0.0:8080


http://cs.nyu.edu/cs/faculty/shasha/papers/webpy1.zip

Download and unzip.

cd ~/webpy1.d
Go through README

From very simple hello world, to taking arguments, to fetching from database.
All uses GET interface.

Assignment: print the input and the reverse of the input.
Also change the greeting to something more clever.

Assignment: find all information about a game having to do
with the Knicks.

http://cs.nyu.edu/cs/faculty/shasha/papers/webpy2.zip
cd ~/webpy2.d
Go through README
Show that you can go through sqlite and do all kinds of cool things.
findbet
team1='Knicks'

Here is the whole flow.
http://cs.nyu.edu/cs/faculty/shasha/papers/webpy.html
is a web page that is just static html. It uses a protocol
called CGI GET to send stuff to the server.
When the user fills in function and argument and clicks submit
(please look at the code of webpy.html) the base href 
http://0.0.0.0:8080 has that function information added to it.

Now looking at server.py in the class index GET function,
 the line
        postquestion = web.input(name=None)
gets that function and arguments and dispatches to the appropriate
python function which in turn accesses the database.

In particular, render.index(findbet('='.join(namefields[1:])))
causes the result of findbet to be put on the index.html page
in the templates directory.
The fact that it's index.html is determined in the urls = statement
towards the top.

If you look at templates/index.html, you can see how information is passed
from the findbet function (or other) to the $name variable.
I'm a little baffled by how to format things better.


