-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kevin Nguyen #437
base: master
Are you sure you want to change the base?
Kevin Nguyen #437
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kevin, Great work on this and really excellent job pushing yourself with both extensions!
while number >= 2 | ||
p "#{number} speckled frogs sat on a log" | ||
p "eating some most delicious bugs." | ||
p "One jumped in the pool where its nice and cool," | ||
number -= 1 | ||
p "then there were #{number} speckled frogs." | ||
puts | ||
end | ||
p "#{number} speckled frogs sat on a log" | ||
p "eating some most delicious bugs." | ||
p "One jumped in the pool where its nice and cool," | ||
p "then there were no more speckled frogs." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of iteration. There are lots of repeated lines of code, that's a sign this could be refactored to remove those repetitions.
def cipher(input, shift) | ||
input_to_ascii_array = input.chars.map {|char| char.ord} | ||
shifted = input_to_ascii_array.map {|char| char+shift} | ||
shifted.map { |char| char.chr }.join | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: When you find code on google, call it out and re-write to match your style of programming.
|
||
p cipher("Pat is Mafia!", 6) | ||
|
||
#Or an alternate, less direct, version that includes 'class' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work thinking through an OOP way of doing this... keep going.
To keep track of how many spaces to shift, a way to track the current position of each letter in needed, then the number to shift over can be applied. First, we break up the "input" string into individual characters. I found the precise coding from google [primary reference link](https://medium.com/@alexander.virga/ruby-simple-string-encryption-shift-caesar-cipher-encoder-rot-9dedf06374d1): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate the transparency of showing your source of the solution you found. This is great.
Note: This exercise to get a step-by-step of how to solve the problem is to get you thinking algorithmically - like what is the recipe for making a caesar cipher?
Explaining the code you found in plain language is great - excellent work. I'd challenge you in the future to try to think first about the steps as you'd explain them in plain language, and then add in code snippets.
print number | ||
end | ||
|
||
FizzBuzz(1,100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on FizzBuzz!
def print_rows(size,y) #define method, uses size & xx | ||
if size % 2 == 0 #for even 'size' do this block | ||
while size >=1 #loop counter rows | ||
if size % 2 == 1 #print this line for odd rows | ||
puts " X" * y #prints pair ' X' y #of-times | ||
size -= 1 | ||
else #print this line for even rows | ||
puts "X " * y #prints pair 'X ' y #of-times | ||
size -= 1 | ||
end | ||
end | ||
else #for odd 'size' do this block | ||
while size >=1 #loop counter rows | ||
if size % 2 == 1 #print this line for odd rows | ||
print "X " * y #prints pair 'X ' y #of-times | ||
puts "X" #print last odd 'X' | ||
size -= 1 | ||
else #print this line for even rows | ||
print " X" * y #prints pair ' X' y #of-times | ||
puts " " #print last odd ' ' | ||
size -= 1 | ||
end | ||
end | ||
end | ||
end | ||
print_rows(size.to_i,y.to_i) #run the method for inputed 'size' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this extension. Cool to see your process of working through it in the comments too!
Here is my pre-work! Thank you.
https://github.com/kevn7n/backend_mod_1_prework.git