forked from exercism/exercism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create api endpoint to fetch current assignments
- Loading branch information
Showing
28 changed files
with
472 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
blurb: "Write a program that, given a word and a list of possible anagrams, selects the correct one(s)." | ||
source: "Inspired by the Extreme Startup game" | ||
source_url: "https://github.com/rchatley/extreme_startup" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
In other words, given: `"listen"` and `%w(enlists google inlets banana)` the program should return "inlets". |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Anagram = function Anagram(word) { | ||
this.word = word; | ||
}; | ||
|
||
Anagram.prototype = { | ||
match: function(words) { | ||
var matches = []; | ||
|
||
for(var i = 0; i < words.length; i++) { | ||
var currentWord = words[i]; | ||
|
||
if (currentWord.length == this.word.length) { | ||
var currentWordLetters = currentWord.split('').sort(); | ||
var matchingWordLetters = this.word.split('').sort(); | ||
|
||
var isMatch = true; | ||
|
||
for (var j = 0; j < currentWordLetters.length; j++) { | ||
if (currentWordLetters[j] != matchingWordLetters[j]) { | ||
isMatch = false; | ||
} | ||
} | ||
|
||
if (isMatch) { matches.push(currentWord); } | ||
} | ||
|
||
} | ||
return matches; | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require('./anagram'); | ||
|
||
describe('Anagram', function() { | ||
|
||
it("no matches",function() { | ||
var detector = new Anagram("diaper"); | ||
var matches = detector.match([ "hello", "world", "zombies", "pants"]); | ||
expect(matches).toEqual([]); | ||
}); | ||
|
||
it("detects simple anagram",function() { | ||
var detector = new Anagram("ba"); | ||
var matches = detector.match(['ab', 'abc', 'bac']); | ||
expect(matches).toEqual(['ab']); | ||
}); | ||
|
||
it("detects multiple anagrams",function() { | ||
var detector = new Anagram("abc"); | ||
var matches = detector.match(['ab', 'abc', 'bac']); | ||
expect(matches).toEqual(['abc', 'bac']); | ||
}); | ||
|
||
it("detects anagram",function() { | ||
var detector = new Anagram("listen"); | ||
var matches = detector.match(['enlists', 'google', 'inlets', 'banana']); | ||
expect(matches).toEqual(['inlets']); | ||
}); | ||
|
||
it("detects multiple anagrams",function() { | ||
var detector = new Anagram("allergy"); | ||
var matches = detector.match(['gallery', 'ballerina', 'regally', 'clergy', 'largely', 'leading']); | ||
expect(matches).toEqual(['gallery', 'regally', 'largely']); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
blurb: "Write a program that, given a word and a list of possible anagrams, selects the correct one(s)." | ||
source: "Inspired by the Extreme Startup game" | ||
source_url: "https://github.com/rchatley/extreme_startup" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Given `"listen"` and `%w(enlists google inlets banana)` the program should return "inlets". |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Anagram | ||
|
||
attr_reader :subject, :letters | ||
def initialize(subject) | ||
@subject = subject | ||
@letters = decompose subject | ||
end | ||
|
||
def match(words) | ||
words.select do |word| | ||
decompose(word) == letters | ||
end | ||
end | ||
|
||
private | ||
|
||
def decompose(s) | ||
s.chars.sort | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative 'anagram' | ||
|
||
class AnagramTest < MiniTest::Unit::TestCase | ||
|
||
def test_no_matches | ||
skip | ||
detector = Anagram.new('diaper') | ||
assert_equal [], detector.match(%w(hello world zombies pants)) | ||
end | ||
|
||
def test_detect_simple_anagram | ||
detector = Anagram.new('ba') | ||
anagrams = detector.match(['ab', 'abc', 'bac']) | ||
assert_equal ['ab'], anagrams | ||
end | ||
|
||
def test_detect_multiple_anagrams | ||
detector = Anagram.new('abc') | ||
anagrams = detector.match(['ab', 'abc', 'bac']) | ||
assert_equal ['abc', 'bac'], anagrams | ||
end | ||
|
||
def test_detect_anagram | ||
skip | ||
detector = Anagram.new('listen') | ||
anagrams = detector.match %w(enlists google inlets banana) | ||
assert_equal ['inlets'], anagrams | ||
end | ||
|
||
def test_multiple_anagrams | ||
skip | ||
detector = Anagram.new('allergy') | ||
anagrams = detector.match %w(gallery ballerina regally clergy largely leading) | ||
assert_equal ['gallery', 'regally', 'largely'], anagrams | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
blurb: "Bob is a lackadaisical teenager. In conversation, his responses are very limited." | ||
source: "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial." | ||
source_url: "http://pine.fm/LearnToProgram/?Chapter=06" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Bob answers 'Sure.' if you ask him a question. | ||
|
||
He answers 'Whatever.' if you tell him something. | ||
|
||
He answers 'Woah, chill out!' if you yell at him (ALL CAPS). | ||
|
||
He says 'Fine. Be that way!' if you address him without actually saying anything. | ||
|
||
Bob, Inspired by the 90s, is bringing back "l33t sP34k", and he'll teach you how to do it. Start any sentence with "Bro, ", and he'll translate the rest of it into l33t sP34k for you. | ||
|
||
## Hints | ||
|
||
`gets`, _get string_ is the opposite of `puts` _put string_. | ||
|
||
Notice that when you type "Something" and then hit enter, you get the string | ||
`"Something\n"` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class Bob | ||
|
||
def hey(something) | ||
if silent?(something) | ||
'Fine, be that way.' | ||
elsif question?(something) | ||
'Sure.' | ||
elsif shouting?(something) | ||
'Woah, chill out!' | ||
else | ||
'Whatever.' | ||
end | ||
end | ||
|
||
private | ||
|
||
def question?(s) | ||
s.end_with?('?') | ||
end | ||
|
||
def silent?(s) | ||
s.empty? | ||
end | ||
|
||
def shouting?(s) | ||
s.upcase == s | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative 'bob' | ||
|
||
class BobTest < MiniTest::Unit::TestCase | ||
attr_reader :bob | ||
|
||
def setup | ||
@bob = Bob.new | ||
end | ||
|
||
def test_stating_something | ||
assert_equal 'Whatever.', bob.hey('Tom-ay-to, tom-aaaah-to.') | ||
end | ||
|
||
def test_shouting | ||
skip | ||
assert_equal 'Woah, chill out!', bob.hey('WATCH OUT!') | ||
end | ||
|
||
def test_asking_a_question | ||
skip | ||
assert_equal 'Sure.', bob.hey('Does this cryogenic chamber make me look fat?') | ||
end | ||
|
||
def test_talking_forcefully | ||
skip | ||
assert_equal 'Whatever.', bob.hey("Let's go make out behind the gym!") | ||
end | ||
|
||
def test_shouting_numbers | ||
skip | ||
assert_equal 'Woah, chill out!', bob.hey('1, 2, 3 GO!') | ||
end | ||
|
||
def test_shouting_with_special_characters | ||
skip | ||
assert_equal 'Woah, chill out!', bob.hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!') | ||
end | ||
|
||
def test_silence | ||
skip | ||
assert_equal 'Fine, be that way.', bob.hey('') | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Write a program that given a string can count the occurrences of each word in that string. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
blurb: "Write a program that given a string can count the occurrences of each word in that string." | ||
source: "The golang tour" | ||
source_url: "http://tour.golang.org" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
```ruby | ||
words = Words.new("olly olly in come free") | ||
words.count | ||
# => {"olly" => 2, "in" => 1, "come" => 1, "free" => 1} | ||
``` | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Words | ||
|
||
attr_reader :text | ||
def initialize(text) | ||
@text = text.downcase.gsub(/[^a-z0-9\s]/, '') | ||
end | ||
|
||
def count | ||
data = Hash.new(0) | ||
text.split(" ").each do |word| | ||
data[word] += 1 | ||
end | ||
data | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative 'words' | ||
|
||
class WordsTest < MiniTest::Unit::TestCase | ||
|
||
def test_count_one_word | ||
words = Words.new("word") | ||
counts = {"word" => 1} | ||
assert_equal counts, words.count | ||
end | ||
|
||
def test_count_one_of_each | ||
skip | ||
words = Words.new("one of each") | ||
counts = {"one" => 1, "of" => 1, "each" => 1} | ||
assert_equal counts, words.count | ||
end | ||
|
||
def test_count_multiple_occurrences | ||
skip | ||
words = Words.new("one fish two fish red fish blue fish") | ||
counts = {"one"=>1, "fish"=>4, "two"=>1, "red"=>1, "blue"=>1} | ||
assert_equal counts, words.count | ||
end | ||
|
||
def test_ignore_punctuation | ||
skip | ||
words = Words.new("car : carpet as java : javascript!!&@$%^&") | ||
counts = {"car"=>1, "carpet"=>1, "as"=>1, "java"=>1, "javascript"=>1} | ||
assert_equal counts, words.count | ||
end | ||
|
||
def test_include_numbers | ||
skip | ||
words = Words.new("testing, 1, 2 testing") | ||
counts = {"testing" => 2, "1" => 1, "2" => 1} | ||
assert_equal counts, words.count | ||
end | ||
|
||
def test_normalize_case | ||
skip | ||
words = Words.new("go Go GO") | ||
counts = {"go" => 3} | ||
assert_equal counts, words.count | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'app/client' | ||
require 'app/api' | ||
|
||
class ExercismApp < Sinatra::Base | ||
set :root, 'lib/app' | ||
|
Oops, something went wrong.