euler-manager 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e9f7edbc9e03e21533e53f4670a3f0378e0a9b0
4
- data.tar.gz: 78681dcecae1397d1b26616d9a319c60192685d3
3
+ metadata.gz: 5336f87fdb342e65419267358213b8b70f9b751d
4
+ data.tar.gz: 621f2862aaeb20504e3707585327f3fffe637fa4
5
5
  SHA512:
6
- metadata.gz: e18b00ed9af02b068bb515bf28337396e29bfce9e38ad6154bb035e5b7dff72490cde7a7ca293ed056651b346c53918ca8321b5e6e849c66e463182af1b71ff4
7
- data.tar.gz: 8b6a417585f284da8107ec3241d854b35e1369d6fbd6b24adec36db8f1eadb124b0d5d6a5f66558aa5d5443b041e8463aee54df1afca6fc9f420099b8bdcd621
6
+ metadata.gz: 5ea6fa3e120c4ff157adcf9d6f4d58ee3e8aa271060b4f2cc74cf5e5da2c2dafca3fe97ee5f28a818693bfa583d87e84ad461ed2c948ec1cfe45fc7a9e304ab7
7
+ data.tar.gz: ef1fdb96086f2f9770445af0594cb7a0b60147165743902f8da527a4a40a8e5e153a617217ae28c955f0c24e8d28d1815c26f61fdcd8ddf03d464b6aaa64fc81
data/README.md CHANGED
@@ -52,11 +52,13 @@ solution for problem number 1 then you can just run `$ euelr run` from `1/ruby`
52
52
  ## Supported Programming Languages
53
53
 
54
54
  - coffeescript
55
+ - haskell
55
56
  - javascript
56
57
  - java
57
58
  - python
58
59
  - ruby
59
60
  - scala
61
+ - julia
60
62
 
61
63
  ## Configuring Euler Manager
62
64
 
data/bin/euler CHANGED
@@ -83,9 +83,15 @@ command :test_all do |c|
83
83
  print "All TESTS PASSED".bold.on_green
84
84
  puts " ".bold.on_green
85
85
  else
86
- print " ".bold.on_red
87
- print "THERE WERE #{failures.length} FAILURE#{failures.length != 1 ? 'S' : ''}".bold.on_red
88
- puts " ".bold.on_red
86
+ if failures.length == 1
87
+ print " ".bold.on_red
88
+ print "THERE WAS A FAILURE".bold.on_red
89
+ print " ".bold.on_red
90
+ else
91
+ print " ".bold.on_red
92
+ print "THERE WERE #{failures.length} FAILURES".bold.on_red
93
+ print " ".bold.on_red
94
+ end
89
95
  failures.each do |failure|
90
96
  puts
91
97
  puts "#{failure.problem.to_s} (#{failure.language})".bold
@@ -107,8 +113,12 @@ command :new do |c|
107
113
  problem_id = args.shift
108
114
  language = args.shift
109
115
 
110
- solution = Euler::Solution.new(problem_id, language)
111
- problem = solution.problem
116
+ begin
117
+ solution = Euler::Solution.new(problem_id, language)
118
+ problem = solution.problem
119
+ rescue
120
+
121
+ end
112
122
 
113
123
  solution.init
114
124
 
data/config/config.rb CHANGED
@@ -60,11 +60,13 @@ end
60
60
  [
61
61
 
62
62
  'coffeescript',
63
+ 'haskell',
63
64
  'java',
64
65
  'javascript',
65
66
  'python',
66
67
  'ruby',
67
- 'scala'
68
+ 'scala',
69
+ 'julia'
68
70
 
69
71
  ].each do |lang|
70
72
  require_relative "../languages/#{lang}"
@@ -0,0 +1,3 @@
1
+ import Euler
2
+
3
+ main = print 0
@@ -0,0 +1,20 @@
1
+ # [Highly divisible triangular number](http://projecteuler.net/problem=12)
2
+
3
+ The sequence of triangle numbers is generated by adding the natural numbers. So the 7<sup>th</sup> triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
4
+
5
+ 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
6
+
7
+ Let us list the factors of the first seven triangle numbers:
8
+
9
+ > ** 1** : 1
10
+ > ** 3** : 1,3
11
+ > ** 6** : 1,2,3,6
12
+ > **10** : 1,2,5,10
13
+ > **15** : 1,3,5,15
14
+ > **21** : 1,3,7,21
15
+ > **28** : 1,2,4,7,14,28
16
+
17
+ We can see that 28 is the first triangle number to have over five divisors.
18
+
19
+ What is the value of the first triangle number to have over five hundred divisors?
20
+
@@ -0,0 +1,3 @@
1
+ import Euler
2
+
3
+ main = print 0
data/example/Eulerfile.rb CHANGED
@@ -67,22 +67,30 @@ end
67
67
 
68
68
  Euler.register_language('python', Class.new do
69
69
 
70
- # The run method must return the result of running the solution.
70
+ # Run the solution
71
71
  def run solution
72
- `python #{solution.dir}/#{solution.problem_id}.py`
72
+ `python #{file_path(solution)}`
73
73
  end
74
74
 
75
- # The init method is used to do any extra initialization for a solution. This
76
- # method is not required
77
- #
78
- # This example symlinks lib/euler.py into the solution's directory and then
79
- # writes a base file into the directory.
75
+ # Copy the template into the solution's directory
80
76
  def init solution
81
- FileUtils.symlink("#{Euler.root}/lib/euler.py", "#{solution.dir}/euler.py")
77
+ rel_euler_root = solution.dir.gsub(Euler.root, '').gsub(/\/[^\/]+/, '/..').sub(/^\//, '')
78
+ old_dir = Dir.pwd
82
79
 
83
- File.open("#{solution.dir}/#{solution.problem_id}.py", 'w') do |f|
84
- f.write("import euler\n\nanswer = 0\n\nprint(answer)\n")
85
- end
80
+ Dir.chdir solution.dir
81
+
82
+ FileUtils.symlink("#{rel_euler_root}/lib/euler.py", "#{solution.dir}/euler.py")
83
+
84
+ Dir.chdir old_dir
85
+
86
+ FileUtils.touch(file_path(solution))
86
87
  end
87
88
 
89
+ private
90
+
91
+ def file_path solution
92
+ "#{solution.dir}/#{solution.problem.id}.py"
93
+ end
94
+
88
95
  end)
96
+
@@ -0,0 +1 @@
1
+ module Euler where
@@ -0,0 +1,25 @@
1
+ Euler.register_language('haskell', Class.new do
2
+
3
+ # Run the solution
4
+ def run solution
5
+ `runhaskell -i#{Euler.root}/lib #{file_path(solution)}`
6
+ end
7
+
8
+ # Copy the template into the solution's directory
9
+ def init solution
10
+ FileUtils.cp(template_path, file_path(solution))
11
+ end
12
+
13
+ private
14
+
15
+ # Returns the path to the solution
16
+ def file_path solution
17
+ "#{solution.dir}/#{solution.problem.id}.hs"
18
+ end
19
+
20
+ # Returns the path to the template
21
+ def template_path
22
+ "#{File.dirname(__FILE__)}/../templates/haskell.hs"
23
+ end
24
+
25
+ end)
@@ -0,0 +1,21 @@
1
+ Euler.register_language('julia', Class.new do
2
+ #Run the solution
3
+ def run(solution)
4
+ `julia #{file_path(solution)}`
5
+ end
6
+
7
+ #Copy the template into the solution's directory
8
+ def init(solution)
9
+ FileUtils.symlink("#{Euler.root}/lib/euler.jl", "#{solution.dir}/euler.jl")
10
+ end
11
+
12
+ private
13
+ #Returns the path of the solution
14
+ def file_path(solution)
15
+ "#{solution.dir}/#{solution.problem.id}.jl"
16
+ end
17
+
18
+ def template_path
19
+ "#{File.dirname(__FILE__)}/../templates/julia.jl"
20
+ end
21
+ end)
data/languages/python.rb CHANGED
@@ -7,7 +7,14 @@ Euler.register_language('python', Class.new do
7
7
 
8
8
  # Copy the template into the solution's directory
9
9
  def init solution
10
- FileUtils.symlink("#{Euler.root}/lib/euler.py", "#{solution.dir}/euler.py")
10
+ rel_euler_root = solution.dir.gsub(Euler.root, '').gsub(/\/[^\/]+/, '/..').sub(/^\//, '')
11
+ old_dir = Dir.pwd
12
+
13
+ Dir.chdir solution.dir
14
+
15
+ FileUtils.symlink("#{rel_euler_root}/lib/euler.py", "#{solution.dir}/euler.py")
16
+
17
+ Dir.chdir old_dir
11
18
 
12
19
  FileUtils.cp(template_path, file_path(solution))
13
20
  end
data/lib/euler/problem.rb CHANGED
@@ -9,8 +9,12 @@ module Euler
9
9
  # Returns the problem with the given id.
10
10
  def self.find id
11
11
  problem_spec_file = "#{Euler.problems_dir}/#{id}.yml"
12
- problem_spec = YAML.load_file(problem_spec_file)
13
- Problem.new problem_spec
12
+ begin
13
+ problem_spec = YAML.load_file(problem_spec_file)
14
+ rescue
15
+ raise "No problem with id '#{id}' found"
16
+ end
17
+ Problem.new(problem_spec)
14
18
  end
15
19
 
16
20
  attr_reader :id, :name, :url
data/lib/euler/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Euler
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/spec/euler_spec.rb CHANGED
@@ -26,10 +26,11 @@ describe Euler do
26
26
 
27
27
  it "should have a few languages preregistered" do
28
28
  Euler.get_language('coffeescript').should be_truthy
29
+ Euler.get_language('haskell').should be_truthy
29
30
  Euler.get_language('java').should be_truthy
30
31
  Euler.get_language('javascript').should be_truthy
31
32
  Euler.get_language('python').should be_truthy
32
- Euler.get_language('coffeescript').should be_truthy
33
+ Euler.get_language('ruby').should be_truthy
33
34
  Euler.get_language('scala').should be_truthy
34
35
  end
35
36
 
@@ -0,0 +1,3 @@
1
+ import Euler
2
+
3
+ main = print 0
@@ -0,0 +1,4 @@
1
+
2
+ answer = 0
3
+
4
+ println(answer)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: euler-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Yaworsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-08 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -753,8 +753,11 @@ files:
753
753
  - euler-manager.gemspec
754
754
  - euler-manager.sublime-project
755
755
  - example/1/README.md
756
+ - example/1/haskell/1.hs
756
757
  - example/1/ruby/1.rb
757
758
  - example/1/scala/1.scala
759
+ - example/12/README.md
760
+ - example/12/haskell/12.hs
758
761
  - example/15/README.md
759
762
  - example/15/python/15.py
760
763
  - example/15/python/euler.py
@@ -763,12 +766,15 @@ files:
763
766
  - example/2/python/euler.py
764
767
  - example/Eulerfile.rb
765
768
  - example/README.md
769
+ - example/lib/Euler.hs
766
770
  - example/lib/euler.py
767
771
  - example/lib/euler.rb
768
772
  - example/lib/euler.scala
769
773
  - languages/coffeescript.rb
774
+ - languages/haskell.rb
770
775
  - languages/java.rb
771
776
  - languages/javascript.rb
777
+ - languages/julia.rb
772
778
  - languages/python.rb
773
779
  - languages/ruby.rb
774
780
  - languages/scala.rb
@@ -785,8 +791,10 @@ files:
785
791
  - spec/spec_helper.rb
786
792
  - templates/Eulerfile.rb
787
793
  - templates/coffeescript.coffee
794
+ - templates/haskell.hs
788
795
  - templates/java.java
789
796
  - templates/javascript.js
797
+ - templates/julia.jl
790
798
  - templates/python.py
791
799
  - templates/ruby.rb
792
800
  - templates/scala.scala
@@ -810,7 +818,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
810
818
  version: '0'
811
819
  requirements: []
812
820
  rubyforge_project:
813
- rubygems_version: 2.0.3
821
+ rubygems_version: 2.0.14
814
822
  signing_key:
815
823
  specification_version: 4
816
824
  summary: Manage and test project Euler problems from your command line.