Skip to content

Commit

Permalink
add issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dementev Roman committed Jul 4, 2014
1 parent 51a1ff7 commit 8ae07b8
Show file tree
Hide file tree
Showing 50 changed files with 738 additions and 107 deletions.
38 changes: 25 additions & 13 deletions issues/array_fetch.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
tags: [array]
level: elementary
tags: [array]
checks:
ruby: ['arr = ["a", "b", "c"]', 'assert(=("b", fetch(arr, 1, "d")))', 'assert(=("d",
fetch(arr, 5, "d")))', 'assert(=("c", fetch(arr, -1, "d")))', 'assert(=("d",
fetch(arr, -5, "d")))']
javascript: ['var arr = ["a", "b", "c"];', 'assert(=("b", fetch(arr, 1, "d")));',
'assert(=("d", fetch(arr, 5, "d")));', 'assert(=("c", fetch(arr, -1, "d")));',
'assert(=("d", fetch(arr, -5, "d")));']
python: ['arr = ["a", "b", "c"]', 'assert(=("b", fetch(arr, 1, "d")))', 'assert(=("d",
fetch(arr, 5, "d")))', 'assert(=("c", fetch(arr, -1, "d")))', 'assert(=("d",
fetch(arr, -5, "d")))']
php: ['$arr = array("a", "b", "c");', 'assert(=("b", fetch(arr, 1, "d")));', 'assert(=("d",
fetch(arr, 5, "d")));', 'assert(=("c", fetch(arr, -1, "d")));', 'assert(=("d",
fetch(arr, -5, "d")));']
ruby: |-
arr = ['a', 'b', 'c']
assert_equal('b', fetch(arr, 1, 'd'))
assert_equal('d', fetch(arr, 5, 'd'))
assert_equal('c', fetch(arr, -1, 'd'))
assert_equal('d', fetch(arr, -5, 'd'))
javascript: |-
var arr = ['a', 'b', 'c'];
assertEqual('b', fetch(arr, 1, 'd'));
assertEqual('d', fetch(arr, 5, 'd'));
assertEqual('c', fetch(arr, -1, 'd'));
assertEqual('d', fetch(arr, -5, 'd'));
python: |-
arr = ['a', 'b', 'c']
assertEqual('b', fetch(arr, 1, 'd'))
assertEqual('d', fetch(arr, 5, 'd'))
assertEqual('c', fetch(arr, -1, 'd'))
assertEqual('d', fetch(arr, -5, 'd'))
php: |-
$arr = array('a', 'b', 'c');
assertEqual('b', fetch(arr, 1, 'd'));
assertEqual('d', fetch(arr, 5, 'd'));
assertEqual('c', fetch(arr, -1, 'd'));
assertEqual('d', fetch(arr, -5, 'd'));
24 changes: 15 additions & 9 deletions issues/array_interleave.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
tags: [array]
level: easy
tags: [array]
checks:
ruby: ['arr = [1, 3, 5]', 'assert(=([1, 2, 3, 4, 5, 6], interleave(arr, 2, 4, 6)))',
'assert(=([1, 2, 3, 4, 5], interleave(arr, [2, 4])))', 'assert(=([1, "2", 3, "4",
5], interleave(arr, "2", "4")))', 'assert(=([2, 4, 6], interleave([], 2, 4,
6)))', 'assert(=([1, 3, 5], interleave(arr)))']
javascript: ['var arr = [1, 3, 5];', 'assert(=([1, 2, 3, 4, 5, 6], interleave(arr,
2, 4, 6)));', 'assert(=([1, 2, 3, 4, 5], interleave(arr, [2, 4])));', 'assert(=([1,
"2", 3, "4", 5], interleave(arr, "2", "4")));', 'assert(=([2, 4, 6], interleave([],
2, 4, 6)));', 'assert(=([1, 3, 5], interleave(arr)));']
ruby: |-
arr = [1, 3, 5]
assert_equal([1, 2, 3, 4, 5, 6], interleave(arr, 2, 4, 6))
assert_equal([1, 2, 3, 4, 5], interleave(arr, [2, 4]))
assert_equal([1, '2', 3, '4', 5], interleave(arr, '2', '4'))
assert_equal([2, 4, 6], interleave([], 2, 4, 6))
assert_equal([1, 3, 5], interleave(arr))
javascript: |-
var arr = [1, 3, 5];
assertEqual([1, 2, 3, 4, 5, 6], interleave(arr, 2, 4, 6));
assertEqual([1, 2, 3, 4, 5], interleave(arr, [2, 4]));
assertEqual([1, '2', 3, '4', 5], interleave(arr, '2', '4'));
assertEqual([2, 4, 6], interleave([], 2, 4, 6));
assertEqual([1, 3, 5], interleave(arr));
33 changes: 18 additions & 15 deletions issues/array_transpose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
description: Re-implement Ruby's Array#transpose.
tags: []
level: medium
tags: []
description: Re-implement Ruby's Array#transpose.
checks:
ruby: ['assert(=([[1, :a], [2, :b], [3, :c]], transpose([[1, 2, 3], [:a, :b, :c]])))',
'assert(=([[1, 3, 5], [2, 4, 6]], transpose([[1, 2], [3, 4], [5, 6]])))', 'assert(=([],
transpose([])))']
javascript: ['assert(=([[1, "a"], [2, "b"], [3, "c"]], transpose([[1, 2, 3], ["a",
"b", "c"]])));', 'assert(=([[1, 3, 5], [2, 4, 6]], transpose([[1, 2], [3, 4],
[5, 6]])));', 'assert(=([], transpose([])));']
python: ['assert(=([[1, "a"], [2, "b"], [3, "c"]], transpose([[1, 2, 3], ["a", "b",
"c"]])))', 'assert(=([[1, 3, 5], [2, 4, 6]], transpose([[1, 2], [3, 4], [5,
6]])))', 'assert(=([], transpose([])))']
php: ['assert(=(array(array(1, "a"), array(2, "b"), array(3, "c")), transpose(array(array(1,
2, 3), array("a", "b", "c")))));', 'assert(=(array(array(1, 3, 5), array(2,
4, 6)), transpose(array(array(1, 2), array(3, 4), array(5, 6)))));', 'assert(=(array(),
transpose(array())));']
ruby: |-
assert_equal([[1, :a], [2, :b], [3, :c]], transpose([[1, 2, 3], [:a, :b, :c]]))
assert_equal([[1, 3, 5], [2, 4, 6]], transpose([[1, 2], [3, 4], [5, 6]]))
assert_equal([], transpose([]))
javascript: |-
assertEqual([[1, 'a'], [2, 'b'], [3, 'c']], transpose([[1, 2, 3], ['a', 'b', 'c']]));
assertEqual([[1, 3, 5], [2, 4, 6]], transpose([[1, 2], [3, 4], [5, 6]]));
assertEqual([], transpose([]));
python: |-
assertEqual([[1, 'a'], [2, 'b'], [3, 'c']], transpose([[1, 2, 3], ['a', 'b', 'c']]))
assertEqual([[1, 3, 5], [2, 4, 6]], transpose([[1, 2], [3, 4], [5, 6]]))
assertEqual([], transpose([]))
php: |-
assertEqual(array(array(1, 'a'), array(2, 'b'), array(3, 'c')), transpose(array(array(1, 2, 3), array('a', 'b', 'c'))));
assertEqual(array(array(1, 3, 5), array(2, 4, 6)), transpose(array(array(1, 2), array(3, 4), array(5, 6))));
assertEqual(array(), transpose(array()));
13 changes: 13 additions & 0 deletions issues/broken_include.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
level: elementary
tags: [array, set]
description: |
Check presence of element in array.
checks:
ruby:
setup: |
set = [1, 2, 3, 4, 5, 6, 7]
asserts: ['assert include?(set, 5)', 'assert !include?(set, 10)']
javascript:
setup: |
var set = [1, 2, 3, 4, 5, 6, 7];
asserts: ['assert(contains(set, 5))', 'assert(!contains(set, 10))']
12 changes: 12 additions & 0 deletions issues/build_hash_with_default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
level: elementary
tags: [hash]
checks:
ruby:
asserts: ['assert_equal({:draft => 0, :completed => 0}, generate([:draft, :completed],
0))', 'assert_equal({:one => 4, :two => 4}, generate([:one, :two], 4))']
javascript:
asserts:
- |
assertEqual({draft: 0, completed: 0}, generate(["draft", "completed"], 0))
- |
assertEqual({one: 4, two: 4}, generate(["one", "two"], 4))
30 changes: 17 additions & 13 deletions issues/build_key_value.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
tags: [array, hash]
level: medium
tags: [array, hash]
checks:
ruby: ['d = {"a" => {"b" => 3, "c" => 2, "d" => [1, 2]}, "x" => ["1", "2", "3"]}',
'expected = {"a[b]" => 3, "a[c]" => 2, "a[d][0]" => 1, "a[d][1]" => 2, "x[0]"
=> "1", "x[1]" => "2", "x[2]" => "3"}', 'assert(=(expected, b_key_val(d)))']
javascript: ['var d = {a: {b: 3, c: 2, d: [1, 2]}, x: ["1", "2", "3"]};', 'var expected
= {a[b]: 3, a[c]: 2, a[d][0]: 1, a[d][1]: 2, x[0]: "1", x[1]: "2", x[2]: "3"};',
'assert(=(expected, bKeyVal(d)));']
php: ['$d = array("a" => array("b" => 3, "c" => 2, "d" => array(1, 2)), "x" => array("1",
"2", "3"));', '$expected = array("a[b]" => 3, "a[c]" => 2, "a[d][0]" => 1, "a[d][1]"
=> 2, "x[0]" => "1", "x[1]" => "2", "x[2]" => "3");', 'assert(=(expected, bKeyVal(d)));']
python: ['d = {"a": {"b": 3, "c": 2, "d": [1, 2]}, "x": ["1", "2", "3"]}', 'expected
= {"a[b]": 3, "a[c]": 2, "a[d][0]": 1, "a[d][1]": 2, "x[0]": "1", "x[1]": "2",
"x[2]": "3"}', 'assert(=(expected, bKeyVal(d)))']
ruby: |-
d = {'a' => {'b' => 3, 'c' => 2, 'd' => [1, 2]}, 'x' => ['1', '2', '3']}
expected = {'a[b]' => 3, 'a[c]' => 2, 'a[d][0]' => 1, 'a[d][1]' => 2, 'x[0]' => '1', 'x[1]' => '2', 'x[2]' => '3'}
assert_equal(expected, b_key_val(d))
javascript: |-
var d = {a: {b: 3, c: 2, d: [1, 2]}, x: ['1', '2', '3']};
var expected = {a[b]: 3, a[c]: 2, a[d][0]: 1, a[d][1]: 2, x[0]: '1', x[1]: '2', x[2]: '3'};
assertEqual(expected, bKeyVal(d));
php: |-
$d = array('a' => array('b' => 3, 'c' => 2, 'd' => array(1, 2)), 'x' => array('1', '2', '3'));
$expected = array('a[b]' => 3, 'a[c]' => 2, 'a[d][0]' => 1, 'a[d][1]' => 2, 'x[0]' => '1', 'x[1]' => '2', 'x[2]' => '3');
assertEqual(expected, bKeyVal(d));
python: |-
d = {'a': {'b': 3, 'c': 2, 'd': [1, 2]}, 'x': ['1', '2', '3']}
expected = {'a[b]': 3, 'a[c]': 2, 'a[d][0]': 1, 'a[d][1]': 2, 'x[0]': '1', 'x[1]': '2', 'x[2]': '3'}
assertEqual(expected, bKeyVal(d))
18 changes: 18 additions & 0 deletions issues/check_phone_number_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
level: medium
tags: [regexp]
description: |
Write a method to validate some strings that could potentially represent phone numbers.
See if you can do it with a regular expression.
checks:
ruby:
asserts: ['assert phone_number?("5555555555")', 'assert !phone_number?("555555555")',
'assert phone_number?("555-5555")', 'assert phone_number?("(555) 555-5555")',
'assert !phone_number?("(555) 555-555")', 'assert phone_number?("555-555-5555")',
'assert !phone_number?("555a-555-5555")', 'assert !phone_number?("555*555-5555")',
'assert !phone_number?("55a-555-5555")']
javascript:
asserts: [assert(isPhoneNumber("5555555555")), assert(!isPhoneNumber("555555555")),
assert(isPhoneNumber("555-5555")), assert(isPhoneNumber("(555) 555-5555")),
assert(!isPhoneNumber("(555) 555-555")), assert(isPhoneNumber("555-555-5555")),
assert(!isPhoneNumber("555a-555-5555")), assert(!isPhoneNumber("555*555-5555")),
assert(!isPhoneNumber("55a-555-5555"))]
22 changes: 22 additions & 0 deletions issues/clash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
level: medium
tags: [hash]
author: {github_nickname: intridea, web_page: 'http://intridea.com'}
description: ''
checks:
ruby:
setup: |
c1 = Clash.new
c.where(:abc => 'def').order(:created_at)
c2 = Clash.new
c.where!.abc('def').ghi(123)._end!.order(:created_at)
c3 = Clash.new
c.where(:abc => 'def').where(:hgi => 123)
asserts:
- |
assert_equal({where: {abc: 'def'}, order: :created_at}, c1.to_hash)
- |
assert_equal({where: {abc: 'def', ghi: 123}, order: :created_at}, c2.to_hash)
- |
assert_equal({where: {abc: 'def', hgi: 123}}, c3.to_hash)
13 changes: 13 additions & 0 deletions issues/counting_array_elements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
level: easy
tags: []
checks:
ruby:
setup: |
test = ['cat', 'dog', 'fish', 'fish']
asserts: ['assert_equal({''cat'' => 1, ''dog'' => 1, ''fish'' => 2}, count(test))']
javascript:
setup: |
test = ['cat', 'dog', 'fish', 'fish']
asserts:
- |
assertEqual({cat: 1, dog: 1, fish: 2}, count(test))
40 changes: 26 additions & 14 deletions issues/credit_card_validator.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
level: medium
tags: [string]
description: |
Credit card numbers can be validated with a process called the Luhn algorithm. Simply stated, the Luhn algorithm works like this:
1. Starting with the next to last digit and continuing with every other digit going back to the beginning of the card, double the digit.
2. Sum all doubled and untouched digits in the number.
3. If that total is a multiple of 10, the number is valid.
tags: [string]
level: medium
checks:
ruby: ['assert(!valid_credit_card?("1234567890123456"))', 'assert(valid_credit_card?("4408041234567893"))',
'assert(!valid_credit_card?("440804l234567893"))', 'assert(valid_credit_card?("38520000023237"))',
'assert(valid_credit_card?("4222222222222"))']
javascript: ['assert(!validCreditCard?("1234567890123456"));', 'assert(validCreditCard?("4408041234567893"));',
'assert(!validCreditCard?("440804l234567893"));', 'assert(validCreditCard?("38520000023237"));',
'assert(validCreditCard?("4222222222222"));']
python: ['assert(!validCreditCard?("1234567890123456"))', 'assert(validCreditCard?("4408041234567893"))',
'assert(!validCreditCard?("440804l234567893"))', 'assert(validCreditCard?("38520000023237"))',
'assert(validCreditCard?("4222222222222"))']
php: ['assert(!validCreditCard?("1234567890123456"));', 'assert(validCreditCard?("4408041234567893"));',
'assert(!validCreditCard?("440804l234567893"));', 'assert(validCreditCard?("38520000023237"));',
'assert(validCreditCard?("4222222222222"));']
ruby: |-
assert(!valid_credit_card?('1234567890123456'))
assert(valid_credit_card?('4408041234567893'))
assert(!valid_credit_card?('4408042234567893'))
assert(valid_credit_card?('38520000023237'))
assert(valid_credit_card?('4222222222222'))
javascript: |-
assert(!validCreditCard?('1234567890123456'));
assert(validCreditCard?('4408041234567893'));
assert(!validCreditCard?('4408042234567893'));
assert(validCreditCard?('38520000023237'));
assert(validCreditCard?('4222222222222'));
python: |-
assert(!validCreditCard?('1234567890123456'))
assert(validCreditCard?('4408041234567893'))
assert(!validCreditCard?('4408042234567893'))
assert(validCreditCard?('38520000023237'))
assert(validCreditCard?('4222222222222'))
php: |-
assert(!validCreditCard?('1234567890123456'));
assert(validCreditCard?('4408041234567893'));
assert(!validCreditCard?('4408042234567893'));
assert(validCreditCard?('38520000023237'));
assert(validCreditCard?('4222222222222'));
22 changes: 22 additions & 0 deletions issues/dash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
level: medium
tags: [hash]
author: {github_nickname: intridea, web_page: 'http://intridea.com'}
description: |
Dash is an extended Hash that has a discrete set of defined properties and only those properties may be set on the hash.
Additionally, you can set defaults for each property. You can also flag a property as required.
Required properties will raise an exception if unset.
checks:
ruby:
setup: |
class Person < Dash
property :name, :required => true
property :email
property :occupation, :default => 'Rubyist'
end
p = Person.new(:name => "Bob")
p.email = 'abc@def.com'
asserts: ['assert_raise(ArgumentError) { Person.new }', 'assert_equal "Bob", p.name',
'assert_equal "abc@def.com", p.email', 'assert_raise(ArgumentError) { p.name
= nil }', 'assert_equal "Rubyist", p.occupation', 'assert_equal "Rubyist",
p[:occupation]', 'assert_raise(NoMethodError) { p[:awesome] }']
14 changes: 14 additions & 0 deletions issues/fibonacci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
level: easy
tags: []
description: |
"Write a method that handles Fibonacci sequences.
Have it return the nth item in the Fibonacci sequence.
Hint: The first item in the sequence is 0."
checks:
ruby:
asserts: ['assert_equal 0, fibo_finder(0)', 'assert_equal 1, fibo_finder(1)',
'assert_equal 3, fibo_finder(4)', 'assert_equal 13, fibo_finder(7)', 'assert_equal
55, fibo_finder(10)']
javascript:
asserts: ['assertEqual(0, fiboFinder(0))', 'assertEqual(1, fiboFinder(1))', 'assertEqual(3,
fiboFinder(4))', 'assertEqual(13, fiboFinder(7))', 'assertEqual(55, fiboFinder(10))']
15 changes: 15 additions & 0 deletions issues/find_palindrome.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
level: medium
tags: []
description: |
A palindrome is a string that is written the same forward as it is in reverse.
Write a method to return the longest palindrome in a given string.
checks:
ruby:
asserts: ['assert_equal "yzzy", longest_palindrome("xyzzy")', 'assert_equal "dhfdkjfffhhfffjkdfhd",
longest_palindrome("afbbbfjdjklgdfdhfdkjfffhhfffjkdfhdhkyejejfjkd")', 'assert_equal
"racecar", longest_palindrome("bartarcarracecarbartar")', 'assert_equal "46264",
longest_palindrome("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982")']
javascript:
asserts: ['assertEqual("yzzy", longestPalindrome("xyzzy"))', 'assertEqual("dhfdkjfffhhfffjkdfhd",
longestPalindrome("afbbbfjdjklgdfdhfdkjfffhhfffjkdfhdhkyejejfjkd"))', 'assertEqual("racecar",
longestPalindrome("bartarcarracecarbartar"))', 'assertEqual("46264", longestPalindrome("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982"))']
32 changes: 22 additions & 10 deletions issues/fizzbuzz.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
level: elementary
tags: [arithmetic, string]
description: |
If a number is divisible by 3, return "Fizz".
If a number is divisible by 5, return "Buzz".
If a number is divisible by 3 and 5, return "FizzBuzz"
tags: [arithmetic, string]
level: elementary
checks:
ruby: ['assert(=("Fizz", fizzbuzz(3)))', 'assert(=("Buzz", fizzbuzz(50)))', 'assert(=("FizzBuzz",
fizzbuzz(150)))', 'assert(=("FizzBuzz", fizzbuzz(5175)))']
javascript: ['assert(=("Fizz", fizzbuzz(3)));', 'assert(=("Buzz", fizzbuzz(50)));',
'assert(=("FizzBuzz", fizzbuzz(150)));', 'assert(=("FizzBuzz", fizzbuzz(5175)));']
php: ['assert(=("Fizz", fizzbuzz(3)));', 'assert(=("Buzz", fizzbuzz(50)));', 'assert(=("FizzBuzz",
fizzbuzz(150)));', 'assert(=("FizzBuzz", fizzbuzz(5175)));']
python: ['assert(=("Fizz", fizzbuzz(3)))', 'assert(=("Buzz", fizzbuzz(50)))', 'assert(=("FizzBuzz",
fizzbuzz(150)))', 'assert(=("FizzBuzz", fizzbuzz(5175)))']
ruby: |-
assert_equal('Fizz', fizzbuzz(3))
assert_equal('Buzz', fizzbuzz(50))
assert_equal('FizzBuzz', fizzbuzz(150))
assert_equal('FizzBuzz', fizzbuzz(5175))
javascript: |-
assertEqual('Fizz', fizzbuzz(3));
assertEqual('Buzz', fizzbuzz(50));
assertEqual('FizzBuzz', fizzbuzz(150));
assertEqual('FizzBuzz', fizzbuzz(5175));
php: |-
assertEqual('Fizz', fizzbuzz(3));
assertEqual('Buzz', fizzbuzz(50));
assertEqual('FizzBuzz', fizzbuzz(150));
assertEqual('FizzBuzz', fizzbuzz(5175));
python: |-
assertEqual('Fizz', fizzbuzz(3))
assertEqual('Buzz', fizzbuzz(50))
assertEqual('FizzBuzz', fizzbuzz(150))
assertEqual('FizzBuzz', fizzbuzz(5175))
17 changes: 17 additions & 0 deletions issues/flatten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
level: easy
tags: []
checks:
ruby:
asserts:
- |
assert_equal [1, 2, {:a => :b}], flatten([1, 2, [[{a: :b}]]])
- assert_equal [1, 2, 3, 4, 5, 6, 7, 8], flatten([1, [2, 3, [4, 5, [6, 7]]], 8])
- assert_equal [], flatten([])
- assert_equal [1, 2, 3, 4], flatten([[1, 2], [3, 4]])
javascript:
asserts:
- |
assertEqual([1, 2, {a: "b"}], flatten([1, 2, [[{a: "b"}]]]))
- assertEqual([1, 2, 3, 4, 5, 6, 7, 8], flatten([1, [2, 3, [4, 5, [6, 7]]], 8]))
- assertEqual([], flatten([]))
- assertEqual([1, 2, 3, 4], flatten([[1, 2], [3, 4]]))
15 changes: 15 additions & 0 deletions issues/happy_numbers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
level: medium
tags: []
description: |
Happy numbers are positive integers that follow a particular formula:
take each individual digit, square it, and then sum the squares to get a new number.
Repeat with the new number and eventually, you might get to a number whose squared sum is 1.
This is a happy number. An unhappy number (or sad number) is one that loops endlessly.
Write a function that determines if a number is happy or not.
checks:
ruby:
asserts: ['assert happy_number?(7)', 'assert happy_number?(986543210)', 'assert
!happy_number?(2)', 'assert !happy_number?(189)']
javascript:
asserts: [assert(isHappyNumber(7)), assert(isHappyNumber(986543210)), assert(!isHappyNumber(2)),
assert(!isHappyNumber(189))]

0 comments on commit 8ae07b8

Please sign in to comment.