Flatiron - Day 005

| Comments

In grade school, snow days meant building snowmen, tossing snow balls and going sledding. At the Flatiron School, snow days mean 6 hours of lecture via video conference. Avi and Co “cancelled” class today in advance of Snowmageddon 2013, but only in the sense that we weren’t expected to physically be in class. Instead, Avi set up a videoconference and hosted virtual class where we continued exploring Ruby.

We covered a range of topics today. Starting with a review of our homework, Avi discussed iteration, arrays, string methods, regular expressions, symbols, variable scope, blocks and hashes. Whew! We went through a lot of material today, but I think I’m grasping everything decently well. Its been pretty interesting to think about how there always seems to be more than one way of doing something in Ruby.

A good example of that was the homework we had last night. We had to write a simple FizzBuzz program and extend that to find all numbers that fizz, buzz or fizzbuzz within a range. I’ve posted my code below. What’s amazed me about coding, though, is that there are countless ways of doing the same thing, both within and across languages. For example, the “trick” to FizzBuzz is to recognize that Fizz and Buzz combine to make FizzBuzz. This means that my code below, while it gets the job done, is not the most efficient and probaly not up to best practices. I have three strings for the three results, but in fact I should only have two strings - Fizz and Buzz, which combine to make FizzBuzz.

Avi showed us a bunch of different ways to code the FizzBuzz problem, and if there’s a ton of different ways to solve the simple FizzBuzz problem, I can only begin to imagine how many infinite paths there are to building more complex applications. That thought is exciting to me; there are many paths out there that haven’t yet been explored and technology continues to be a space of great potential for human creativity and ingenuity. When I think back to a year ago, a part of me was resigned to thinking that we’ve reached the end of the road for technology - we have Google, Facebook and Twitter, what else could be out there? However, now that I’ve taken a peek under the hood of the web and seen a glimpse of what is possible, I’m convinced that the best is yet to come. Not just in web development, but in technology more broadly. 3-D printing, Internet-enabled hardware, sensors - the possibilities are limitless for the technology platforms that are only now in their infancy. Its both humbling and exciting to think about.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Define variable scope and initialize arrays

$fizzer = []
$buzzer = []
$fizzbuzzer = []
$remainder = []

# Method to calculate fizzbuzz for any given number

def fizzbuzz(num)
  if num % 3 == 0 && num % 5 == 0
    puts "FizzBuzz"
  elsif num % 3 == 0
    puts "Fizz"
  elsif num % 5 == 0
    puts "Buzz"
  else
    puts "Not divided by 3 or 5"
  end
end

# Method to ask a user to input a number they want to fizzbuzz

def fizzbuzz_ask
  print "What number do you want to fizzbuzz? "
  num = gets.to_i
  fizzbuzz(num)
end

# Method to fizzbuzz a range of numbers

def fizzbuzz_loop(num1=1, num2)
  (num1..num2).each do |i|
    if i % 3 == 0 && i % 5 == 0
      $fizzbuzzer << i
    elsif i % 3 == 0
      $fizzer << i
    elsif i % 5 == 0
      $buzzer << i
    else
      $remainder << i
    end
  end
end

# Method to ask a user to define the start and end points for fizzbuzz

def fizzbuzz_loop_ask
  print "Where do you want to start fizzbuzzing? "
  start = gets.to_i
  print "Where do you want to end fizzbuzzing? "
  finish = gets.to_i
  while finish == "".to_i
    puts "Sorry, please input an ending value. Where do you want to end fizzbuzzing?"
    finish = gets.to_i
  end
  fizzbuzz_loop(start, finish)
end

# Fizzbuzz method calls

fizzbuzz_ask
fizzbuzz_loop_ask

# Print results of fizzbuzz calls

puts "fizzer: #{$fizzer}"
puts "buzzer: #{$buzzer}"
puts "fizzbuzzer: #{$fizzbuzzer}"
puts "no fizz or buzz: #{$remainder}"

Comments