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
| beers = 99 | |
| while beers > 0 | |
| puts beers.to_s + ' bottles of beer on the wall, ' + beers.to_s + ' bottles of beer!' | |
| beers -= 1 | |
| if beers < 1 | |
| puts "Ya take one down, pass it around, no more bottles of beer on the wall!" | |
| else | |
| puts 'Ya take one down, pass it around, ' + beers.to_s + ' bottles of beer on the wall!' | |
| end |
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
| var numSheep = 4; | |
| var monthsToPrint = 12; | |
| for(var monthNumber = 1; monthNumber <= monthsToPrint; monthNumber++) { | |
| if (monthNumber % 4 = 0) { | |
| numSheep *= .75; | |
| var removed = numSheep; | |
| console.log("Removing " + removed + " sheep from the population. Phew!"); | |
| } else if (numSheep > 10000) { | |
| numSheep /= 2; |
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
| def decode(code) | |
| "SOLUTION GOES HERE" | |
| key = { | |
| a: ".-", | |
| b: "-...", | |
| c: "-.-.", | |
| d: "-..", | |
| e: ".", | |
| f: "..-.", | |
| g: "--.", |
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
| class Person | |
| def initialize(first_name,last_name) | |
| @first_name = first_name | |
| @last_name = last_name | |
| @full_name = @first_name + " " + @last_name | |
| end | |
| def print | |
| puts "My name is #{@full_name}." | |
| puts "My name is #{@first_name} #{@last_name}." | |
| end |
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
| def winner?(board) | |
| @match = false | |
| def check(type) | |
| @match = true if type.uniq.length == 1 && !type.include?(" ") | |
| end | |
| board.each do |row| | |
| check(row) | |
| end |
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
| def most_common(string) | |
| counts = {} | |
| words = string.downcase.tr(",.?!",'').split(' ') | |
| words.uniq.each do |word| | |
| counts[word] = 0 | |
| end | |
| words.each do |word| | |
| counts[word] = string.scan(word).count |
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
| def hex_to_decimal(input) | |
| input = input.split('') | |
| array = [] | |
| input.each do |x| | |
| x == "A" ? x.replace("10").to_i : x | |
| x == "B" ? x.replace("11").to_i : x | |
| x == "C" ? x.replace("12").to_i : x | |
| x == "D" ? x.replace("13").to_i : x | |
| x == "E" ? x.replace("14").to_i : x |
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
| def display_scores(file) | |
| num = 1 | |
| rankings = Hash.new | |
| File.open(file).each_line do |line| | |
| total = 0 | |
| line = line.split(',') | |
| name = line.shift | |
| line.each do |strokes| |
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
| def valid_email?(input) | |
| regex = /(\w*|\w*[.]\w*|\w*[-]\w*)[@](\w*|\w*[.]\w*|\w*[-]\w*)[.]((\w{2,4})|(\w{2}[.]\w{2,3}))/ | |
| regex.match(input) != nil ? true : false | |
| end | |
| def valid_phone_number?(input) | |
| regex = /\d{10}|[(]\d{3}[)]\s\d{3}[-]\d{4}|[(]\d{3}[)][-]\d{3}[-]\d{4}|\d{3}[-]\d{3}[-]\d{4}/ | |
| regex.match(input) != nil ? true : false | |
| end |
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
| def word_frequency(sample_file) | |
| count = Hash.new(0) | |
| IO.readlines(sample_file).each do |line| | |
| line.split(/[\W\s]/).each do |word| | |
| count[word.downcase] += 1 | |
| end | |
| end | |
| count |
OlderNewer