This file contains 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
require 'test/unit' | |
# Head ends here | |
def pairs( a,k) | |
#a is an array containing numbers and k is the difference. | |
end | |
class PairTest < Test::Unit::TestCase | |
def test_small_occurances | |
assert_equal 3, pairs([1, 5, 3, 4, 2], 2) |
This file contains 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
Your task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order. | |
Essentially, rearrange the digits to create the highest possible number. | |
Examples: | |
Input: 42145 Output: 54421 | |
Input: 145263 Output: 654321 | |
Input: 123456789 Output: 987654321 |
This file contains 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 Noise | |
def consider(number) | |
return 'fizzbuzz' if number % 15 == 0 | |
return 'fizz' if number % 3 == 0 | |
return 'buzz' if number % 5 == 0 | |
number | |
end | |
end | |
noise = Noise.new |
This file contains 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
Task | |
You will be given an array of numbers. You have to sort the odd numbers in ascending order while leaving the even numbers at their original positions. | |
Examples | |
[7, 1] => [1, 7] | |
[5, 8, 6, 3, 4] => [3, 8, 6, 5, 4] | |
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0] => [1, 8, 3, 6, 5, 4, 7, 2, 9, 0] |
This file contains 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
[Sample Input] | |
A 4 | |
B 3 | |
X 5 | |
[Sample output] | |
AAAA | |
BBB AAAA BBB | |
CC BBB AAAA BBB CC | |
D CC BBB AAAA BBB CC D |
This file contains 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
Sample Data: | |
//randomly generate 1 to 20 numbers with values between 0 and 1000. | |
2 4 6 8 10 12 14 | |
1 2 3 4 5 6 7 8 9 | |
2 10 20 21 23 24 40 55 60 61 | |
Sample Output: | |
//perhaps print out your randomly generated array one here so we can compare odds and evens | |
Odds - [] |
This file contains 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
# How would you write an erb file that produces exactly the following output | |
<articles> | |
<article>Title</article> | |
<article>Title</article> | |
<article class=”high”>Title</article> | |
<article>Title</article> | |
<article>Title</article> | |
<article class=”high”>Title</article> | |
<article>Title</article> | |
<article>Title</article> |
This file contains 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 BitmapEditor | |
VALID_SIZE_RANGE = (1..250) | |
DEFAULT_COLOR = 'O' | |
def clear(c = cols, r = rows) | |
return unless VALID_SIZE_RANGE === r && | |
VALID_SIZE_RANGE === c | |
@bitmap = Array.new(r) { Array.new(c) { DEFAULT_COLOR }} | |
end | |
This file contains 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
<html> | |
<head> | |
<style> | |
#container li{ font: 12pt/14pt Times; color: blue; } | |
ul.list li.item { font-size: 14pt; font-weight: bold; font-family: Verdana; } | |
</style> | |
</head> | |
<body> | |
<div id="container"> | |
<ul class="list"> |
This file contains 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
# Fizz Buzz | |
# Print the numbers from 1 to 100 | |
# If a number is divisible by 3 print "Fizz" instead | |
# If a number is divisible by 5 print "Buzz" instead | |
# If a number is divisible by 3 and 5 print "FizzBuzz" instead | |
# Sample output | |
# 1 | |
# 2 | |
# Fizz | |
# 4 |
NewerOlder