Skip to content

Instantly share code, notes, and snippets.

@parksilk
parksilk / valid_triangle?.rb
Last active December 10, 2015 04:38
Code for my answer to "Exercise: Triangle side lengths" in Dev Bootcamp's Socrates. See the revisions for my original code that was missing some elements and did not work.
def valid_triangle?(a, b, c)
if a+b>c and a+c>b and b+c>a
true
else
false
end
end
@parksilk
parksilk / array_mode.rb
Last active June 20, 2018 20:52
Exercise: Calculating the array mode: Write a method "mode" which takes an Array of numbers as its input and returns an Array of the most frequent values. If there's only one most-frequent value, it returns a single-element Array. For example, mode([1,2,3,3]) # => [3] mode([4.5, 0, 0]) # => [0] mode([1.5, -1, 1, 1.5]) # => [1.5] mode([1,1,2,2]) …
def mode(array)
counter = Hash.new(0)
# this creates a new, empty hash with no keys, but makes all defalt values zero. it will be used to store
# the information from the array, such that the keys will be each unique number from the array (IOW, if there
# are two or more 4's in the array, there will just be one key that is a 4), and the value for each key will
# be the number of times that integer appears in the array.
array.each do |i|
counter[i] += 1
end
# this interates throught the array, and for each element it creates a key for that integer (if it hasn't been
@parksilk
parksilk / times_table.rb
Last active January 15, 2016 23:00
Implement a method called times_table which takes as its input an integer and prints out a times table with that number of rows.
def times_table(rows)
1.upto(rows) do |r|
1.upto(rows) do |c|
print (r * c), "\t" # the "\t" tabbs over and creates better colums than spaces
end
print "\n"
end
end
# it's two loops and the variables that track the number of iteratinos (r and c)
@parksilk
parksilk / super_fizzbuzz.rb
Created January 14, 2013 04:22
Dev Bootcamp exercise 22: Super FizzBuzz
def super_fizzbuzz(array)
result = []
array.each do |i|
if i % 15 == 0
result << "FizzBuzz"
elsif i % 5 == 0
result << "Buzz"
elsif i % 3 == 0
result << "Fizz"
else
@parksilk
parksilk / guessing_game.rb
Last active January 15, 2016 23:00
Dev Bootcamp Guessing Game Exercise
class GuessingGame
def initialize(answer)
@answer = answer
end
def guess(num_guess)
if num_guess > @answer then @result = :high
elsif num_guess < @answer then @result = :low
else @result = :correct
end

Keybase proof

I hereby claim:

  • I am parksilk on github.
  • I am park (https://keybase.io/park) on keybase.
  • I have a public key whose fingerprint is 9F45 F156 4C1A 5BD3 473D 574D 71E7 F6AC EE3A 6A4C

To claim this, I am signing this object: