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 prefill(n,v="undefined") | |
| if !([true, false].include?(n)) && (n.to_i.to_s == n && n.to_i >= 0 || n.is_a?(Fixnum) && n >= 0) | |
| generate_array(n.to_i, v) | |
| else | |
| raise TypeError, "#{n} is invalid" | |
| end | |
| end | |
| def generate_array(n,v) | |
| case v |
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 Fibproduct | |
| def initialize | |
| @fib_numbers = [0, 1] | |
| end | |
| def product(prod) | |
| i = 0 | |
| loop do | |
| return [fib(i), fib(i + 1), true] if fib(i) * fib(i + 1) == prod |
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 tax_calculator total | |
| case | |
| when total.to_i <= 0 | |
| return 0 | |
| when total <= 10 | |
| tax_first(total) | |
| when total <= 20 | |
| tax_second(total) | |
| when total <= 30 |
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 strip_it(code) | |
| result = "" | |
| i = 0 | |
| commented = {singleline: false, multiline: false} | |
| while i <= code.size-1 | |
| case | |
| when code[i..i+1] == "/*" && commented[:singleline] == false && commented[:multiline] == false | |
| commented[:multiline] = true | |
| i += 2 | |
| when code[i..i+1] == "*/" && commented[:singleline] == false && commented[:multiline] == true |
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 josephus_survivor(n,k) | |
| circle = (1..n).to_a | |
| index = -1 | |
| size = circle.size | |
| until circle.size == 1 | |
| if index + k <= size | |
| index += k | |
| circle.delete_at(index) | |
| else | |
| index = k - (size - index) |
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 validate(n) | |
| multiply_other(n) % 10 == 0 ? true : false | |
| end | |
| def multiply_other(n) | |
| is_even?(n) ? multiply(n) { |index| index.odd? } : multiply(n) { |index| index.even? } | |
| end | |
| def is_even?(n) | |
| n.to_s.split(//).size.even? |
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 weirdcase string | |
| string.split.map { |word| word.each_char.with_index.map { |char, index| index.even? ? char.upcase : char.downcase }.join }.join(" ") | |
| 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 weirdcase string | |
| counter = 0 | |
| string.chars.map! do |char| | |
| counter = -1 if char == " " | |
| if counter.even? | |
| counter += 1 | |
| char.upcase | |
| else | |
| counter += 1 | |
| char.downcase |
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 Player | |
| def initialize | |
| @directions = [:forward, :right, :backward, :left] | |
| end | |
| def play_turn(warrior) | |
| @warrior = warrior | |
| @move_direction = find_way | |
| survive |
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 Player | |
| def play_turn(warrior) | |
| directions = [:forward, :right, :backward, :left] | |
| if warrior.listen.size > 0 | |
| way = warrior.direction_of(warrior.listen.last) | |
| else | |
| way = warrior.direction_of_stairs |