Konstantinovich

Instructor email:  
Office hours: 
Periods 6+7 in room 301. (I get food at the start of 6, so I may be gone for a few minutes)
It helps to let me know you are coming so I am aware when you plan to come because sometimes I have meetings.
CS Dojo: 
A place to hone your skills, and practice with the guidance of caring supportive upperclassmen. 
(Will start soon)  Mon-Thur in 3073:40-4:40pm


Tools and References: 
OSX text editors:   textmate   Brackets

Network Proxy: 
Press the ubuntu start menu circle (top left)
Type: network    and click on the network icon.
click on Network Proxy, switch it to manual then fill in:
HTTP:   149.89.1.30                 3128
HTTPS:   149.89.1.30                3128
(3128 goes in the far right box of each line)

2018-04-20

posted Apr 20, 2018, 5:51 AM by Konstantinovich Samuel   [ updated Apr 20, 2018, 6:48 AM ]

At the dojo website you can find a ton of resources if you want to learn or figure things out:


You will sometimes need to transfer files from home to the school computer:
Demo in class.
  • Run your ftp program (filezilla or any other)
  • Host (choose 1): marge.stuy.edu    homer.stuy.edu     lisa.stuy.edu    bart.stuy.edu
  • Username: the username for your StuyCS account
  • Password: the password for your StuyCS account
  • Port: 22
Classwork:
Fill this out:
 
Work on your website!


Homework: 
1. Post your website by 8am Monday. TRY to post files early so you know that you are able. Do not wait to do this!!

2. Your homepage assignment should be located exactly at this location:
  ~/public_html/01homepage/profile.html
    You may of course have images and other resources in the same directory!

3. The dojo tutorial to post files is here: (Note that you must use a different host name than is specified in the tutorial!)
 Also take a look at their terminal tutorial!




2018-04-19 HW

posted Apr 19, 2018, 6:06 AM by Konstantinovich Samuel   [ updated Apr 19, 2018, 7:18 AM ]


Goal: CSS is your friend
css file:
body {
background-color: black;
color: blanchedalmond;
}
h1{
    color:aquamarine;
}
p {
    font-size: 18px;
color:aqua;
    font-family: cursive;
}
table {
    color: yellow;
    font-family:monospace;
    font-size: 32px;
}

HTML FILE:
<!DOCTYPE html>
<html>
    <head>
        <title>Wow!</title>
<!--
        <link rel="stylesheet" href="style.css">

-->
<!--

        <style>
            body {
                background-color: tan;
            }
            p{
                font-family: sans-serif;
                color: blue;

            }

            h1{
                font-family: sans-serif;
                color: darkgoldenrod;
            }
            table{
              width:50%;
              height: 40px;
            }
            th,td{
              padding: 15px;
            }
            table,th,td{

                font-size: 140%;
                font-family: monospace;
                border: 2px solid black;
                border-collapse: collapse;
                padding: 15px
                background-color: antiquewhite;
                color: saddlebrown;
            }
            th{
                color: chocolate;
            }
        </style>
-->

    </head>
    <body>

      <h1>This is B - Not a visa....(h1)</h1>
      <h2>This is H2 - Not a paragraph....</h2>

        <center>This is not in a paragraph. has a center tag</center>
        <p>Lorem ipsum dolor sit amet, quis nostrud exerci tation
           ullamcorper suscipit lobortis nisl ut aliquip ex ea
           commodo consequat. Duis autem vel eum iriure dolor in
           hendrerit in vulputate velit esse feugait nulla facilisi
           molestie consequat, vel illum dolore eu feugiat nulla
           facilisis at vero eros et accumsan et iusto odio dignissim
           qui blandit praesent luptatum zzril delenit augue duis
           dolore te.
        </p>
        <p>Bacon ipsum dolor amet tail shankle hamburger,
        pork loin kielbasa leberkas sirloin flank doner pork
        corned beef ham hock cow filet mignon pancetta. Salami
        picanha alcatra pork. Short loin chuck turkey kevin pancetta.
        </p>

        Also not a paragraph... default stuff here.<br>
        More non-pargraph.<br>
        So silly... more again!
        <hr>
        <table>
        <tr>
            <th>Reel</td>
            <th>Big</td>
            <th>Fish</td>
        </tr>
        <tr>
            <td>Go</td>
            <td>
                <img width="100" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
            </td>
            <td>Yoself</td>
        </tr>
        <tr>
            <td>Red</td>
            <td>Foo , Sky</td>
            <td>Blue</td>
        </tr>
        </table>
        <h1>WHOA! HTML</h1>
        <h3>smaller header</h3>

        <p>Frankfurter pastrami ball tip, landjaeger bresaola ground
        round burgdoggen. Shankle pig shoulder ground round strip steak
        hamburger spare ribs brisket tri-tip boudin ribeye bresaola kielbasa
        frankfurter ham.</p>
    </body>
</html>




Homework (due Monday)

1. make a folder in your home directory:  public_html 
This folder can be viewed by going to a web server:   homer.stuy.edu/~YOUR_USERNAME
e.g.
homer.stuy.edu/~jmatsui01/
homer.stuy.edu/~konstans/   <- here is mine

2. Make an "about me" webpage and post in the location discussed in class.    ~/public_html/01homepage/
-Include basic "public friendly" information about you and things you like. No sensitive information. *discussion point*
-Use CSS to style the page and show off your creativity and technical skills.

Technical Requirements:
-There should be 3-4 paragraphs about you, and at least 2 different lists of things. Writing the content should be super easy, just write about stuff you like and things you find interesting. 
-Format the information using the HTML tags you have learned in a sensible way.
-Format the HTML in a reasonable way. (Tabs newlines etc)
-You may Include images
-Do NOT include sounds
-Please make it a single page, not several linked together!
-Most of the style should be in the style tag, or in an external css file, NOT in individual tags.
-Demonstrate you understand how to research and apply a variety of styles to your website

Aesthetic requirements:
-Pick a color theme that makes sense, not random colors. 
    https://coolors.co/ can help you pick some colors, and then use: http://colorsafe.co to see if it has enough contrast.
-Size your images to make sense in a browser window.

Optionally: You can ask to be judged and I will have the class vote on the best web pages! 
-More details to follow.

2018-04-18 HW

posted Apr 18, 2018, 5:59 AM by Konstantinovich Samuel   [ updated Apr 18, 2018, 7:31 AM ]

Homework:
Complete the simple css tutorials here: 
We will discuss CSS tomorrow.

DO Now:
Open your HTML side by side (text editor / web browser) If you don't have it then just start the rest of the work. DO NOT work on the website now!

Classwork: You are collaborating on a fake quiz! You may use each other, but you may NOT RUN the code

DIRECTIONS:
1. Work with 3-4 of your neighbors. 
2. Do not run the code! Do not run the code!
3. Agree with each of your group for each problem you do. EVERYONE write it down. (include the expression AND answer)
4. Complete one section at a time and compare that ENTIRE section with 2 neighboring groups.
5. Move on to the next section only after 2 other groups agree with you.
--Any group that has an individual that deviates from these directions will not receive credit.-- The entire group will fall if one member falls!
 


By the end of this everyone should have the same answers, and should be convinced that they are correct. 


EVALUATE EACH OF THESE Sections using the definitions:
#starting list and strings
s = "two fish?"
L = ["two","fish?"]
L2 = ["one","fish","two","fishs?"]

#(The actual problems predict the output)
#print "---Section I LEN:---"
print len(s)
print len(L)
print len(L2)

#print "---Section II Indexing:---"
print s[1]
print L[1]
print L2[1]

#print "---Section III Slices:---"
print L2[1:3]
print L2[2:3]
print L2[:2]
print L2[::2]
print L2[1::2]

#print "---Section IV splitting :---"
print "this is a test".split()
print "this is a test".split("s ")

#print "---Section V range:---"
print range(5)
print range(2,5)
print range(2,10,2)

#print "---Section VI in:---"
print "a" in "fish"
print "i" in "fish"
print 5 in [1,2,3]
print 5 in [3,4,5]


#NEW STUFF: Join  
#A string method that takes a list of strings and uses the string to 
#glue the list together (As if it were replacing each of the commas)

#String.join(ListOfStrings) -> a new string
#e.g.
#"x".join(["a","2","b","c"]) results in "ax2xbxc"
#"a b".join(["a","b","c"]) results in "aa bba bc"
#"".join(["a","b","c"]) results in "abc"

#print "---Section VI Join:---"
print "wh".join(["o"," are"," you"])
print "an".join(["b","n","a"])

#VII split and join
print "---SPLIT+JOIN:---"
print "!".join("the only way to go?".split())
print "".join("bannana".split("an"))


2018-04-17 HW

posted Apr 17, 2018, 6:05 AM by Konstantinovich Samuel

Goal: Lists and Tables

Discussion tables + lists.



Easy Website Lab: (complete at home!)
Open a plain text editor (gedit)  note: You can use gedit on your own computers too! It is a small free download. 
Create an empty file and save it with the file name: webpage.html 
Open it in a web browser, so that you can see it in both HTML and Webpage view.
(You should have gedit + web browser side by side)
Now you can edit the file and view the contents in a web browser by reloading the page (F5 reloads)

correction from yesterday: You CAN open a file with a web browser the SAME way as with gedit.
$ gedit filename &                      \
            <note the & is used to prevent gedit from occupying your terminal

$ chromium-browser filename    
            < note that you do not need the & after a web browser



Create a webpage that looks like this one:
-Structure the page first, add the image last.
-A similar image is sufficient, but relative size is important.  (Google for a similar image)
-You may need to look up how to do certain things: 
    -center content 

2018-04-16 HW

posted Apr 15, 2018, 7:11 PM by Konstantinovich Samuel   [ updated Apr 16, 2018, 10:04 AM ]

1.  OS / TERMINAL STUFF + FILE HIERARCHY:

Homework:
Part 1: 
Draw a tree of your file hierarchy. Start with the drive that contains your OS install. 
Windows: Start in c:\
Mac/Linux: Start in /  (the root directory)
Part 2: Read through this:


Paths and Terminal viewing of files
You need to know where you save stuff. Using a search to do so will not help you when you have multiple downloaded copies, and multiple saved copies of a file. 

pwd
ls
cat
cd
Directory Tree :




2. HTML STUFF:

A. What tags are required just to make a basic page without any content?
!DOCTYPE html
html
head
body

This is how an empty webpage would look:

<!DOCTYPE html>
<html>
    <head>
        <!-- head definitions go here -->
    </head>
    <body>
        <!-- the content goes here -->
    </body>
</html>


Comment tags tell the browser not to read the text between:
 the : <!-- 
and the-->

e.g.
<!-- ANY TEXT HERE IS IGNORED -->


What tags need to go in the head?
 Title

B. What goes in the body?
The basic elements of an HTML page are placed here:

B1. A text header is any of the following:
<h1>, <h2>, <h3>, <h4>, <h5>, or <h6>

B2. A paragraph:
 <p> 
B3. A horizontal ruler
 <hr> 
B4. A link (anchor tag)  (DISCUSSED LATER)
<a> 

B5. Lists: (DISCUSSED LATER)
 <ul> (unordered list)
 <ol> (ordered list)
 both of which use : <li> (list element) 

B6. An image:  (DISCUSSED LATER)
<img>

B7. Tags that do not do anything by themselves:
A divider
<div> 
A text span
<span>

They are mostly used for styling by using an id or class. We don't care about them for the simple things we are doing in this class. 

3. Links:

Important: You need the https:// in each link!

3A. The link is an <a> tag, with an href property. You will see many tags have a few properties inside of the <> symbols.

<a href="https://www.google.com">A link to Google</a>


3B. Internal Links:

To create a link to a different section in the same page, you will need to use a hash sign along with the element ID to where you would like the browser to jump to. For example:

<a href="#section1">Go to Section 1Questions</a>

LOTS OF TEXT IN BETWEEN.

<h3 id="section1">This is a new section!</h3>
<p>Section 1 text here...</p>



4. Images in HTML are inline elements. Inline means it can be put on the same text lines and paragraphs as other elements. (Headers are not inline, as they cause new lines to be rendered on the html) 

The <img> tag has several attributes to determine which image to render and make it display the way you want.

Which image:
The src attribute is the location of the file.
This can be a local path:
<img src="/static/img/cat.jpg">
or a remote file:
<img src="http://www.mysite.com/img/cat.jpg">

Resizing 
Use the width and height attributes of an image
<img src="/static/img/code.jpg" width="100">
alternatively by using CSS to resize:
<img src="/static/img/cat.jpg" style="width: 100px">

Other information for when the image fails to load:
Having an "alt" attribute set will add a tooltip description that will be displayed when hovering on top of an image OR when the image does not load
<img src="/static/img/cat.jpg" alt="A picture of some code">
This can be combined with the size too!
<img src="/static/img/cats.jpg" width="100" alt="A picture of some cats">

2018-04-13 HTML HW

posted Apr 13, 2018, 6:25 AM by Konstantinovich Samuel

General Info:
HTML is Hyper Text Markup Language
It is more or less a glorified document styling language, not a programming language. 

You use HTML to organize, arrange, and style your document, including all the things you would expect in a document editor:  
text: color/size/font , 
images, 
tables, 
and of course links.

HTML is made using tags. 

Tags can wrap around things:
<tagname> things </tagname>

or be stand alone:
<otherTagName>

This:
Oh?
<b>This is bolded</b>
<br>
<i>This is italicized</i>

Would produce this output:
Oh? This is bolded
This is italicized


You need to know this much HTML. Each section (Basic elements onward) contains many tags. You need to know how they all work. It is not sufficient to just go through them once. You should focus on everything up to Links for now. 
Classwork / Homework: 
Go through the tutorials up to and including links. Go find other tutorials that help you learn this in a style you are comfortable with.
You will be asked to duplicate the appearance of a website using the tags that you are supposed to know. Keep in mind that is the goal of this unit: To be able to use HTML to get the appearance required. 
Deliverable: Make a webpage with simple content, but format it in a variety of ways to show you know that different tags exist, and how to use them.
Just write a few paragraphs about you. We will expand on this in a more formal "about me" page assignment. 

The reference that I like is W3Schools.hthttps://www.w3schools.com/html/

 They have a nicely organized reference and some tutorials. The nice thing about HTML is that there isn't much to understand. It is more about familiarizing yourself with the tags and knowing which tags exist so that you can use them. You may like other tutorials, but this is perfect if you need to look up something.

2018-04-10 Sentences! HW

posted Apr 10, 2018, 6:25 AM by Konstantinovich Samuel   [ updated Apr 11, 2018, 8:00 AM ]

QUIZ THURSDAY (recursion 2nd attempt!)

HW DUE FRIDAY:
-In class, you will run it a few times to show me your awesome sentences. 
-You will have to show me which parts you completed
-For full credit, you need to complete section III
-You must have 2 sets of words (regular + one themed set) This demonstrates you didn't use global variables. 
So you will call it 2 different ways:
improvedSentence(nouns,        properNouns,        verbs, 
                 transitiveVerbs,       adjectives,       adverbs)
improvedSentence(nounsThemed , properNounsThemed , verbsThemed
                 transitiveVerbsThemed, adjectivesThemed, adverbsThemed)

Your Theme can be any number of things:
SciFi
Horror
Harry Potter
MyLittlePony
School
etc.

Your proper nouns can be even more categories if you like...
AvengerNames
PonyNames
StrangeNames
etc.


SECTION 0 (PRE LAB)
Think:
What are the basic parts of a sentence? 
What is the simplest sentence you can make?


We would ideally start with a simple sentence like:
noun verb
kitty plays
toast runs
tea steams

BETTER: add 'the' to the sentence: 
the toast runs

1. Add random words lists. They should be in the format:
nouns =  ['kitty', 'toast', 'tea']
verbs =  ['runs', 'plays', 'steams'] 

2. Write a function to get a random element from a list
def getOne( words ):
   ???

YOU SHOULD HAVE getOne before continuing  
Hint: you need to use random numbers to do this
import random
then:
random.randint(ab)

Return a random integer N such that a <= N <= b


3. If you do that then it is trivial to make a simple sentence that chooses a verb and a noun and adds them with spaces!

"the " +getOne(nouns) + " " + getOne(verbs) 


Here is the simple sentence() function:

sentence(nouns,verbs) returns  'the kitty runs'

sentence(nouns,verbs) returns 'the kitty plays'
sentence(nouns,verbs) returns 'the toast steams'

Every time you run it you should get randomized results depending on your list of words.


If you finished up to this point, you can try to make better sentences by replacing getOne(nouns) and getOne(verbs) with new functions. 
We can replace a noun with a noun phrase, and replace a verb with a verb phrase. You can experiment on your own to do so. Try using adjectives and adverbs.

YOUR JOB IS TO MAKE IT BETTER: After your basic generator works, you should implement as many of these as you can. We can show off the best sentences at the end of class or on Monday. 
Your generator should not always give the same type of sentence:
Sometimes noun verb
Sometimes adjective noun verb
Somtimes adjective adjective noun verb
etc. 

All of these can be distilled down to two parts: a noun phrase and a verb phrase
the dog walks
Jack Sparrow clumsily stumbles
the slow pedestrian obliviously drives
(In the next two notice a verb phrase can include a noun phrase inside of it! see part 6 on transitive verbs)
the cat eats the mouse 
the tiny dancer holds Tony Danza


SECTION I (BASICS)
Start with this:
def sentenceImproved(nouns,adjectives,verbs,adverbs):
  return makeNounPhrase(nouns,adjectives) + " "+makeVerbPhrase(verbs,adverbs) 

Remember:
You can pass in other parameters to each function if you need to. (properNoun, transitiveVerb, etc)
makeVerbPhrase might need nouns and adjectives too when you have transitive verbs.
You can create more categories of words.

-You can ignore capitalization.
-You need the random function in more than just your getOne() function.
-You should have the most awesome sentence generator in class on Friday. 


HOW TO MAKE DIFFERENT STYLE RESULTS RANDOMLY
1. We can choose between different options randomly by using  a series of random in the cond statement as  follows:
x = random.randint(0,2)
if x == 0:
  return   THING1
if x == 1:
  return   THING2  
if x == 2:
  return   THING3  
...any number of options just change your random number range



Section II. Make better nouns
def makeNounPhrase(nouns,adjectives):
  ???


HOW TO MODIFY NOUNS
2. AdjectiveBlock: (0 or more adjectives to use in your noun Phrases)
Notice you can have any number of adjectives connected! 
Since you can have 0 or more you can always include an ajective block on normal nouns in your noun phrase.
You can define a function AdjectiveBlock that uses either a loop or recursion to return a random number of adjectives. 
e.g.
AdjectiveBlock(adjectives) -> "slow tall"
AdjectiveBlock(adjectives) -> "fast silly furry"
AdjectiveBlock(adjectives) -> "fishy"
AdjectiveBlock(adjectives) -> ""

Proper Nouns
3. Proper nouns can be one option in your noun phrase list: 
-Do not place a 'the' in front of these! 
-Do not place adjectives here either!
(You would need a separate list of proper nouns, and a function that gets one for you)
Loki defies the world wrestling federation.
Dave walks.
Thor smashes
Tony Stark quickly shoots
The Hulk gleefully plays (notice 'the hulk' is a proper noun, the 'the' is attached to the name...)
 

Section III. Make better verbs
def makeVerbPhrase(verbs,adverbs):
  ???

remember: makeVerbPhrase might need nouns and adjectives too when you have transitive verbs so you can modify it :
def makeVerbPhrase(verbs,adverbs,nouns,adjectives):
  ???


4. AdverbVerbBlock(verbs,adverbs) :   (0 or more adverbs + verb, just like adjectives!) 
it could return:
"quickly runs"
"sleeps"
"slowly silently creeps"
"silently efficiently screams"
"jumps slowly"


5. Some verbs require another noun to tell what is recieving an action. These are called transitive verbs. 

"Joe runs"  is just noun verb

"Joe takes the ball" is noun verb noun2
This is because "take" is a transitive verb, it requires a target.

Make a 2nd list of transitiveVerbs that requires a 2nd noun/nounphrase. You can randomly select:
-Choose an intransitive verb like we just did before (the normal verb list)
-Choose a transitive verb then choose a noun phrase:
Thor pokes Loki  ;transitive verb + proper noun
The dog bites the little chair. ;transitive verb + noun phrase


Section IV. Make it awesome!

You need to be able to write a basic sentence generator first, after that works you can make it more elaborate/poetic/creative:
Noun1 <negate> verb1 Noun2, noun2 verb noun2.
Like:
Guns don't kill people, people kill people. 
or:
Toasters don't toast toast, toast toast toast.

You can add other kinds of phrases, negations, and any language features that you would like to.
You can also try including "and" "or" "but" etc. This would make your sentenceImproved need a few more options...

def sentenceImproved(nouns,adjectives,verbs,adverbs):
  if ???
       return makeNounPhrase(nouns,adjectives) + " "+makeVerbPhrase(verbs,adverbs) #basic structure
  if ???
       #return a different kind of sentence
  etc...

nouns = ['advice', 'airplane', 'alcohol', 'alien', 'aluminum', 'ambigram', 'ambulance', 'ant', 'apple', 'aquarium', 'astrophysicist', 'athlete', 'avocado', 'ball', 'banana', 'barnacle', 'baseball', 'battleship', 'bear', 'bed', 'binder', 'bird', 'blueberry', 'bluejay', 'books', 'bookshelf', 'bowl', 'brouhaha', 'building', 'burger', 'bus', 'butterbeer', 'cadet', 'calendar', 'calculator', 'calculus', 'calculus', 'camera', 'candle', 'candy', 'canine', 'car', 'carnival', 'carpet', 'carrot', 'cat', 'cat', 'cheek', 'cheetah', 'chemistry', 'chicken', 'chocolate', 'chopsticks', 'chrome', 'clout', 'clown', 'comma', 'computer', 'concrete', 'congressman', 'conniption', 'consanguinity', 'conundrum', 'cornucopia', 'couch', 'cow', 'cracker', 'crown', 'cryptocurrency', 'customer', 'death', 'defibrillator', 'deodorant', 'dilemma', 'dinosaur', 'discord', 'disease', 'dog', 'dolphin', 'doorknob', 'dragon', 'duck', 'dust', 'bunny', 'dynasty', 'ease', 'eigenvector', 'elderberries', 'elephant', 'elevator', 'engineer', 'ennui', 'epidemiologist', 'exhibition', 'eyeball', 'fairy', 'fern', 'flower', 'flower', 'flute', 'food', 'foot', 'fox', 'fuddy-duddy', 'gazebo', 'gazelle', 'geodesic', 'giant', 'giraffe', 'girth', 'grades', 'grandma', 'half-and-half', 'hallway', 'headache', 'headsets', 'health', 'heirloom', 'helicopter', 'home', 'hunger', 'iamb', 'ice', 'island', 'isopropyl-alcohol', 'jelly', 'kerfuffle', 'king', 'lab', 'ladder', 'letter', 'macrology', 'loophole', 'lotion', 'love', 'machine', 'magician', 'mars', 'mirage', 'mirror', 'mouse', 'muffin', 'muggle', 'mullet', 'normie', 'nose', 'notebook', 'novel', 'oreos', 'organ', 'ostrich', 'palace', 'panda', 'paper', 'park', 'pear', 'pedigree', 'pencil', 'penguin', 'peregrine', 'falcon', 'person', 'person', 'pillow', 'pillow', 'pineapple', 'pirate', 'plant', 'podcast', 'poetry', 'poster', 'potato', 'projector', 'puppy', 'quail', 'question', 'rack', 'rice', 'river', 'rock', 'sacrifice', 'saddle', 'saiyan', 'sculpture', 'sharpener', 'shibboleth', 'sloth', 'snail', 'spaghetti', 'student', 'subway', 'summit', 'sun', 'sushi', 'table', 'tardis', 'thunder', 'tiger', 'time', 'toddler', 'tomato', 'tongue', 'train', 'treaty', 'tree', 'turtle', 'vapor', 'violet', 'vision', 'wolverine', 'word', 'xebec', 'zither', 'zombie'] 

#YOU NEED TO BREAK UP THE LIST OF VERBS - some are transitive, some require prepositions afterwards, and some are normal. 
verbs = ['accumulates', 'adheres', 'affirms', 'aggregates', 'aids', 'amalgamates', 'assumes', 'attacks', 'bakes', 'baking', 'beckons', 'beholds', 'bellows', 'bolsters', 'breathes', 'breathes', 'browses', 'bulldozes', 'calls', 'calls', 'carries', 'catapults', 'catches', 'cheats', 'chops', 'chucks', 'cleans', 'clips', 'codes', 'constructs', 'creates', 'cries', 'cries', 'crush', 'crying', 'crystallizes', 'cuts', 'dabs', 'dance', 'dances', 'dances', 'dances', 'dashes', 'deceives', 'degusts', 'demands', 'deplores', 'destroys', 'deters', 'dies', 'dies', 'dodges', 'does', 'dozes', 'drink', 'drinks', 'drops', 'eat', 'eating', 'eats', 'eats', 'embark', 'enters', 'escapes', 'executes', 'exemplifies', 'falls', 'falls', 'fears', 'feeds', 'finishes', 'flails', 'flicks', 'flies', 'flies', 'floats', 'flushes', 'flying', 'flys', 'folds', 'follows', 'fosters', 'frolics', 'gallops', 'gathers', 'gives', 'goes', 'golfs', 'hacks', 'hates', 'hits', 'hits', 'holds', 'illuminates', 'inhales', 'interferes', 'invents', 'irritates', 'jettisons', 'jogs', 'jumps', 'kneels', 'kraal', 'leaps', 'licks', 'listens', 'lists', 'lives', 'lounging', 'mars', 'materializes', 'meanders', 'mines', 'mitigates', 'motivates', 'mourns', 'moves', 'naps', 'obtains', 'passes', 'perambulates', 'peruses', 'placates', 'plays', 'plays', 'plunges', 'ponders', 'pours', 'promises', 'pulls', 'push', 'racewalks', 'radiates', 'raids', 'reading', 'reclines', 'recycles', 'reduces', 'reuses', 'rotates', 'ruminates', 'runs', 'runs', 'rustles', 'saunters', 'scares', 'scaring', 'screams', 'screams', 'searches', 'shouts', 'sings', 'sinking', 'skedaddles', 'skips', 'slaps', 'slaps', 'sleep', 'sleeps', 'sleeps', 'slumbers', 'slurps', 'smells', 'smile', 'smiling', 'smirks', 'snorkels', 'soaks', 'speaks', 'splats', 'sprints', 'squanders', 'submits', 'survives', 'swim', 'swims', 'swims', 'tantalizes', 'taste', 'tenses', 'thinks', 'thinks', 'throws', 'throws', 'tries', 'tries', 'trudges', 'tumbles', 'types', 'vomits', 'votes', 'waddles', 'walks', 'want', 'whispers', 'win', 'works', 'writes', 'yeets', 'zip-lines'] 

adjectives = ['abominable', 'admirable', 'aggressive', 'alarming', 'amazing', 'ambiguous', 'angry', 'annoying', 'annoying', 'antibiotic', 'antidisestablishmentarian', 'arrogant', 'authentic', 'bald', 'barbarous', 'bawdy', 'beautiful', 'beautiful', 'bereft', 'bereft', 'big', 'big', 'bilious', 'bludgeoned', 'blue', 'boring', 'brackish', 'brash', 'brave', 'bright', 'broken', 'brown', 'calamitous', 'calm', 'chaotic', 'charismatic', 'cheerful', 'chunky', 'cloudy', 'colorful', 'comely', 'confused', 'confuzzle', 'cool', 'cordial', 'coriacious', 'corrosive', 'coy', 'crazy', 'creepy', 'crimson', 'crispy', 'cruel', 'cumbersome', 'dangerous', 'dank', 'dead', 'dead', 'deafening', 'delicious', 'delightful', 'deplorable', 'depressed', 'difficult', 'diffident', 'dim', 'diminutive', 'diplomatic', 'discombobulated', 'disgusting', 'distorted', 'dizzy', 'draconian', 'dreamy', 'drumpf', 'dumb', 'dummy', 'eager', 'ecstatic', 'egregious', 'evanescent', 'excited', 'exhilarating', 'exquisite', 'extra', 'extravagant', 'exuberant', 'exuberant', 'fast', 'fast', 'fire-breathing', 'firm', 'first', 'flaccid', 'flimsy', 'flippant', 'fluffy', 'fluffy', 'forlorn', 'fragile', 'free', 'fresh', 'frustrating', 'funny', 'gargantuan', 'giant', 'glib', 'gothic', 'grandiose', 'green', 'happy', 'hard', 'hedonistic', 'heroic', 'hostile', 'hot', 'huge', 'huge', 'impromptu', 'inexpensive', 'innocent', 'insensitive', 'interesting', 'interesting', 'invincible', 'jarring', 'jolly', 'kafkaesque', 'languid', 'late', 'lazy', 'long', 'loquacious', 'lucky', 'ludicrous', 'mammoth', 'maniacal', 'melodic', 'moist', 'mouthwatering', 'muscular', 'mystic', 'neutral', 'nice', 'non-offensive', 'normal', 'obsequious', 'obtuse', 'odd', 'Orwellian', 'pale', 'partitioned', 'petulant', 'possessive', 'practical', 'proactive', 'quadripartite', 'quick', 'random', 'rare', 'red', 'red', 'regretful', 'repulsive', 'resonant', 'reverent', 'romanized', 'rotten', 'rubiginous', 'rustic', 'sad', 'salty', 'satanic', 'scruffy', 'scrumptious', 'scrumptious', 'serendipitous', 'shiny', 'short', 'silent', 'sketchy', 'slow', 'slow', 'small', 'smart', 'soft', 'sore', 'sparkling', 'sparkly', 'spicy', 'squishy', 'stinky', 'strenuous', 'strong', 'stupendous', 'stupendous', 'successful', 'supercalifragilisticexpialidocious', 'surreal', 'surrounded', 'swanky', 'sweaty', 'swift', 'taboo', 'tacky', 'tall', 'tasty', 'tenacious', 'tiny', 'tired', 'unladen', 'upset', 'useful', 'vast', 'venomous', 'voracious', 'wet', 'wild', 'wonderful', 'zany', 'zealous', 'zoophagous'] 

adverbs = ['inadvertently', 'abnormally', 'above', 'abruptly', 'absentmindedly', 'across', 'afterwards', 'always', 'amazingly', 'angrily', 'anxiously', 'bashfully', 'beautifully', 'because', 'below', 'boldly', 'brilliant', 'brutally', 'cagily', 'calmly', 'carefully', 'cautiously', 'childishly', 'cleverly', 'coaxingly', 'continuously', 'cooly', 'courageously', 'cowardly', 'crazily', 'deadly', 'deliberately', 'desperately', 'diminishingly', 'dramatically', 'dreadfully', 'early', 'elegantly', 'endlessly', 'endlessly', 'enjoyably', 'enthusiastically', 'erroneously', 'esoterically', 'especially', 'eternally', 'everywhere', 'excruciatingly', 'expeditiously', 'flagrantly', 'frankly', 'frantically', 'frenetically', 'funnily', 'gently', 'genuinely', 'gingerly', 'grotesquely', 'haphazardly', 'happily', 'hastily', 'helplessly', 'hilariously', 'honestly', 'hurriedly', 'idyllically', 'immaculately', 'impatiently', 'impressively', 'incompetently', 'indubitably', 'inquisitively', 'instantly', 'interestingly', 'jauntily', 'jubilantly', 'justly', 'keenly', 'kindly', 'kindly', 'lasciviously', 'lastly', 'lazily', 'lazily', 'lifelessly', 'lightly', 'loftily', 'loudly', 'lovely', 'luckily', 'majestically', 'meaningfully', 'mysteriously', 'nervously', 'nervously', 'occasionally', 'onwards', 'optimistically', 'optimistically', 'painfully', 'pathetically', 'powerfully', 'precariously', 'presently', 'properly', 'quaintly', 'queasily', 'quickly', 'quickly', 'quickly', 'quickly', 'quickly', 'quickly', 'quickly', 'quietly', 'randomly', 'rapidly', 'really', 'recklessly', 'regretfully', 'regularly', 'rhapsodically', 'roughly', 'sadly', 'salaciously', 'scarcely', 'secretively', 'sedately', 'selfishly', 'serendipitously', 'sheepishly', 'shortly', 'shrewdly', 'silently', 'silently', 'sloppily', 'slowly', 'slowly', 'slowly', 'slowly', 'slowly', 'slowly', 'sluggishly', 'slyly', 'smoothly', 'solemnly', 'sorrowfully', 'speedily', 'steadily', 'stealthily', 'strongly', 'studiously', 'stupidly', 'suddenly', 'surprisingly', 'sweetly', 'swiftly', 'swimmingly', 'terribly', 'terribly', 'there', 'thoroughly', 'tiredly', 'tomorrow', 'tremulously', 'trickily', 'triumphantly', 'truthfully', 'unbearably', 'underground', 'unenthusiastically', 'unfortunately', 'unpredictably', 'unquestionably', 'violently', 'wearily', 'wickedly', 'wildly', 'zealously']

2018-04-09

posted Apr 8, 2018, 6:27 AM by Konstantinovich Samuel   [ updated Apr 9, 2018, 6:34 AM ]

Recursion

For each problem below:
a. Write the base case.
   e.g. When n is 0 the result is 0.
b. Write out the recursive relationship. (hint: start with numbers and then do it in terms of n)
    e.g.   fib(n)  is   fib(n-1) + fib(n-2)
c. Write the function in idle. Test it (start with base cases and work your way up)

1. Triangle numbers:
We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. 
This is a size 5 triangle:
*
**
***
****
*****
Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows. 

triangle(0) → 0 
Because there are no rows. 

triangle(1) → 1 
Because it is just:
*

triangle(2) → 3
Because it is just:
*
**

2. Consider a function powerN(base,n) where you are given base and n that are both positive integers. 
You must compute recursively (no loops) the value of base to the n power, so powerN(5, 2) is 25 (5 squared). 

powerN(3, 1) → 3 
powerN(3, 2) → 9 
powerN(3, 3) → 27

3. Given a string, compute recursively (no loops) a new string where all the lowercase 'x' chars have been changed to 'y' chars. 
hint: Think of string concatenation to be just like addition, you can say   return "y" + function( value)  
changeXY("codex") → "codey" 
changeXY("xxhixx") → "yyhiyy" 
changeXY("xhixhix") → "yhiyhiy"

4. Given a non-empty list of integers, compute recursively the number of times that the value 11 appears in the list. 
We'll use the convention of considering only the part of the array that begins at the given index. 
In this way, a recursive call can pass index+1 to move down the array. 
The initial call will pass in index as 0. 

Do not modify the list! 

Hint: the base case has 2 options!

array11([4], 0) → 0  
array11([11], 0) → 1
array11([1, 2, 11], 0) → 1 
array11([11, 11, 3], 0) → 2 
array11([11, 11, 3], 1) → 1  #because you are looking starting at index 1!
array11([1, 2, 3, 4], 0) → 0

To see how this can be used, remember that the 2nd parameter is the place you are looking at now so:
array11([11, 2, 11, 11, 11], 0) → 4  #start by looking at the 0th index.
array11([11, 2, 11, 11, 11], 1) → 3  #start by looking at the 1st index. (This would be used in the previous call)
array11([11, 2, 11, 11, 11], 2) → 3
array11([11, 2, 11, 11, 11], 3) → 2
array11([11, 2, 11, 11, 11], 4) → 1



2018-03-29 HW

posted Mar 29, 2018, 6:16 AM by Konstantinovich Samuel   [ updated Apr 8, 2018, 6:04 AM ]

HW1 server slot: Hanoi
Submit hanoi sometime today. (It should have been done already)
Your program should not print anything when run, I will run my own tests.

Make sure the following command would work:
hanoi(2,"A","B","C")

Make sure the output is EXACTLY:
move from A to B
move from A to C
move from B to C

HW2:
fill out the google doc: (fill out your period correctly to get credit)

Extra:
Trees:
I will have an extra credit slot for the tree!



Classwork Complete at home:

Since a list can be modified, it is sometimes useful to write functions that change the contents of a list. 
***Sadly these kinds of functions cannot be tested on codingbat, so you need to thoroughly test your code to be sure that it works. 

1. Write a function that takes a list of strings and MODIFIES IT by swapping the first and last words.
w = ["a", "b", "c", "j", "k"]
swapStuff(w)
print w # shows:  ["k", "b", "c","j","a"]

2. Write a function that takes a list of integers and MODIFIES IT by deleting all negative values
s = [-9,1,-2,3,-4,-3,5,6,-7,-12,8]
removeNegs( s )
print s  #shows [1,3,5,6,8] 

y = [-21,-2,13,3,-14,12,5,6,-7,8]
removeNegs( y )
print y  #shows [13,3,12,5,6,8]

The function does not return a value. 

3. Write a function that takes a list of integers and MODIFIES IT by moving all negative values to the end of the list (in the same order)
s = [1,-2,3,-4,5,6,-7,8]
moveNegsToEnd( s )
print s  #shows [1,3,5,6,8,-2,-4,-7] 

y = [-21,-2,13,3,-14,12,5,6,-7,8]
moveNegsToEnd( y )
print y  #shows [13,3,12,5,6,8,-21,-2,-14,-7]

The function does not return a value. 


2018-03-27 Hanoi2 (2 days)

posted Mar 27, 2018, 6:06 AM by Konstantinovich Samuel   [ updated Mar 28, 2018, 5:46 AM ]

Tree Lab: Will check in class on the 28th
Open your tree lab to demo as I walk around. Show me that your sliders work for your tree-3 when I come by.

Goal: Towers of Hanoi 2: To understand recursion you must first... understand recursion.

define a function: 
def hanoi(n, start, temp, end):
   ???

Parameters:
n : the number of disks.
start temp and end : strings with the names of the towers.
Output:
The function must print the set of moves as seen in the examples below


hanoi(2, "A","B","C")
Output:
move from A to B
move from A to C
move from B to C

hanoi(3, "X","temp","Y")
Output:
move from X to Y
move from X to temp
move from Y to temp
move from X to Y
move from temp to X
move from temp to Y
move from X to Y

Think of this recursively, and remember that a base case that is "do nothing" just means you can write something like this with no else:

if you_have_more_to_do : 
   do recursion step(s)
   do recursion step(s)




The number of moves to solve a towers of hanoi with n disks is easily calculated.
Explicit definition:
tn = 2n - 1 
Recursive definition:
tn = 2 * t(n-1) + 1  [twice the previous result plus one]

Since this number is huge, computers cannot realistically compute results for any large values of n.


Remember Moore's Law:

Moore's law refers to an observation made by Intel co-founder Gordon Moore in 1965. He noticed that the number of transistors per square inch on integrated circuits had doubled every year since their invention. Moore's law predicts that this trend will continue into the foreseeable future

"I've heard the death of Moore's law more times than anything else in my career, and I'm here today to really show you and tell you that Moore's Law is alive and well and flourishing." Intel CEO Brian Krzanich (2017)

Moore's law does seem to predict speed increases as we can see from this chart of calculations per second per $1000:


1-10 of 39