Skip to content

Instantly share code, notes, and snippets.

View johnc219's full-sized avatar
🙂

John Careaga johnc219

🙂
View GitHub Profile

Raspberry Pi Onboarding Steps

  • Updating packages
    • sudo apt-get update
    • sudo apt-get upgrade
    • sudo apt-get clean
    • sudo apt-get autoremove
  • Installing Vim
    • sudo apt-get vim
  • Apply a .vimrc
  • Change default editor
## -----------------------------------------------------------------------------
## Replace Type Code With Subclasses
## Replace Conditional with Polymorphism
## -----------------------------------------------------------------------------
# Start
class Animal
def initialize(type_code)
@type_code = type_code
# Calculate number of triangles (that don't contain triangles) inside a
# Sierpinski triangle
module Sierpinski
# @param [Integer] n - number of iterations
# @return [Integer] the number of triangles that don't contain triangles
#
# f(n) = 4(f(n - 1) - f(n - 2)) + f(n - 2)
# T(n) in O(n)
def self.triangles(n)
raise 'must be nonnegative' if n < 0