job_interview 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/job_interview.rb +1 -0
- data/lib/job_interview/answer.rb +1 -0
- data/lib/job_interview/fibonacci.rb +10 -0
- data/lib/job_interview/fizz_buzz.rb +7 -15
- data/lib/job_interview/primes.rb +2 -9
- data/lib/job_interview/questions.rb +10 -2
- data/spec/fibonacci_spec.rb +4 -0
- data/spec/hello_world_spec.rb +16 -0
- data/spec/questions_spec.rb +32 -0
- metadata +22 -7
data/lib/job_interview.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.expand_path('../job_interview/fizz_buzz', __FILE__)
|
2
2
|
require File.expand_path('../job_interview/fibonacci', __FILE__)
|
3
|
+
require File.expand_path('../job_interview/hello_world', __FILE__)
|
3
4
|
require File.expand_path('../job_interview/knapsack' , __FILE__)
|
4
5
|
require File.expand_path('../job_interview/quine' , __FILE__)
|
5
6
|
require File.expand_path('../job_interview/primes' , __FILE__)
|
data/lib/job_interview/answer.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'matrix'
|
1
2
|
module JobInterview
|
2
3
|
module Fibonacci
|
3
4
|
|
@@ -8,6 +9,8 @@ module JobInterview
|
|
8
9
|
def fib(n, *args)
|
9
10
|
if args && args.include?(:iterative)
|
10
11
|
iterative_fib(n)
|
12
|
+
elsif args && args.include?(:matrix)
|
13
|
+
matrix_fib(n)
|
11
14
|
else
|
12
15
|
## TODO: make this efficient
|
13
16
|
return Array.new(n) {|i| recursive_fib(i + 1) }
|
@@ -31,6 +34,13 @@ module JobInterview
|
|
31
34
|
|
32
35
|
return result
|
33
36
|
end
|
37
|
+
|
38
|
+
def matrix_fib(n)
|
39
|
+
1.upto(n).map do |i|
|
40
|
+
fibonacci_matrix = Matrix[[1,1],[1,0]]
|
41
|
+
(fibonacci_matrix**(i-1)) [0,0]
|
42
|
+
end
|
43
|
+
end
|
34
44
|
|
35
45
|
end
|
36
46
|
end
|
@@ -1,21 +1,13 @@
|
|
1
1
|
module JobInterview
|
2
2
|
module FizzBuzz
|
3
|
-
|
3
|
+
|
4
4
|
def fizz_buzz(max)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
acc << "Fizz"
|
11
|
-
elsif (n % 5 == 0)
|
12
|
-
acc << "Buzz"
|
13
|
-
else
|
14
|
-
acc << n
|
15
|
-
end
|
5
|
+
Array.new(max) do |i|
|
6
|
+
j = i + 1
|
7
|
+
val = (j % 3 == 0 ? "Fizz" : "") +
|
8
|
+
(j % 5 == 0 ? "Buzz" : "")
|
9
|
+
val.empty? ? j.to_s : val
|
16
10
|
end
|
17
|
-
return acc
|
18
11
|
end
|
19
|
-
|
20
12
|
end
|
21
|
-
end
|
13
|
+
end
|
data/lib/job_interview/primes.rb
CHANGED
@@ -3,7 +3,7 @@ module JobInterview
|
|
3
3
|
module Questions
|
4
4
|
|
5
5
|
def in_5_years
|
6
|
-
"I'd like to " +
|
6
|
+
"I'd " + %W[like love hope].sample + " to " +
|
7
7
|
[
|
8
8
|
"have made",
|
9
9
|
"have enhanced shareholder value by creating",
|
@@ -37,7 +37,7 @@ module JobInterview
|
|
37
37
|
["Some times I", "I always"].sample + " " +
|
38
38
|
["try too hard", "work too much", "care too much", "fail so rarely"].sample + " " +
|
39
39
|
"so I " +
|
40
|
-
[ "make others jealous",
|
40
|
+
[ "make others jealous",
|
41
41
|
"make too much money",
|
42
42
|
"shift too many paradigms",
|
43
43
|
"innovate too hard"].sample + "."
|
@@ -61,6 +61,14 @@ module JobInterview
|
|
61
61
|
].sample + thing + "."
|
62
62
|
end
|
63
63
|
|
64
|
+
def what_interest
|
65
|
+
"I have a special interest in " +
|
66
|
+
["scalable ", "modular ", "distributed "].sample +
|
67
|
+
["mobile ", "social ", "global ", "local "].sample +
|
68
|
+
["business ", "consumer ", "startup ", "enterprise "].sample +
|
69
|
+
["applications.", "frameworks.", "platforms.", "services."].sample
|
70
|
+
end
|
71
|
+
|
64
72
|
def p_equals_np
|
65
73
|
[
|
66
74
|
"If it does, we can kiss encryption goodbye.",
|
data/spec/fibonacci_spec.rb
CHANGED
@@ -10,6 +10,10 @@ module FibonacciSpec
|
|
10
10
|
@answer.fib(10, :iterative).should == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
|
11
11
|
end
|
12
12
|
|
13
|
+
it "should return the fibinacci sequence in matrix mode" do
|
14
|
+
@answer.fib(10, :matrix).should == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
|
15
|
+
end
|
16
|
+
|
13
17
|
it "should return the fibinacci sequence in recursive mode" do
|
14
18
|
@answer.fib(10).should == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
|
15
19
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HelloWorldSpec
|
4
|
+
|
5
|
+
describe "When called" do
|
6
|
+
before(:each) do
|
7
|
+
@answer = JobInterview::Answer.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should print 'Hello, World!'" do
|
11
|
+
@answer.hello_world.should == "Hello, World!"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
module QuestionsSpec
|
3
|
+
include JobInterview::Questions
|
4
|
+
|
5
|
+
class Dummy
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "When called" do
|
9
|
+
before(:each) do
|
10
|
+
@dummy = Dummy.new
|
11
|
+
@dummy.extend(JobInterview::Questions)
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_correct_answer(type, answer)
|
15
|
+
if answer.respond_to? :wrong
|
16
|
+
return false
|
17
|
+
else
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
%W[in_5_years leaving_current manhole_cover greatest_weakness why_here p_equals_np what_interest].each do |m|
|
23
|
+
it "should return the right answer for #{m}" do
|
24
|
+
answer = @dummy.send(m)
|
25
|
+
is_correct_answer(m, answer).should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: job_interview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-05-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faker
|
17
|
-
requirement: &
|
17
|
+
requirement: &2160569960 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.9.5
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2160569960
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &2160569320 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,7 +33,18 @@ dependencies:
|
|
33
33
|
version: 2.9.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2160569320
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
requirement: &2160568840 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.9.2
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2160568840
|
37
48
|
description: Programmer job interview answers, packaged for your convenience. Fibonacci,
|
38
49
|
FizzBuzz, and more! A project from BohConf 2012.
|
39
50
|
email:
|
@@ -53,7 +64,9 @@ files:
|
|
53
64
|
- lib/job_interview/quine.rb
|
54
65
|
- spec/fibonacci_spec.rb
|
55
66
|
- spec/fizz_buzz_spec.rb
|
67
|
+
- spec/hello_world_spec.rb
|
56
68
|
- spec/primes_spec.rb
|
69
|
+
- spec/questions_spec.rb
|
57
70
|
- spec/quine_spec.rb
|
58
71
|
homepage: https://github.com/ruby-jokes/job_interview
|
59
72
|
licenses:
|
@@ -76,12 +89,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
89
|
version: '0'
|
77
90
|
requirements: []
|
78
91
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.8.
|
92
|
+
rubygems_version: 1.8.10
|
80
93
|
signing_key:
|
81
94
|
specification_version: 3
|
82
95
|
summary: Programmer job interview answers, packaged for your convenience
|
83
96
|
test_files:
|
84
97
|
- spec/fibonacci_spec.rb
|
85
98
|
- spec/fizz_buzz_spec.rb
|
99
|
+
- spec/hello_world_spec.rb
|
86
100
|
- spec/primes_spec.rb
|
101
|
+
- spec/questions_spec.rb
|
87
102
|
- spec/quine_spec.rb
|