Skip to content

Commit

Permalink
Merge pull request #41 from MrPhantomT/master
Browse files Browse the repository at this point in the history
add issues
  • Loading branch information
mokevnin committed Jul 4, 2014
2 parents 7ec606b + 8ae07b8 commit c82d990
Show file tree
Hide file tree
Showing 58 changed files with 810 additions and 105 deletions.
27 changes: 27 additions & 0 deletions issues/array_fetch.yml
@@ -0,0 +1,27 @@
level: elementary
tags: [array]
checks:
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'));
17 changes: 17 additions & 0 deletions issues/array_interleave.yml
@@ -0,0 +1,17 @@
level: easy
tags: [array]
checks:
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));
20 changes: 20 additions & 0 deletions issues/array_transpose.yml
@@ -0,0 +1,20 @@
level: medium
tags: []
description: Re-implement Ruby's Array#transpose.
checks:
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
@@ -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
@@ -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))
19 changes: 19 additions & 0 deletions issues/build_key_value.yml
@@ -0,0 +1,19 @@
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_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
@@ -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
@@ -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
@@ -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))
33 changes: 33 additions & 0 deletions issues/credit_card_validator.yml
@@ -0,0 +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.
checks:
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
@@ -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
@@ -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
@@ -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"))']
27 changes: 27 additions & 0 deletions issues/fizzbuzz.yml
@@ -0,0 +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"
checks:
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
@@ -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
@@ -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))]
23 changes: 23 additions & 0 deletions issues/hash_deep_merge.yml
@@ -0,0 +1,23 @@
level: easy
tags: [hash]
description: Returns a new hash with **self** and **other_hash** merged recursively.
author: {github_nickname: zzet, web_page: 'http://zzet.org'}
checks:
ruby:
setup: |
h1 = { x: { y: [4, 5, 6] }, z: [7, 8, 9] }
h2 = { x: { y: [7, 8, 9] }, z: 'xyz' }
asserts:
- |
assert_equal({x: {y: [7, 8, 9]}, z: "xyz"}, h1.deep_merge(h2))
- |
assert_equal({x: {y: [4, 5, 6]}, z: [7, 8, 9]}, h2.deep_merge(h1))
javascript:
setup: |
var h1 = { x: { y: [4, 5, 6] }, z: [7, 8, 9] }
var h2 = { x: { y: [7, 8, 9] }, z: 'xyz' }
asserts:
- |
assertEqual({x: {y: [7, 8, 9]}, z: "xyz"}, deepMerge(h1, h2))
- |
assertEqual({x: {y: [4, 5, 6]}, z: [7, 8, 9]}, deepMerge(h2, h1))
14 changes: 14 additions & 0 deletions issues/hash_with_indifferent_access.yml
@@ -0,0 +1,14 @@
level: easy
tags: [hash]
description: Implement a hash class which does not distinguish between symbols and strings for its keys.
checks:
ruby:
setup: |
composers = HashWithIndifferentAccess.new
composers[:Janacek] = "Leos Janacek"
composers["Sweelinck"] = "Jan Pieterszoon Sweelinck"
mathematicians = HashWithIndifferentAccess["Yutaka", "Taniyama", :Alonzo, "Church"]
asserts: ['assert_equal "Leos Janacek", composers["Janacek"]', 'assert_equal "Jan
Pieterszoon Sweelinck", composers[:Sweelinck]', 'assert_equal "Taniyama",
mathematicians[:Yutaka]', 'assert_equal mathematicians["Alonzo"], mathematicians[:Alonzo]']
12 changes: 12 additions & 0 deletions issues/integer_difference.yml
@@ -0,0 +1,12 @@
level: easy
tags: [array, arithmetic]
description: |
Write a function that accepts an array of random integers and an integer n.
Determine the number of times where two integers in the array have the difference of n.
checks:
ruby:
asserts: ['assert_equal 3, integer_difference(4, [1, 1, 5, 6, 9, 16, 27])', 'assert_equal
4, integer_difference(2, [1, 1, 3, 3])']
javascript:
asserts: ['assertEqual(3, integerDifference(4, [1, 1, 5, 6, 9, 16, 27]))', 'assertEqual(4,
integerDifference(2, [1, 1, 3, 3]))']
10 changes: 10 additions & 0 deletions issues/invert_hash.yml
@@ -0,0 +1,10 @@
level: elementary
tags: [enumerable, hash]
description: Rewrite source hash to new representation
checks:
ruby:
asserts: ['assert_equal({10=>:c, 66=>:f, 78=>:b, "gAqtSP"=>:d}, invert_hash({:b=>78,
:c=>10, :d=>"gAqtSP", :f=>66}))', 'assert_equal({0=>[:c, :d], 55=>:b, "jXXuj1"=>:a},
invert_hash({:a=>"jXXuj1", :b=>55, :c=>0, :d=>0}))', 'assert_equal({0=>[:c,
:d, :e], 55=>:b, "jXXuj1"=>:a}, invert_hash({:a=>"jXXuj1", :b=>55, :c=>0,
:d=>0, :e=>0}))']

0 comments on commit c82d990

Please sign in to comment.