This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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" |
NewerOlder