Rubeuler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ Rubeuler
2
+ ========
3
+
4
+ For Rubyists who enjoy solving and optimizing [Project Euler](http://www.projecteuler.net) problems. It uses `Benchmark` so be sure to use this with Ruby >= 1.9.3
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Rubeuler is a Ruby gem, and can be installed using `gem install rubeuler`
10
+
11
+ Usage
12
+ -----
13
+
14
+ The Rubeuler::Problem class should be initialized with two arguments, `:number` & `:answer` (problem designator and some ruby code as a string).
15
+ If the answer to problem one is 42, the code below should produce a successful response
16
+
17
+ ```ruby
18
+ Rubeuler::Problem.new(number: 1, answer: "7*3*2").execute!
19
+ ```
20
+ ### Pull requests/issues
21
+
22
+ Please submit any useful pull requests through GitHub. I expect bugs, please report them with the issue tracker! Thanks.
@@ -0,0 +1,11 @@
1
+ module Rubeuler
2
+ class Base
3
+ def load_option(option, options)
4
+ instance_variable_set("@#{option}", options.fetch(option.to_sym) { raise "Missing required option: #{option}" } )
5
+ end
6
+
7
+ def load_options(*option_names, options)
8
+ option_names.each{|o| load_option(o, options) }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require 'benchmark'
2
+
3
+ module Rubeuler
4
+ class Problem < ::Rubeuler::Base
5
+ def initialize(options)
6
+ load_options(:number, :answer, options)
7
+ end
8
+
9
+ def execute!
10
+ time = Benchmark.measure { @data = answer }.real
11
+ true_or_false = @data == solutions[@number.to_s] ? true : false
12
+
13
+ return Rubeuler::Result.new(success: true_or_false, problem: @number, data: @data, runtime: time)
14
+ end
15
+
16
+ private
17
+ def answer
18
+ instance_eval(@answer.gsub("\n",";"))
19
+ end
20
+
21
+ def solutions
22
+ {
23
+ "1" => 0,
24
+ "2" => 0,
25
+ "3" => 0,
26
+ "4" => 0,
27
+ "5" => 0,
28
+ "6" => 0,
29
+ "7" => 0
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module Rubeuler
2
+ class Result
3
+ def initialize(options)
4
+ @success = options[:success]
5
+ @data = options[:data]
6
+ @runtime = options[:runtime]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Rubeuler
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rubeuler.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "rubeuler/base"
2
+ require "rubeuler/problem"
3
+ require "rubeuler/result"
4
+ require "rubeuler/version"
data/rubeuler.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rubeuler/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "Rubeuler"
7
+ s.version = Rubeuler::VERSION
8
+ s.authors = ["Tad Hosford"]
9
+ s.email = ["tad.hosford@gmail.com"]
10
+ s.homepage = "http://github.com/rthbound/rubeuler"
11
+ s.description = %q{ For Rubyists who love ProjectEuler.net }
12
+ s.summary = %q{Evaluates whether a block produces a predefined response. Returns diagnostics if the block's return value was expected.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_development_dependency "minitest"
20
+ s.add_development_dependency "mocha"
21
+ s.add_development_dependency "turn"
22
+
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "pry"
25
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Rubeuler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tad Hosford
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mocha
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: turn
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: ! ' For Rubyists who love ProjectEuler.net '
95
+ email:
96
+ - tad.hosford@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - Gemfile
102
+ - README.md
103
+ - lib/rubeuler.rb
104
+ - lib/rubeuler/base.rb
105
+ - lib/rubeuler/problem.rb
106
+ - lib/rubeuler/result.rb
107
+ - lib/rubeuler/version.rb
108
+ - rubeuler.gemspec
109
+ homepage: http://github.com/rthbound/rubeuler
110
+ licenses: []
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 1.8.21
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Evaluates whether a block produces a predefined response. Returns diagnostics
133
+ if the block's return value was expected.
134
+ test_files: []