Skip to content

Instantly share code, notes, and snippets.

@sarahstandish
sarahstandish / rot_n.rb
Created October 4, 2018 19:00
a program to rotate a string by n characters
# Method name: rot_n
# Inputs: A String to be encoded plus an integer to "rotate" by
# Returns: A ROT-N encoded message
# Prints: Nothing
# In a previous kata, we wrote a ROT13 method. In this one, we will write
# a ROT-N method.
# e.g., rot13(string) == rot_n(string, 13)
@sarahstandish
sarahstandish / rot13.rb
Created October 3, 2018 21:41
A program for the Rotate 13 "encode" method
# Method name: rot13
# Inputs: A String to be encoded in ROT13
# Returns: A ROT13-encoded string
# Prints: Nothing
# ROT13 is short for "rotate 13" and is the simplest example of a
# "Caesar cipher". See http://en.wikipedia.org/wiki/ROT13
# ROT13 works by taking a string and "rotating" all the characters in that
# string 13 places to the right in the alphabet, with "z" wrapping around to
@sarahstandish
sarahstandish / run_lenth_decode
Last active October 4, 2018 16:44
Run length decode problem
# Method name: run_length_encode
# Inputs: A String that has been "run-length encoded"
# Returns: The original string
# Prints: Nothing
# This takes a run-length encoded string and "reconstructs" the original string.
# From https://github.com/codeunion/ruby-exercises/blob/master/exercises/run_length_decode.rb
def run_length_decode(string)
@sarahstandish
sarahstandish / run_length_encode.rb
Created October 2, 2018 17:32
run length encoding exercise
# Method name: run_length_encode
# Inputs: A String to be encoded
# Returns: A String that has been "run-length encoded"
# Prints: Nothing
# This kata is meant to explore the basic idea behind file compression using
# a very naive type of compression called "run-length encoding."
# See http://en.wikipedia.org/wiki/Run-length_encoding
@sarahstandish
sarahstandish / time_format.rb
Last active September 25, 2018 22:39
Convert a number of seconds to the equivalent days, hours, and seconds
# Method name: time_format
# Inputs: A number, representing seconds
# Returns: A string, describing the number of weeks, days, minutes, seconds
# Prints: Nothing
# Remember when we wrote the countdown clock to count down from 5 minutes?
# Let's write a method that takes in an integer, representing a number of
# seconds, and returns a string describing larger chunks of time. For example,
#
# time_format(1234) == "20m 34s"
@sarahstandish
sarahstandish / tictactoe.rb
Last active October 2, 2018 22:33
Try at creating a tic tac toe game
# a tic tac toe game
def welcome_message
puts "Welcome to the tic tac toe game! \n \n"
end
#going to create an empty board
#where the key and the value are the same
ttt_board = {
@sarahstandish
sarahstandish / pig_latin.rb
Last active September 25, 2018 22:41
Pig latin program attempt--got a model that works but it's clunky...
# Method name: pig_latin
# Inputs: A string representing a single word (i.e., no spaces)
# Returns: The word translated into "pig latin"
# Prints: Nothing
# Note #1
# There are two rules for translating something into "pig latin":
# 1. If a word begins with a consonant or sequence of consonants, move the
# sequence of consonants to the end of the word and then append "ay"
# 2. If a word begins with a vowel, just append "ay"
@sarahstandish
sarahstandish / fibonacci.rb
Last active September 25, 2018 22:41
Program to calculate the nth fibonacci number
# Method name: fibonacci
# Inputs: A single non-negative integer, n
# Returns: The n-th Fibonacci number (see below)
# Prints: Nothing
# The Fibonacci numbers are the numbers in the following sequence:
#
# n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
# fib(n) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
#
@sarahstandish
sarahstandish / factorial.rb
Created September 18, 2018 15:10
Program that will give you n! (n factorial) -- exercise to practice ruby
# Method name: factorial
# Inputs: A single non-negative integer, n
# Returns: The factorial of n (see below)
# Prints: Nothing
# The factorial of 5 is denoted by 5! and is defined as
# 5! = 5*4*3*2*1
#
# In English, you'd read "5!" as "five factorial". In general, the factorial
# of a number is the product of every number from that number down to 1, so
@sarahstandish
sarahstandish / Commas.rb
Last active September 25, 2018 22:43
Program to insert commas in the correct places in numbers
# Method name: commas
# Inputs: A number, n
# Returns: A string representing the input, with commas inserted into the
# correct position.
# Prints: Nothing
# For example,
#
# commas(123) == "123"
# commas(1234) == "1,234"