Skip to content

Commit 22e80bf

Browse files
committed
Trying out exercism. Seems pretty neat.
0 parents  commit 22e80bf

File tree

29 files changed

+1397
-0
lines changed

29 files changed

+1397
-0
lines changed

clojure/bob/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Bob
2+
3+
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
4+
5+
Bob answers 'Sure.' if you ask him a question.
6+
7+
He answers 'Woah, chill out!' if you yell at him.
8+
9+
He says 'Fine. Be that way!' if you address him without actually saying anything.
10+
11+
He answers 'Whatever.' to anything else.
12+
13+
## Instructions
14+
15+
Run the test file, and fix each of the errors in turn. When you get the first test to pass, go to the first pending or skipped test, and make that pass as well. When all of the tests are passing, feel free to submit.
16+
17+
Remember that passing code is just the first step. The goal is to work towards a solution that is as readable and expressive as you can make it.
18+
19+
Have fun!
20+
21+
22+
23+
## Source
24+
25+
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [view source](http://pine.fm/LearnToProgram/?Chapter=06)

clojure/bob/bob_test.clj

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(ns bob.test (:require [clojure.test :refer :all]))
2+
(load-file "bob.clj")
3+
4+
(deftest responds-to-something
5+
(is (= "Whatever." (bob/response-for "Tom-ay-to, tom-aaaah-to."))))
6+
7+
(deftest responds-to-shouts
8+
(is (= "Woah, chill out!" (bob/response-for "WATCH OUT!"))))
9+
10+
(deftest responds-to-questions
11+
(is (= "Sure." (bob/response-for "Does this cryogenic chamber make me look fat?"))))
12+
13+
(deftest responds-to-forceful-talking
14+
(is (= "Whatever." (bob/response-for "Let's go make out behind the gym!"))))
15+
16+
(deftest responds-to-acronyms
17+
(is (= "Whatever." (bob/response-for "It's OK if you don't want to go to the DMV."))))
18+
19+
(deftest responds-to-forceful-questions
20+
(is (= "Woah, chill out!" (bob/response-for "WHAT THE HELL WERE YOU THINKING?"))))
21+
22+
(deftest responds-to-shouting-with-special-characters
23+
(is (= "Woah, chill out!" (bob/response-for "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"))))
24+
25+
(deftest responds-to-shouting-numbers
26+
(is (= "Woah, chill out!" (bob/response-for "1, 2, 3 GO!"))))
27+
28+
(deftest responds-to-shouting-with-no-exclamation-mark
29+
(is (= "Woah, chill out!" (bob/response-for "I HATE YOU"))))
30+
31+
(deftest responds-to-statement-containing-question-mark
32+
(is (= "Whatever." (bob/response-for "Ending with ? means a question."))))
33+
34+
(deftest responds-to-silence
35+
(is (= "Fine. Be that way!" (bob/response-for ""))))
36+
37+
(deftest responds-to-prolonged-silence
38+
(is (= "Fine. Be that way!" (bob/response-for " "))))
39+
40+
(deftest responds-to-only-numbers
41+
(is (= "Whatever." (bob/response-for "1, 2, 3"))))
42+
43+
(deftest responds-to-number-question
44+
(is (= "Sure." (bob/response-for "4?"))))
45+
46+
(run-tests)

coffeescript/bob/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Bob
2+
3+
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
4+
5+
Bob answers 'Sure.' if you ask him a question.
6+
7+
He answers 'Woah, chill out!' if you yell at him.
8+
9+
He says 'Fine. Be that way!' if you address him without actually saying anything.
10+
11+
He answers 'Whatever.' to anything else.
12+
13+
## Instructions
14+
15+
Run the test file, and fix each of the errors in turn. When you get the first test to pass, go to the first pending or skipped test, and make that pass as well. When all of the tests are passing, feel free to submit.
16+
17+
Remember that passing code is just the first step. The goal is to work towards a solution that is as readable and expressive as you can make it.
18+
19+
Have fun!
20+
21+
22+
23+
## Source
24+
25+
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [view source](http://pine.fm/LearnToProgram/?Chapter=06)

coffeescript/bob/bob_test.spec.coffee

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Bob = require "./bob"
2+
describe "Bob", ->
3+
bob = new Bob()
4+
it "stating something", ->
5+
result = bob.hey "Tom-ay-to, tom-aaaah-to."
6+
expect(result).toEqual "Whatever."
7+
8+
xit "shouting", ->
9+
result = bob.hey "WATCH OUT!"
10+
expect(result).toEqual "Woah, chill out!"
11+
12+
xit "asking a question", ->
13+
result = bob.hey "Does this cryogenic chamber make me look fat?"
14+
expect(result).toEqual "Sure."
15+
16+
xit "talking forcefully", ->
17+
result = bob.hey "Let's go make out behind the gym!"
18+
expect(result).toEqual "Whatever."
19+
20+
xit "using acronyms in regular speech", ->
21+
result = bob.hey "It's OK if you don't want to go to the DMV."
22+
expect(result).toEqual "Whatever."
23+
24+
xit "forceful questions", ->
25+
result = bob.hey "WHAT THE HELL WERE YOU THINKING?"
26+
expect(result).toEqual "Woah, chill out!"
27+
28+
xit "shouting numbers", ->
29+
result = bob.hey "1, 2, 3 GO!"
30+
expect(result).toEqual "Woah, chill out!"
31+
32+
xit "shouting with special characters", ->
33+
result = bob.hey "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
34+
expect(result).toEqual "Woah, chill out!"
35+
36+
xit "shouting with no exclamation mark", ->
37+
result = bob.hey "I HATE YOU"
38+
expect(result).toEqual "Woah, chill out!"
39+
40+
xit "statement containing question mark", ->
41+
result = bob.hey "Ending with a ? means a question."
42+
expect(result).toEqual "Whatever."
43+
44+
xit "prattling on", ->
45+
result = bob.hey "Wait! Hang on. Are you going to be OK?"
46+
expect(result).toEqual "Sure."
47+
48+
xit "silence", ->
49+
result = bob.hey ""
50+
expect(result).toEqual "Fine. Be that way!"
51+
52+
xit "prolonged silence", ->
53+
result = bob.hey " "
54+
expect(result).toEqual "Fine. Be that way!"

elixir/bob/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Bob
2+
3+
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
4+
5+
Bob answers 'Sure.' if you ask him a question.
6+
7+
He answers 'Woah, chill out!' if you yell at him.
8+
9+
He says 'Fine. Be that way!' if you address him without actually saying anything.
10+
11+
He answers 'Whatever.' to anything else.
12+
13+
## Instructions
14+
15+
Run the test file, and fix each of the errors in turn. When you get the first test to pass, go to the first pending or skipped test, and make that pass as well. When all of the tests are passing, feel free to submit.
16+
17+
Remember that passing code is just the first step. The goal is to work towards a solution that is as readable and expressive as you can make it.
18+
19+
Have fun!
20+
21+
22+
23+
## Source
24+
25+
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [view source](http://pine.fm/LearnToProgram/?Chapter=06)

elixir/bob/bob.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Teenager do
2+
def hey(input) do
3+
cond do
4+
5+
end
6+
end
7+
end

elixir/bob/bob_test.exs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
if System.get_env("EXERCISM_TEST_EXAMPLES") do
2+
Code.load_file("example.exs")
3+
else
4+
Code.load_file("bob.exs")
5+
end
6+
7+
ExUnit.start
8+
9+
defmodule TeenagerTest do
10+
use ExUnit.Case, async: true
11+
doctest Teenager
12+
13+
test "stating something" do
14+
assert Teenager.hey("Tom-ay-to, tom-aaaah-to.") == "Whatever."
15+
end
16+
17+
test "shouting" do
18+
# assert Teenager.hey("WATCH OUT!") == "Woah, chill out!"
19+
end
20+
21+
test "asking a question" do
22+
# assert Teenager.hey("Does this cryogenic chamber make me look fat?") == "Sure."
23+
end
24+
25+
test "talking forcefully" do
26+
# assert Teenager.hey("Let's go make out behind the gym!") == "Whatever."
27+
end
28+
29+
test "shouting numbers" do
30+
# assert Teenager.hey("1, 2, 3 GO!") == "Woah, chill out!"
31+
end
32+
33+
test "shouting with special characters" do
34+
# assert Teenager.hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!") == "Woah, chill out!"
35+
end
36+
37+
test "shouting with no exclamation mark" do
38+
# assert Teenager.hey("I HATE YOU") == "Woah, chill out!"
39+
end
40+
41+
test "statement containing question mark" do
42+
# assert Teenager.hey("Ending with ? means a question.") == "Whatever."
43+
end
44+
45+
test "silence" do
46+
# assert Teenager.hey("") == "Fine. Be that way!"
47+
end
48+
49+
test "prolonged silence" do
50+
# assert Teenager.hey(" ") == "Fine. Be that way!"
51+
end
52+
53+
test "only numbers" do
54+
# assert Teenager.hey("1, 2, 3") == "Whatever."
55+
end
56+
57+
test "question with numbers" do
58+
# assert Teenager.hey("4?") == "Sure."
59+
end
60+
61+
test "shouting in Russian" do
62+
# Hopefully this is Russian for "get out"
63+
# assert Teenager.hey("УХОДИТЬ") == "Woah, chill out!"
64+
end
65+
end

go/leap/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Leap
2+
3+
Write a program that will take a year and report if it is a leap year.
4+
5+
The tricky thing here is that a leap year occurs:
6+
7+
```plain
8+
on every year that is evenly divisible by 4
9+
except every year that is evenly divisible by 100
10+
unless the year is also evenly divisible by 400
11+
```
12+
13+
For example, 1997 is not a leap year, but 1996 is.
14+
1900 is not a leap year, but 2000 is.
15+
16+
If your language provides a method in the standard library that does this
17+
look-up, pretend it doesn't exist and implement it yourself.
18+
19+
## Notes
20+
21+
For a delightful, four minute explanation of the whole leap year phenomenon, go watch [this youtube video](http://www.youtube.com/watch?v=xX96xng7sAE).
22+
23+
24+
## Source
25+
26+
JavaRanch Cattle Drive, exercise 3 [view source](http://www.javaranch.com/leap.jsp)

go/leap/leap_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package leap
2+
3+
import (
4+
"testing"
5+
)
6+
7+
var testCases = []struct {
8+
year int
9+
expected bool
10+
description string
11+
}{
12+
{1996, true, "a vanilla leap year"},
13+
{1997, false, "a normal year"},
14+
{1900, false, "a century"},
15+
{2400, true, "an exceptional century"},
16+
}
17+
18+
func TestLeapYears(t *testing.T) {
19+
for _, test := range testCases {
20+
observed := IsLeapYear(test.year)
21+
if observed != test.expected {
22+
t.Fatalf("%v is %s", test.year, test.description)
23+
}
24+
}
25+
}

haskell/bob/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Bob
2+
3+
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
4+
5+
Bob answers 'Sure.' if you ask him a question.
6+
7+
He answers 'Woah, chill out!' if you yell at him.
8+
9+
He says 'Fine. Be that way!' if you address him without actually saying anything.
10+
11+
He answers 'Whatever.' to anything else.
12+
13+
## Instructions
14+
15+
Run the test file, and fix each of the errors in turn. When you get the first test to pass, go to the first pending or skipped test, and make that pass as well. When all of the tests are passing, feel free to submit.
16+
17+
Remember that passing code is just the first step. The goal is to work towards a solution that is as readable and expressive as you can make it.
18+
19+
Have fun!
20+
21+
22+
23+
## Source
24+
25+
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [view source](http://pine.fm/LearnToProgram/?Chapter=06)

0 commit comments

Comments
 (0)