From 13311aafeadc03e8652a2957bc47a6e167393333 Mon Sep 17 00:00:00 2001 From: Aphilosopher30 Date: Fri, 30 Oct 2020 13:37:40 -0600 Subject: [PATCH 01/11] Add day 1 --- day_1/calculator.txt | 2 ++ day_1/ex1.rb | 11 +++++++++++ day_1/ex2.rb | 11 +++++++++++ day_1/ex3.rb | 30 ++++++++++++++++++++++++++++++ day_1/ex4.rb | 24 ++++++++++++++++++++++++ day_1/ex5.rb | 19 +++++++++++++++++++ day_1/ex6.rb | 0 day_1/ex7.rb | 0 day_1/exercises/interpolation.rb | 3 ++- day_1/exercises/loops.rb | 8 ++++++-- day_1/exercises/numbers.rb | 7 ++++--- day_1/exercises/strings.rb | 6 ++++-- day_1/exercises/variables.rb | 11 +++++++++-- day_1/questions.md | 26 ++++++++++++++++++++++++++ 14 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 day_1/calculator.txt create mode 100644 day_1/ex1.rb create mode 100644 day_1/ex2.rb create mode 100644 day_1/ex3.rb create mode 100644 day_1/ex4.rb create mode 100644 day_1/ex5.rb create mode 100644 day_1/ex6.rb create mode 100644 day_1/ex7.rb diff --git a/day_1/calculator.txt b/day_1/calculator.txt new file mode 100644 index 000000000..d3f81eaee --- /dev/null +++ b/day_1/calculator.txt @@ -0,0 +1,2 @@ + +print (3.5+3)*.65 diff --git a/day_1/ex1.rb b/day_1/ex1.rb new file mode 100644 index 000000000..edcc53fea --- /dev/null +++ b/day_1/ex1.rb @@ -0,0 +1,11 @@ +#exercise 1: A good First Program + +puts "Hello world!" +#puts "Hello Again" +#puts "I like typing this." +#puts "this is fun." +#puts "Yay! Printing" +#puts "I'd much rather you 'not'." +#puts 'I "said" do not touch this.' + +#puts "another line" diff --git a/day_1/ex2.rb b/day_1/ex2.rb new file mode 100644 index 000000000..45594140e --- /dev/null +++ b/day_1/ex2.rb @@ -0,0 +1,11 @@ +#Exercise 2: Comments and Pound Characters + +#A comment, this is so you can read your program later. +# Anything after the # is ignored by ruby. + +puts "I could have code like this." # and the comment after is ignored + +# You can also use a comment to "disable" or comment out a piece of code: +# puts "This won't run." + +puts "This will run." diff --git a/day_1/ex3.rb b/day_1/ex3.rb new file mode 100644 index 000000000..176ba4ff8 --- /dev/null +++ b/day_1/ex3.rb @@ -0,0 +1,30 @@ +puts "I will now count my chickents:" + +#adds 25 to 30 devided by 6 +puts "Hens #{25.0 + 30.0 / 6.0}" +#multiplies 24 by 3 devides that number by 4, takes the remeinder and subtracts it from 100 +puts "Roosters #{100.0 - 25.0 * 3.0 % 4.0}" + +puts "Now I will count the eggs:" + +# it takes 4, devides by 2, then it subtracts 1 devided by 4, and then adds 6, 1, 2, 3, and subtrats 5 +puts 3.0 + 2.0 + 1.0 - 5.0 +4.0 %2.0 -1.0 /4.0 +6.0 + +puts "Is it true that 3 +2 < 5 - 7?" + +# prints out 3+2, and then 5-7 on a new line +puts 3.0 + 2.0 , 5.0 - 7.0 + +# prints the answer to the equastion as part of a string +puts "What is 3 + 2? #{3.0+2.0}" +# prints the answer to the equastion as part of a string +puts "What is 5 - 7? #{5.0-7.0}" + +puts "Oh, that's why it's false." + +puts "How about some more." + +#these lines evaluate wheather the left number is, greater than, greater or equal to, less than or equal to the number of the right, respectivly. if it is it prints out true, if not it prints out fallse +puts "Is it greater? #{5.0 > -2.0}" +puts "Is it greater or equal? #{5.0 >= -2.0}" +puts "Is it less or equal? #{5.0 <= -2.0}" diff --git a/day_1/ex4.rb b/day_1/ex4.rb new file mode 100644 index 000000000..cb1b638eb --- /dev/null +++ b/day_1/ex4.rb @@ -0,0 +1,24 @@ +#how many cars are there +cars = 100 +#how many passangers a car can have +space_in_a_car = 4.0 +#number of drivers +drivers = 30 +#nubmer of passangers +passengers = 90 +#the number of cars that don't get someone to drive them +cars_not_driven = cars - drivers +#number of cars that are driven +cars_driven = drivers +#number of people that can be transported +carpool_capacity = cars_driven * space_in_a_car +#average_passengers_per_car +average_passengers_per_car = passengers / cars_driven + + +puts "There are #{cars} cars available." +puts "There are only #{drivers} drivers available." +puts "There will be #{cars_not_driven} empty cars today." +puts "We can transport #{carpool_capacity} people today." +puts "We have #{passengers} to carpool today." +puts "We need to put about #{average_passengers_per_car} in each car." diff --git a/day_1/ex5.rb b/day_1/ex5.rb new file mode 100644 index 000000000..285ea4756 --- /dev/null +++ b/day_1/ex5.rb @@ -0,0 +1,19 @@ +name = 'Zed A. Shaw' +age = 35 # not a lie in 2009 +height = 74 #inches +weight = 180 # lbs +eyes = 'Blue' +teeth = 'White' +hair = 'Brown' + +height_in_centimeters = height*2.54 +weight_in_kilograms = weight*0.453592 + +puts "Let's talk about #{name}." +puts "He's #{height} inches tall." +puts "He's #{weight} pounds heavy." +puts "Actually that's not too heavy." +puts "He's got #{eyes} eyes and #{teeth} depending on the coffee." + +# this line is tricky, try to get it exactly right +puts "If I add #{age}, #{height}, and #{weight} i get #{age +height + weight}." diff --git a/day_1/ex6.rb b/day_1/ex6.rb new file mode 100644 index 000000000..e69de29bb diff --git a/day_1/ex7.rb b/day_1/ex7.rb new file mode 100644 index 000000000..e69de29bb diff --git a/day_1/exercises/interpolation.rb b/day_1/exercises/interpolation.rb index c7f4f47df..58fc2bb73 100644 --- a/day_1/exercises/interpolation.rb +++ b/day_1/exercises/interpolation.rb @@ -15,7 +15,7 @@ speedy = "quick red fox" slow_poke = "lazy brown dog" -p # YOUR CODE HERE +p "The #{speedy} jumps over #{slow_poke}." # Write code that uses the variables below to form a string that reads # "In a predictable result, the tortoise beat the hare!": @@ -23,3 +23,4 @@ speedy = "hare" # YOUR CODE HERE +"In a predictable result, the #{slow_poke} beat the #{speedy}!" diff --git a/day_1/exercises/loops.rb b/day_1/exercises/loops.rb index 90dc15ab1..d555c987e 100644 --- a/day_1/exercises/loops.rb +++ b/day_1/exercises/loops.rb @@ -5,14 +5,18 @@ # Example: Write code that prints your name five times: 5.times do - p "Hermione Granger" + puts "Andrew Shafer" end # Write code that prints the sum of 2 plus 2 seven times: 7.times do - # YOUR CODE HERE + puts 2+2 end # Write code that prints the phrase 'She sells seashells down by the seashore' # ten times: # YOUR CODE HERE + +10.times do + p "She sells seashells down by the seashore" +end diff --git a/day_1/exercises/numbers.rb b/day_1/exercises/numbers.rb index 9a5468a31..0a7486c38 100644 --- a/day_1/exercises/numbers.rb +++ b/day_1/exercises/numbers.rb @@ -7,10 +7,11 @@ p 2 + 2 # Write code that prints the result of 7 subtracted from 83: -p #YOUR CODE HERE +p 83 - 7 #YOUR CODE HERE # Write code that prints the result of 6 multiplied by 53: -# YOUR CODE HERE - +p 6*53 # Write code that prints the result of the modulo of 10 into 54: # YOUR CODE HERE + +p 54%10 diff --git a/day_1/exercises/strings.rb b/day_1/exercises/strings.rb index f2f903ffc..f0361a3e7 100644 --- a/day_1/exercises/strings.rb +++ b/day_1/exercises/strings.rb @@ -4,10 +4,12 @@ # `ruby day_1/exercises/strings.rb` # Example: Write code that prints your name to the terminal: -p "Alan Turing" +p "Andrew Shafer" # Write code that prints `Welcome to Turing!` to the terminal: -p #YOUR CODE HERE +p "Welcome to Turing!"#YOUR CODE HERE # Write code that prints `99 bottles of pop on the wall...` to the terminal: # YOUR CODE HERE + +p "99 bottles of pop on the wall..." diff --git a/day_1/exercises/variables.rb b/day_1/exercises/variables.rb index a1e45bb26..1f87831bb 100644 --- a/day_1/exercises/variables.rb +++ b/day_1/exercises/variables.rb @@ -1,29 +1,36 @@ # In the below exercises, write code that achieves # the desired result. To check your work, run this -# file by entering the following command in your terminal: +# file by entering the following command in your terminal: # `ruby day_1/exercises/variables.rb` # Example: Write code that saves your name to a variable and # prints what that variable holds to the terminal: -name = "Harry Potter" +name = "Andrew Shafer" p name # Write code that saves the string 'Dobby' to a variable and # prints what that variable holds to the terminal: house_elf = "Dobby" # YOUR CODE HERE +p house_elf # Write code that saves the string 'Harry Potter must not return to Hogwarts!' # and prints what that variable holds to the terminal: # YOUR CODE HERE +string = "Harry Potter must not return to Hogwarts!" +p string + # Write code that adds 2 to the `students` variable and # prints the result: students = 22 # YOUR CODE HERE +students += 2 + p students # Write code that subracts 2 from the `students` variable and # prints the result: # YOUR CODE HERE +students = students - 2 p students diff --git a/day_1/questions.md b/day_1/questions.md index 73700e323..3af11552a 100644 --- a/day_1/questions.md +++ b/day_1/questions.md @@ -2,16 +2,42 @@ 1. How would you print the string `"Hello World!"` to the terminal? +`print "Hello World!"` + 1. What character is used to indicate comments in a ruby file? +'#' + 1. Explain the difference between an integer and a float? +a float is a number with a decimal while an integer is a number without a descimal. + 1. In the space below, create a variable `animal` that holds the string `"zebra"` +'animal = "zebra" ' + 1. How would you print the string `"zebra"` using the variable that you created above? +'puts animal' + 1. What is interpolation? Use interpolation to print a sentence using the variable `animal`. +interpolation is basically something that lest you run code inside of a string. + +'puts "the animal is a #{animal}"' + + 1. What method is used to get input from a user? +gets.chomp + + 1. Name and describe two common string methods: + + +'.length' +this method tells us how long the string is. + + +'.upcase' +this method changes the string to be all uppercase. From 08e0b8e8fb8bcfd55617a74948dd817368f09e0d Mon Sep 17 00:00:00 2001 From: Aphilosopher30 Date: Fri, 30 Oct 2020 13:54:57 -0600 Subject: [PATCH 02/11] Add two files to day_1 --- day_1/ex6.rb | 34 ++++++++++++++++++++++++++++++++++ day_1/ex7.rb | 10 ++++++++++ 2 files changed, 44 insertions(+) diff --git a/day_1/ex6.rb b/day_1/ex6.rb index e69de29bb..f5cf92609 100644 --- a/day_1/ex6.rb +++ b/day_1/ex6.rb @@ -0,0 +1,34 @@ +# Strings and Text +#this is a number +types_of_people = 10 +#this puts that nuber in a stinrg +x = "There are #{types_of_people} types of people." +#string +binary = "binary" +#string +do_not = "don't" +#string with string in it +y = "Those who know #{binary} and those who #{do_not}." + +#printing strings +puts x +puts y + +#printing strings in more strings +puts "I said:#{x}." +puts "I also said: '#{y}'" + +#bollion +hilarious = false +#bollion in string +joke_evaluation = "Isn't that joke so funny?! #{hilarious}" + +#printing bollion in string +puts joke_evaluation + +#strings +w = "This is the left side of..." +e = "a string with a right side." + +#combining strings +puts w + e diff --git a/day_1/ex7.rb b/day_1/ex7.rb index e69de29bb..f930477f9 100644 --- a/day_1/ex7.rb +++ b/day_1/ex7.rb @@ -0,0 +1,10 @@ +#excercise 11: asking Questions + +print "How old are you? " +age = gets.chomp +print "How tall are you? " +height = gets.chomp +print "How much do you weigh? " +weight = gets.chomp + +puts "so, you're #{age} old, #{height} tall and #{weight} heavy." From 45140f6bbb898a9da852e3948ef16a6339495354 Mon Sep 17 00:00:00 2001 From: Aphilosopher30 Date: Fri, 30 Oct 2020 14:48:32 -0600 Subject: [PATCH 03/11] Add Day 2 Work --- day_2/aray_methods.ms | 11 +++++ day_2/exercises/arrays.rb | 18 ++++++++- day_2/exercises/iteration.rb | 20 +++++++-- day_2/iteration_exercises.rb | 78 ++++++++++++++++++++++++++++++++++++ day_2/questions.md | 20 +++++++++ 5 files changed, 142 insertions(+), 5 deletions(-) create mode 100644 day_2/aray_methods.ms create mode 100644 day_2/iteration_exercises.rb diff --git a/day_2/aray_methods.ms b/day_2/aray_methods.ms new file mode 100644 index 000000000..4e60a33db --- /dev/null +++ b/day_2/aray_methods.ms @@ -0,0 +1,11 @@ + + +.sort : returns a sorted array +.each : cycles through an array +.join : take a array and puts each element of that array into a string +.index : returns the index position of the +include? : if an array contains a specific element then it returns true, if not, then it returns false +.collect : goes through each element in an array and modifies it +.first : returns the first element of the array +.last : returns the last element of the array +.shuffle : returns an array that is NOT sorted. diff --git a/day_2/exercises/arrays.rb b/day_2/exercises/arrays.rb index f572a5ae6..c46d87ecb 100644 --- a/day_2/exercises/arrays.rb +++ b/day_2/exercises/arrays.rb @@ -10,12 +10,15 @@ # Write code that stores an array of states in a variable, # then prints that array: -states = #YOUR CODE HERE +states = ["CO", "NY", "CA", "TX", "AZ"] #YOUR CODE HERE p states # Write code that stores an array of foods in a variable, # then prints that array: # YOUR CODE HERE +foods = ["toco", "pizza" , "banana"] +p foods + # Example: Write code that prints the number of elements # in your above array of animals: @@ -24,17 +27,30 @@ # Write code that prints the number of elements # in your above array of foods: # YOUR CODE HERE +p foods.count + # Write code that prints "Zebra" from your animals array: # YOUR CODE HERE +p animals[0] + + # Write code that prints the last item of your foods array: # YOUR CODE HERE +p foods[-1] + + # Write code that adds "lion" to your animals array # and prints the result (Hint- use a method): # YOUR CODE HERE +animals.push("lion") +p animals + # Write code that removes the last element from your foods array # and prints the result (Hint- use a method): # YOUR CODE HERE +foods.pop() +p foods diff --git a/day_2/exercises/iteration.rb b/day_2/exercises/iteration.rb index a801cb4fc..ed1b4050c 100644 --- a/day_2/exercises/iteration.rb +++ b/day_2/exercises/iteration.rb @@ -15,14 +15,26 @@ # "The is awesome!" for each animal: animals.each do |animal| - # YOUR CODE HERE + p "The #{animal} is awesome!" end -# Write code that stores an array of foods in a variable, +# Write code that stores an array of foods in a variable, # then iterates over that array to print # "Add to shopping list" for each food item: # YOUR CODE HERE -# Write code that stores an array of numbers in a variable, -# then iterates over that array to print doubles of each number: +foods = ["egg", "toco", "hotdog"] + +foods.each do |food| + p "add #{food} to the shopping list" +end + +# Write code that stores an array of numbers in a variable, +# then iterates over that array to print doubles of each number: # YOUR CODE HERE + +numbers = [1, 2, 3, 4, 57, 8, 95, 0, 3, 6] + +numbers.each do |number| + p number*2 +end diff --git a/day_2/iteration_exercises.rb b/day_2/iteration_exercises.rb new file mode 100644 index 000000000..1c0524603 --- /dev/null +++ b/day_2/iteration_exercises.rb @@ -0,0 +1,78 @@ +#If you had an array of numbers, e.g. [1,2,3,4], how do you print out the doubles of each number? Triples? + +array = [1,2,3,4,5,6,7,8,9,10] + +# double + array.each {| number | puts number*2} + +# tripple + array.each {| number | puts number*3} + +#If you had the same array, how would you only print out the even numbers? What about the odd numbers? + +array = [1,2,3,4,5,6,7,8,9,10] + +#print even +array.each do |number| + if (number % 2) == 0 + print number + end +end + +#print odd +array.each do |number| + if (number % 2) == 1 + print number + end +end + +#How could you create a new array which contains each number multipled by 2? + +array = [1,2,3,4,5,6,7,8,9,10] + +new_array = array.collect{|number| number*2} + +#Given an array of first and last names, e.g. [“Alice Smith”, “Bob Evans”, “Roy Rogers”], how would you print out the full names line by line? + +array = ["Alice Smith", "Bob Evans", "Roy Rogers"] + +array.each do |name| + puts name +end + +#How would you print out only the first name? + +array.each do |name| + x = name.split + puts x[0] +end + + + +#How would you print out only the last name? + +array.each do |name| + x = name.split + puts x[1] +end + +#How could you print out only the initials? + +array.each do |name| + x = name.split + print x[0][0]+x[1][0] + "\n" +end + +#How can you print out the last name and how many characters are in it? + +array.each do |name| + x = name.split + puts "#{x[1]} has #{x.length} letters" +end + +#How can you create an integer which represents the total number of characters in all the names? + +x = 0 +array.each do |name| + x += name.length +end diff --git a/day_2/questions.md b/day_2/questions.md index a179f0b04..06a9ad03e 100644 --- a/day_2/questions.md +++ b/day_2/questions.md @@ -2,16 +2,36 @@ 1. Create an array containing the following strings: `"zebra", "giraffe", "elephant"`. +`["zebra", "giraffe", "elephant"]` + 1. Save the array you created above to a variable `animals`. +`animals = ["zebra", "giraffe", "elephant"]` + 1. Using the array `animals`, how would you access `"giraffe"`? +`animals[1]` + 1. How would you add `"lion"` to the `animals` array? +`animals.push("lion")` + 1. Name and describe two additional array methods: +.index() : tells you where in a an array a specific item is +.sort() : returns a new array that is sorted + 1. What are the boolean values in Ruby? +true and false + 1. In Ruby, how would you evaluate if `2` is equal to `25`? What is the result of this evaluation? +'2 == 25' +this returns false + + 1. In Ruby, how would you evaluate if `25` is greater than `2`? What is the result of this evaluation? + +'25 > 2 ' +this returns true From de31a25b5dd2a604fe449b843d8cb210f4828cd4 Mon Sep 17 00:00:00 2001 From: Aphilosopher30 Date: Fri, 30 Oct 2020 20:12:36 -0600 Subject: [PATCH 04/11] day_3 --- day_3/ex29.rb | 36 ++++++++++++++++++++++++++++++++ day_3/ex30.rb | 30 ++++++++++++++++++++++++++ day_3/ex31.rb | 36 ++++++++++++++++++++++++++++++++ day_3/exercises/if_statements.rb | 27 ++++++++++++++++-------- day_3/questions.md | 26 +++++++++++++++++++++++ 5 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 day_3/ex29.rb create mode 100644 day_3/ex30.rb create mode 100644 day_3/ex31.rb diff --git a/day_3/ex29.rb b/day_3/ex29.rb new file mode 100644 index 000000000..9fa2f48b5 --- /dev/null +++ b/day_3/ex29.rb @@ -0,0 +1,36 @@ +people = 30 +cats = 30 +dogs = 30 + + +if people < cats + puts "too many cats! The world is doomed!" +end + +if people > cats + puts "not many cats! The world is saved!" +end + +if people < dogs + puts "The world is drooled on!" +end + +if people > dogs + puts "The world is dry!" +end + + +dogs += 5 + +if people >= dogs + puts "People are greater than or equal to dogs." +end + +if people <= dogs + puts "people are less than or equal to dogs." +end + + +if people == dogs + puts "people are dogs." +end diff --git a/day_3/ex30.rb b/day_3/ex30.rb new file mode 100644 index 000000000..34ad5c40e --- /dev/null +++ b/day_3/ex30.rb @@ -0,0 +1,30 @@ + +#these are the values we are working with +people = 30 +cars = 40 +trucks = 15 + +#this section evaluates compares cars to people to see if we should take cars +if cars > people + puts "We should take the cars." +elsif cars < people + puts "We should not take the cars." +else + puts "We can't decide." +end + +#compares trucks and cars. +if trucks > cars + puts "That's too many trucks." +elsif trucks < cars + puts "Maybe we could take the trucks." +else + puts "We still can't decide." +end + +#this part evaluates people vs trucks to see if we should take trucks or stay home. +if people > trucks + puts "Alright. let's just take the trucks." +else + puts "Fine, let's stay home then." +end diff --git a/day_3/ex31.rb b/day_3/ex31.rb new file mode 100644 index 000000000..4bad96595 --- /dev/null +++ b/day_3/ex31.rb @@ -0,0 +1,36 @@ +puts "You enter a dark room with two doors. Do you go through door #1 or door #2?" + +print "> " +door = $stdin.gets.chomp + +if door == "1" + puts "There's a giant bear here eating a cheese cake. What do you do?" + puts "1. Take the cake." + puts "2. Scream at the bear." + + print "> " + bear = $stdin.gets.chomp + + if bear == "1" + puts "The bear eats your face off. Good job!" + elsif bear == "2" + puts "The bear eats your legs off. Good job!" + else + puts "Well, doing %s is probably better. Bear runs away." % bear + end + +elsif door == "2" + puts "You stare into the endless abyss at Cthulhu's retina." + puts "1. Blueberries." + puts "2. Yellow jacket clothespins." + puts "3. Understanding revolvers yelling melodies." + + print "> " + insanity = $stdin.gets.chomp + + if insanity == "1" ||insanity == "2" + puts "Your body survives powered by a mind of jello. Good Job!" + else + puts "The insanity rots your eyes into a pool of muck. Good job!" + end +end diff --git a/day_3/exercises/if_statements.rb b/day_3/exercises/if_statements.rb index a80b96840..4ba050017 100644 --- a/day_3/exercises/if_statements.rb +++ b/day_3/exercises/if_statements.rb @@ -3,14 +3,14 @@ # file by entering the following command in your terminal: # `ruby day_3/exercises/if_statements.rb` -# Example: Using the weather variable below, write code that decides +# Example: Using the weather variable below, write code that decides # what you should take with you based on the following conditions: # if it is sunny, print "sunscreen" # if it is rainy, print "umbrella" # if it is snowy, print "coat" # if it is icy, print "yak traks" - weather = 'snowy' + weather = 'sunny' if weather == 'sunny' p "sunscreen" @@ -35,7 +35,7 @@ # Right now, the program will print # out both "I have enough money for a gumball" and -# "I don't have enough money for a gumball". Write a +# "I don't have enough money for a gumball". Write a # conditional statement that prints only one or the other. # Experiment with manipulating the value held within num_quarters @@ -43,13 +43,15 @@ num_quarters = 0 -puts "I have enough money for a gumball" -puts "I don't have enough money for a gumball" - +if num_quarters > 1 + puts "I have enough money for a gumball" +else + puts "I don't have enough money for a gumball" +end ##################### # Using the variables defined below, write code that will tell you -# if you have the ingredients to make a pizza. A pizza requires +# if you have the ingredients to make a pizza. A pizza requires # at least two cups of flour and sauce. # You should be able to change the variables to achieve the following outputs: @@ -61,5 +63,12 @@ # Experiment with manipulating the value held within both variables # to make sure all above conditions output what you expect. -cups_of_flour = 1 -has_sauce = true +cups_of_flour = 5 +has_sauce = false + + +if cups_of_flour >= 2 and has_sauce == true + puts "I can make pizza" +else + puts "i cannot make pizza" +end diff --git a/day_3/questions.md b/day_3/questions.md index db6170fa7..48b1d5876 100644 --- a/day_3/questions.md +++ b/day_3/questions.md @@ -2,12 +2,38 @@ 1. What is a conditional statement? Give three examples. +it's basically a sentence that uses the word 'if', or some equivalent. + +* if you have the password, then you can enter. +* if it is raining, then the ground is wet. +* if the moon in made of green cheese, then blubber is gray. + 1. Why might you want to use an if-statement? +because sometimes you need something to happen only if certain conditions are met. + + 1. What is the Ruby syntax for an if statement? +if conditional + execute code +end + 1. How do you add multiple conditions to an if statement? +you use the term "elsif" + + 1. Provide an example of the Ruby syntax for an if/elsif/else statement: +if x == 1 + print "no" +elsif x == 2 + print "yes" +elsif == 3 + print "perhaps" +end + 1. Other than an if-statement, can you think of any other ways we might want to use a conditional statement? + +not really. i consider the statement "unless you do this, that will happen" to be an if statement, because it is logically equivalent to, "IF you do NOT do this, THEN that will happen", even though it technically does not have the word 'if' in it. from this perspective, you can't have a conditional statement that is not also, at least indirectly an if-statement. From 6c27f5425d7fbe769a43f1f28b5e44fd15671f8c Mon Sep 17 00:00:00 2001 From: Aphilosopher30 Date: Sat, 31 Oct 2020 12:12:38 -0600 Subject: [PATCH 05/11] Add day 4 work --- day_4/exercices.rb | 12 ++++++++++ day_4/exercises/ex18.rb | 25 ++++++++++++++++++++ day_4/exercises/ex19.rb | 47 ++++++++++++++++++++++++++++++++++++++ day_4/exercises/ex21.rb | 37 ++++++++++++++++++++++++++++++ day_4/exercises/methods.rb | 26 ++++++++++++++++----- day_4/mutate.rb | 21 +++++++++++++++++ day_4/mutate0.rb | 21 +++++++++++++++++ day_4/questions.md | 19 +++++++++++++++ day_4/return.rb | 7 ++++++ day_4/say.rb | 16 +++++++++++++ 10 files changed, 225 insertions(+), 6 deletions(-) create mode 100644 day_4/exercices.rb create mode 100644 day_4/exercises/ex18.rb create mode 100644 day_4/exercises/ex19.rb create mode 100644 day_4/exercises/ex21.rb create mode 100644 day_4/mutate.rb create mode 100644 day_4/mutate0.rb create mode 100644 day_4/return.rb create mode 100644 day_4/say.rb diff --git a/day_4/exercices.rb b/day_4/exercices.rb new file mode 100644 index 000000000..625a74636 --- /dev/null +++ b/day_4/exercices.rb @@ -0,0 +1,12 @@ +# Write a program that prints a greeting message. This program should contain a method called greeting that takes a name as its parameter and returns a string. + +def greeting(name) + "hello, #{name}" +end + +# Write a program that includes a method called multiply that takes two arguments and returns the product of the two numbers. + +def multiply(a, b) + print a*b + a * b +end diff --git a/day_4/exercises/ex18.rb b/day_4/exercises/ex18.rb new file mode 100644 index 000000000..0e22a7b48 --- /dev/null +++ b/day_4/exercises/ex18.rb @@ -0,0 +1,25 @@ +# this one is like your scripts with ARGV +def print_two(*args) + arg1, arg2 = args + puts "arg1: #{arg1}, arg2: #{arg2}" +end + +#OK, that *args is actually pointless, we can just do this +def print_two_again(arg1, arg2) + puts "arg1: #{arg1}, arg2: #{arg2}" +end + +# this just takes one argument +def print_one(arg1) + puts "arg1: #{arg1}" +end + +# this one takes no arguments +def print_none() + puts "I got nothin'." +end + +print_two("Zed","Shaw") +print_two_again("Zed","Shaw") +print_one("First!") +print_none() diff --git a/day_4/exercises/ex19.rb b/day_4/exercises/ex19.rb new file mode 100644 index 000000000..9838ac93c --- /dev/null +++ b/day_4/exercises/ex19.rb @@ -0,0 +1,47 @@ + +# this method prints out how much cheese and chrackers we have +def cheese_and_crackers(cheese_count, boxes_of_crackers) + puts "You have #{cheese_count} cheeses!" + puts "You have #{boxes_of_crackers} boxes of crackers!" + puts "Man that's enough for a party!" + puts "get a blanket. \n" +end + +# this section is about printing crackers and chesse there is +puts "We can just give the function numbers directly:" +cheese_and_crackers(20, 30) + +# this section is about assinging variables that signify how much crackers ad chesse we have +puts "OR, we can use variables from our script:" +amounts_of_cheese = 10 +amounts_of_crackers = 50 + +#this uses the veriables as peramiters +cheese_and_crackers(amounts_of_cheese, amounts_of_crackers) + +# this uses math within the peramiters +puts "We can even do maths inside too:" +cheese_and_crackers(10 + 20, 5 + 6) + +# veiables AND mathematics in peramiters +puts "And we can combine the two, variables and math:" +cheese_and_crackers(amounts_of_cheese+100, amounts_of_crackers+1000) + + +def add_two_numbers(x,y) + return x+y +end + +add_two_numbers(1,2) +add_two_numbers(3,4) +add_two_numbers(6,5) + +add_two_numbers(2,2) +add_two_numbers(3,3) +add_two_numbers(4,4) + +add_two_numbers(5,5) +add_two_numbers(6,6) +add_two_numbers(7,7) + +add_two_numbers(2345,87654) diff --git a/day_4/exercises/ex21.rb b/day_4/exercises/ex21.rb new file mode 100644 index 000000000..872d5d682 --- /dev/null +++ b/day_4/exercises/ex21.rb @@ -0,0 +1,37 @@ +def add(a,b) + puts "ADDING #{a} + #{b}" + a + b +end + +def subtract(a,b) + puts "SUBTRACTING #{a} - #{b}" + a - b +end + +def multiply(a,b) + puts "MULTIPLYING #{a} * #{b}" + return a*b +end + +def divide(a,b) + puts "DIVIDING #{a} / #{b}" + return a / b +end + + +puts "Let's do some math with just functions!" + +age = add(30, 5) +height = subtract(78, 4) +weight = multiply(90, 2) +iq = divide(100, 2) + +puts "Age: #{age}, Height: #{height}, Weight: #{weight}, IQ: #{iq}" + + +# A puzzle for the extra credit, type it in anyway. +puts "here is a puzzle." + +what = add(age, subtract(height, multiply(weight, divide(iq, 2)))) + +puts "That becomes: #{what}. Can you do it by hand?" diff --git a/day_4/exercises/methods.rb b/day_4/exercises/methods.rb index 6ed338e5d..20e37ffd9 100644 --- a/day_4/exercises/methods.rb +++ b/day_4/exercises/methods.rb @@ -5,23 +5,37 @@ # Example: Write a method that when called will print your name: def print_name - p "Severus Snape" + p "Andrew Shafer" end print_name # Write a method that takes a name as an argument and prints it: def print_name(name) - # YOUR CODE HERE + p name end print_name("Albus Dumbledore") -# Write a method that takes in 2 numbers as arguments and prints +# Write a method that takes in 2 numbers as arguments and prints # their sum. Then call your method: # YOUR CODE HERE -# Write a method that takes in two strings as arguments and prints -# a concatenation of those two strings. Example: The arguments could be -# (man, woman) and the end result might output: "When Harry Met Sally". +def add_numbers(x, y) + puts x + y + return x + y +end + +add_numbers(2,2) + +# Write a method that takes in two strings as arguments and prints +# a concatenation of those two strings. Example: The arguments could be +# (man, woman) and the end result might output: "When Harry Met Sally". # Then call your method: + +def concatenate_strings(x,y) + puts x + y + return x + y +end + +concatenate_strings("something, ", "here") diff --git a/day_4/mutate.rb b/day_4/mutate.rb new file mode 100644 index 000000000..dc8e10e4f --- /dev/null +++ b/day_4/mutate.rb @@ -0,0 +1,21 @@ +a = [1,2,3] + +#Example of a method definition that modifies it's arguments permanently +def mutate(array) + array.pop +end + +p "Before mutate method: #{a}" +mutate(a) +p "After mutate method: #{a}" + +a = [1, 2, 3] + +#Example of a method defintiion that does not mutate the caller +def no_mutate(array) + array.last +end + +p "Before no_mutate method : #{a}" +no_mutate(a) +p "after no_mutate: #{a}" diff --git a/day_4/mutate0.rb b/day_4/mutate0.rb new file mode 100644 index 000000000..dc8e10e4f --- /dev/null +++ b/day_4/mutate0.rb @@ -0,0 +1,21 @@ +a = [1,2,3] + +#Example of a method definition that modifies it's arguments permanently +def mutate(array) + array.pop +end + +p "Before mutate method: #{a}" +mutate(a) +p "After mutate method: #{a}" + +a = [1, 2, 3] + +#Example of a method defintiion that does not mutate the caller +def no_mutate(array) + array.last +end + +p "Before no_mutate method : #{a}" +no_mutate(a) +p "after no_mutate: #{a}" diff --git a/day_4/questions.md b/day_4/questions.md index af17ab4da..1228377e3 100644 --- a/day_4/questions.md +++ b/day_4/questions.md @@ -2,10 +2,29 @@ 1. In your own words, what is the purpose of a method? +the purpose of a method is to bundle up a bunch of code into something we can reference in a short amount of space, so that we can run that same set of code more easily in different contexts. + + 1. Create a method named `hello` that will print `"Sam I am"`. +``` +def hello() + puts "Sam I am" +end +``` + 1. Create a method named `hello_someone` that takes an argument of `name` and prints `"#{name} I am"`. +``` +def hello_someone(name) + puts "#{name} I am" +end +``` + 1. How would you call or execute the method that you created above? +`hello_someone(Sam)` + 1. What questions do you have about methods in Ruby? + +none right now, but i am looking forward to playing around with lamdas and proc's when i have a chance. diff --git a/day_4/return.rb b/day_4/return.rb new file mode 100644 index 000000000..c670cfb7f --- /dev/null +++ b/day_4/return.rb @@ -0,0 +1,7 @@ +def add_three(number) + return number + 3 + number + 4 +end + +returned_value = add_three(4) +puts returned_value diff --git a/day_4/say.rb b/day_4/say.rb new file mode 100644 index 000000000..593ef00fb --- /dev/null +++ b/day_4/say.rb @@ -0,0 +1,16 @@ + + + +puts "hello" +puts "hi" +puts "how are you" +puts "I'm fine" + +def say(words='hello') + puts words + "." +end + +say( "hello") +say( "hi") +say("how are you") +say( "I'm fine") From ab92c60e85cc7eb66d5d115be5fb500dc1b0be07 Mon Sep 17 00:00:00 2001 From: Aphilosopher30 Date: Sat, 31 Oct 2020 17:09:19 -0600 Subject: [PATCH 06/11] Add day 5 work --- day_5/ex39.rb | 66 +++++++++++++++++++++++++++++++++++++++ day_5/exercises/hashes.rb | 23 ++++++++++---- day_5/questions.md | 16 ++++++++++ 3 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 day_5/ex39.rb diff --git a/day_5/ex39.rb b/day_5/ex39.rb new file mode 100644 index 000000000..6e164090a --- /dev/null +++ b/day_5/ex39.rb @@ -0,0 +1,66 @@ +# create a mapping of state to abbreviation +states = { + 'Oregon' => 'OR' + 'Flordia' => 'FL' + 'California' => 'CA' + 'New York'=> 'NY' + 'Michigan' => 'MI' +} + +# create a basic set of states and some cities in them +cities = { + 'CA' => 'San Francisco' + 'MI' => 'Detroit' + 'FL' => 'Jacksonvill' +} + +# add some more cities +cities['NY'] = 'New York' +cities['OR'] = 'Portland' + +# puts out some cities +puts '-' *10 +puts "NY State has: #{cities['NY']}" +puts "OR State has: #{cities['OR']}" + +# puts some states +puts '-' * 10 +puts "Michigan's abbreviation is: #{states['Michigan']}" +puts "Florida's abbreviation is: #{states['Florida']}" + +# do it by using the state then cities dict +puts '-'*10 +puts "Michigan's abbreviation is: #{states['Michigan']}" +puts "Florida's abbreviation is : #{states['Florida']}" + +#puts every state abbreviation +puts '-' * 10 +states.each do |state, abbrev| + puts "#{state} is abbreviated #{abbrev}" +end + +#puts every city in state +puts '-' * 10 +cities.each do |abbrev, city| + puts "#{abbrev} has the city #{city}" +end + +# now do both at the smae time +puts '-' * 10 +states.each do |state, abbrev| + city = cities[abbrev] + puts "#{state} is abbreviated #{ abbrev } and has city #{city}" +end + +puts '-' * 10 +# by default ruby says 'nil' when somethign isnt in there +state = state['Texas'] + +if !state + puts "Sorry, no Texas." +end + +# default values using || = with the nil result +city = cities ['TX'] +city ||= 'Does Not Exist' +puts "The city for the state 'TX' is: #{city}" diff --git a/day_5/exercises/hashes.rb b/day_5/exercises/hashes.rb index 99fcebb77..418d3497e 100644 --- a/day_5/exercises/hashes.rb +++ b/day_5/exercises/hashes.rb @@ -1,28 +1,39 @@ # In the below exercises, write code that achieves # the desired result. To check your work, run this -# file by entering the following command in your terminal: +# file by entering the following command in your terminal: # `ruby day_5/exercises/hashes.rb` # Example: Write code that prints a hash holding grocery store inventory: + foods = {apples: 23, grapes: 507, eggs: 48} p foods # Write code that prints a hash holding zoo animal inventory: -zoo = #YOUR CODE HERE +zoo = {"lion":4, "tiger's":6, "bears":8} p zoo -# Write code that prints all of the 'keys' of the zoo variable +# Write code that prints all of the 'keys' of the zoo variable # you created above: # YOUR CODE HERE -# Write code that prints all of the 'values' of the zoo variable +zoo.each_key{|key| puts key} + + +# Write code that prints all of the 'values' of the zoo variable # you created above: # YOUR CODE HERE -# Write code that prints the value of the first animal of the zoo variable +zoo.each_value{|value| puts value} + + +# Write code that prints the value of the first animal of the zoo variable # you created above: # YOUR CODE HERE -# Write code that adds an animal to the zoo hash. +puts zoo[:"lion"] + +# Write code that adds an animal to the zoo hash. # Then, print the updated hash: # YOUR CODE HERE + +zoo["Kiwi"] = 1 diff --git a/day_5/questions.md b/day_5/questions.md index d059e12c6..6e4c1d00f 100644 --- a/day_5/questions.md +++ b/day_5/questions.md @@ -2,12 +2,28 @@ 1. What is a Hash, and how is it different from an Array? +its a data structure that makes a list which connects to pieces of information so that you can use one to access the other. +it is primarily different from an array in that it is not ordered. + 1. In the space below, create a Hash stored to a variable named `pet_store`. This hash should hold an inventory of items and the number of that item that you might find at a pet store. +`pet_store = {"food": 33, "toys": 10, "litter_box":7}` + 1. Given the following `states = {"CO" => "Colorado", "IA" => "Iowa", "OK" => "Oklahoma"}`, how would you access the value `"Iowa"`? +`states["IA"]` + 1. With the same hash above, how would we get all the keys? How about all the values? +``` +states.each_key{|key| puts key} +states.each_value{|value| puts value} +``` + 1. What is another example of when we might use a hash? In your example, why is a hash better than an array? +grocery list. it's better in this case because we can now have each item on the grocery list pared with the number of items that we want to purchase of it. + 1. What questions do you still have about hashes? + +none. From c4fc04b305f3d6c81fe1cce3172c48a204a6086e Mon Sep 17 00:00:00 2001 From: Aphilosopher30 Date: Sat, 31 Oct 2020 23:42:32 -0600 Subject: [PATCH 07/11] Add day 6 work --- day_6/exercises/burrito.rb | 19 ++++++++++++++++++- day_6/exercises/dog.rb | 10 +++++++++- day_6/exercises/person.rb | 23 ++++++++++++++++++++++- day_6/exercises/student.rb | 18 ++++++++++++++++++ day_6/questions.md | 15 +++++++++++++++ 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 day_6/exercises/student.rb diff --git a/day_6/exercises/burrito.rb b/day_6/exercises/burrito.rb index 967f68b6c..e3bd32741 100644 --- a/day_6/exercises/burrito.rb +++ b/day_6/exercises/burrito.rb @@ -1,4 +1,4 @@ -# Add the following methods to this burrito class and +# Add the following methods to this burrito class and # call the methods below the class: # 1. add_topping # 2. remove_topping @@ -11,9 +11,26 @@ def initialize(protein, base, toppings) @base = base @toppings = toppings end + + def add_topping(topping) + return @protein << topping + end + + def remove_topping + @protein.pop + end + + def change_protein(new_protein) + @protein = new_protein + end + end dinner = Burrito.new("Beans", "Rice", ["cheese", "salsa", "guacamole"]) p dinner.protein p dinner.base p dinner.toppings + +dinner.remove_topping +dinner.add_topping("extra-CHEESE") +dinner.change_protein("pork") diff --git a/day_6/exercises/dog.rb b/day_6/exercises/dog.rb index 03221314d..a1a6b7eea 100644 --- a/day_6/exercises/dog.rb +++ b/day_6/exercises/dog.rb @@ -1,5 +1,5 @@ # In the dog class below, write a `play` method that makes -# the dog hungry. Call that method below the class, and +# the dog hungry. Call that method below the class, and # print the dog's hunger status. class Dog @@ -12,6 +12,10 @@ def initialize(breed, name, age) @hungry = true end + def play + @hungry = true + end + def bark p "woof!" end @@ -28,3 +32,7 @@ def eat p fido.hungry fido.eat p fido.hungry + + +fido.play +p fido.hungry diff --git a/day_6/exercises/person.rb b/day_6/exercises/person.rb index 2c26e9570..b64b344c7 100644 --- a/day_6/exercises/person.rb +++ b/day_6/exercises/person.rb @@ -1,5 +1,26 @@ -# Create a person class with at least 2 attributes and 2 behaviors. +# Create a person class with at least 2 attributes and 2 behaviors. # Call all person methods below the class and print results # to the terminal that show the methods in action. # YOUR CODE HERE + +class Person + attr_accessor :has_hair, :is_full + + def eats_food + self.is_full = true + end + + def shave_head + self.has_hair = false + end + +end + + +adam = Person.new +adam.has_hair = true +adam.is_full = true + +adam.is_full +adam.has_hair diff --git a/day_6/exercises/student.rb b/day_6/exercises/student.rb new file mode 100644 index 000000000..0c9be9b4d --- /dev/null +++ b/day_6/exercises/student.rb @@ -0,0 +1,18 @@ +class Student + attr_accessor :first_name, :last_name, :primary_phone_number + + def introduction(target) + puts "Hi #{target}, I'm #{first_name}" + end + + def favorite_number + 7 + end + +end + + +frank = Student.new +frank.first_name = "Frank" +frank.introduction('Katrina') +puts "frank's favorite number is #{frank.favorite_number}" diff --git a/day_6/questions.md b/day_6/questions.md index f58ca5f71..00bc3bfcc 100644 --- a/day_6/questions.md +++ b/day_6/questions.md @@ -2,12 +2,27 @@ 1. In your own words, what is a Class? +it is a category of things. + 1. What is an attribute of a Class? +it is a property that things have + 1. What is behavior of a Class? +it is what a member of the class can do. + 1. In the space below, create a Dog class with at least 2 attributes and 2 behaviors: +Dog class + +Attributes: gender and is_hungry +Behaviors: eat and reproduce + 1. How do you create an instance of a class? +`Class.new` + 1. What questions do you still have about classes in Ruby? + +none at the moment. From 7c1f57d48a985669e85fd6cc3b952f1a2145924b Mon Sep 17 00:00:00 2001 From: Aphilosopher30 Date: Wed, 6 Jan 2021 15:17:21 -0700 Subject: [PATCH 08/11] Add day 7 work --- day_7/10_speckled_frogs.rb | 45 ++++++++++++++++++++++++++++++++++++++ day_7/fizzbuzz.rb | 27 +++++++++++++++++++++++ day_7/high_level.md | 35 +++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 day_7/10_speckled_frogs.rb create mode 100644 day_7/fizzbuzz.rb create mode 100644 day_7/high_level.md diff --git a/day_7/10_speckled_frogs.rb b/day_7/10_speckled_frogs.rb new file mode 100644 index 000000000..470973966 --- /dev/null +++ b/day_7/10_speckled_frogs.rb @@ -0,0 +1,45 @@ + +#change this number to be any number of frogs you want. +starting_frogs = 10 + +#you need to add more numeral => lettering pairs if you want more than 10 frogs. +$num_words = {1 => "one", +2 => "two", +3 => "three", +4 => "four", +5 => "five", +6 => "six", +7 => "seven", +8 => "eight", +9 => "nine", +10 => "ten"} + +#this turns integers (1,2,etc) into words (one, two, etc). in call casses the wouds are fully lower case +def numeral_to_letters(numeral, numeral_refference = $num_words ) + if numeral_refference.key?(numeral) + return numeral_refference[numeral] + else + return numeral + end +end + +# use this for sellecting whether to print gramtical constructions that are plural or singular. +def singular(num, string, alt_string = "") + if num != 1 + return string + else + return alt_string + end +end + + + +for number in (starting_frogs).downto(1) + + puts " #{numeral_to_letters(number).capitalize} speckled frog#{singular(number, "s")} sat on a log + Eating some most delicious bugs. + #{singular(number, "One", "It")} jumped in the pool where it's nice and cool, + Then there #{singular(number, "was", "were")} #{numeral_to_letters(singular(number,(number-1), "no more"))} speckled frog#{singular(number, "s")}. \n \n" + + +end diff --git a/day_7/fizzbuzz.rb b/day_7/fizzbuzz.rb new file mode 100644 index 000000000..3e909f635 --- /dev/null +++ b/day_7/fizzbuzz.rb @@ -0,0 +1,27 @@ + + +def fizz_buzz(game_length = 100, ruels = {3=>"fizz", 5=>"buzz"}) + for number in 1..game_length + needs_number = true + + ruels.each_key do |key, value| + + if number % key == 0 + if needs_number == true + print ruels[key].capitalize + else + print ruels[key] + end + needs_number = false + end + end + + if needs_number == true + print number + end + print "\n" + end +end + + +fizz_buzz() diff --git a/day_7/high_level.md b/day_7/high_level.md new file mode 100644 index 000000000..4ae20a48d --- /dev/null +++ b/day_7/high_level.md @@ -0,0 +1,35 @@ + +##Ceasar Cipher + +1. Make a hash (call it alphabet) with each letter associated with a number {1:a, 2:b, 3:c etc} +2. Make a method, shift_character, that takes one character as an argument and one number as the argument and returns a character shifted by the number. + * If the number in the parameter is less than 0, then change the number to be the largest number in alphabet plus the negative number. + * If the character is uppercase, then Make the letter lowercase, and set a variable up_c to true + * If the character is not in the alphabet hash, then return character unchanged (this is so that things like “.”, “,”, “:”, and “ “ will not cause problems) + * else, take character and find associated number in alphabet and save to a veriable. + * Then subtract the number received from the parameters, from the number which associate with the character in alphabet and has been saved to a veriable. + * While the resulting number is 0 or less, then add the negative number to the largest possible number in alphabet. This will eventually result in a number that is between 1 and the largest possible number in alphabet. + * Take the number that results, and find the letter that is associated with it, and save that letter to a variable, called new_letter + * finally, If up_c == true, make new_letter upper case + * Return new_letter. +3. Make a method (call it, ‘encode’) that takes a string and a number as it’s argument, and returns the whole string shifted by the number. + * Make loop that goes through the string one character at a time + * Put each letter through the shift_character method, and shift it according to the number given in the parameter. + * Put each new character at the end of a new string. + * When the loop is fished, Return that new string. +4. prompt user for input of one string to be encoded +5. prompt user for number to be shifted +6. run encode, using peramiters that were just given by user +7. print result + +##Checker Board + +1. Make function print_line that takes one number (N) and two characters (X and Y) as inputs, and then prints those characters (X and Y) on a single line, alternating between them N number of times. + - Make loop that cycles through all numbers from 1 to N. for each number… + - If current number %2 == 0, then print X, otherwise print Y +2. Make function called print_board that takes two numbers L and W + - Make a loop that cycles through all numbers from 1 to L. for each number… + - If current number %2 = 0, you call function print_line. And pass it the parameters "X" and “ “ for X and Y. use W as N. + - Else (current number %2 != 0), you call function print_line and pass it the parameters “ “ and X for X and Y(the reverse order of how you did previously) use W as N. +4. Get a number from the user +5. Finally, call the function print_board, and use number recived as the parameter for both L and W. From 35c66c4256cb5d6fab5654001e17a1cb37e0d8f7 Mon Sep 17 00:00:00 2001 From: Andrew Shafer <73140608+Aphilosopher30@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:23:43 -0700 Subject: [PATCH 09/11] Update high_level.md --- day_7/high_level.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/day_7/high_level.md b/day_7/high_level.md index 4ae20a48d..f0de00262 100644 --- a/day_7/high_level.md +++ b/day_7/high_level.md @@ -1,8 +1,8 @@ ##Ceasar Cipher -1. Make a hash (call it alphabet) with each letter associated with a number {1:a, 2:b, 3:c etc} -2. Make a method, shift_character, that takes one character as an argument and one number as the argument and returns a character shifted by the number. +* Make a hash (call it alphabet) with each letter associated with a number {1:a, 2:b, 3:c etc} +* Make a method, shift_character, that takes one character as an argument and one number as the argument and returns a character shifted by the number. * If the number in the parameter is less than 0, then change the number to be the largest number in alphabet plus the negative number. * If the character is uppercase, then Make the letter lowercase, and set a variable up_c to true * If the character is not in the alphabet hash, then return character unchanged (this is so that things like “.”, “,”, “:”, and “ “ will not cause problems) @@ -12,15 +12,15 @@ * Take the number that results, and find the letter that is associated with it, and save that letter to a variable, called new_letter * finally, If up_c == true, make new_letter upper case * Return new_letter. -3. Make a method (call it, ‘encode’) that takes a string and a number as it’s argument, and returns the whole string shifted by the number. +* Make a method (call it, ‘encode’) that takes a string and a number as it’s argument, and returns the whole string shifted by the number. * Make loop that goes through the string one character at a time * Put each letter through the shift_character method, and shift it according to the number given in the parameter. * Put each new character at the end of a new string. * When the loop is fished, Return that new string. -4. prompt user for input of one string to be encoded -5. prompt user for number to be shifted -6. run encode, using peramiters that were just given by user -7. print result +* prompt user for input of one string to be encoded +* prompt user for number to be shifted +* run encode, using peramiters that were just given by user +* print result ##Checker Board From 04d71fd9c8282df37af66e154e7aa0dbb786232c Mon Sep 17 00:00:00 2001 From: Andrew Shafer <73140608+Aphilosopher30@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:24:25 -0700 Subject: [PATCH 10/11] Update high_level.md --- day_7/high_level.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/day_7/high_level.md b/day_7/high_level.md index f0de00262..dec2bf01c 100644 --- a/day_7/high_level.md +++ b/day_7/high_level.md @@ -24,12 +24,12 @@ ##Checker Board -1. Make function print_line that takes one number (N) and two characters (X and Y) as inputs, and then prints those characters (X and Y) on a single line, alternating between them N number of times. +- Make function print_line that takes one number (N) and two characters (X and Y) as inputs, and then prints those characters (X and Y) on a single line, alternating between them N number of times. - Make loop that cycles through all numbers from 1 to N. for each number… - If current number %2 == 0, then print X, otherwise print Y -2. Make function called print_board that takes two numbers L and W +- Make function called print_board that takes two numbers L and W - Make a loop that cycles through all numbers from 1 to L. for each number… - If current number %2 = 0, you call function print_line. And pass it the parameters "X" and “ “ for X and Y. use W as N. - Else (current number %2 != 0), you call function print_line and pass it the parameters “ “ and X for X and Y(the reverse order of how you did previously) use W as N. -4. Get a number from the user -5. Finally, call the function print_board, and use number recived as the parameter for both L and W. +- Get a number from the user +- Finally, call the function print_board, and use number recived as the parameter for both L and W. From 5a2ba45f22755c88419fed8d264b7aa6e8ba1f2f Mon Sep 17 00:00:00 2001 From: Andrew Shafer <73140608+Aphilosopher30@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:24:50 -0700 Subject: [PATCH 11/11] Update high_level.md --- day_7/high_level.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/day_7/high_level.md b/day_7/high_level.md index dec2bf01c..975135764 100644 --- a/day_7/high_level.md +++ b/day_7/high_level.md @@ -1,5 +1,5 @@ -##Ceasar Cipher +## Ceasar Cipher * Make a hash (call it alphabet) with each letter associated with a number {1:a, 2:b, 3:c etc} * Make a method, shift_character, that takes one character as an argument and one number as the argument and returns a character shifted by the number. @@ -22,7 +22,7 @@ * run encode, using peramiters that were just given by user * print result -##Checker Board +## Checker Board - Make function print_line that takes one number (N) and two characters (X and Y) as inputs, and then prints those characters (X and Y) on a single line, alternating between them N number of times. - Make loop that cycles through all numbers from 1 to N. for each number…