main
1require "spec_helper"
2require 'prime'
3
4describe "problem seven" do
5 #By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
6 #What is the 10 001st prime number?
7
8 class Primes
9 include Enumerable
10
11 def [](index)
12 each_with_index do |n, current|
13 return n if current == (index - 1)
14 end
15 end
16
17 def each(&block)
18 prime.each(&block)
19 end
20
21 private
22
23 def prime
24 Prime
25 end
26 end
27
28 subject { Primes.new }
29
30 it "returns the first 6 primes" do
31 expect(subject.take(6)).to eql([2, 3, 5, 7, 11, 13])
32 end
33
34 it "returns 13" do
35 expect(subject[6]).to eql(13)
36 end
37
38 it "returns the 10_001 prime" do
39 expect(subject[10_001]).to eql(104743)
40 end
41end