zadt 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0c11ab2bf7da2e0f74cce5774efd9f9cb863e35
4
- data.tar.gz: a7c1eb72e05d0d7d6b55f296274d4c6c7cce011e
3
+ metadata.gz: 5422fde4c7568acba5ed3f8781201d95b27a96b7
4
+ data.tar.gz: 213d340850bbf767e01e6cce0cec8ffef7859e12
5
5
  SHA512:
6
- metadata.gz: 66c8828077da9414c71df8eac48dd92b6027f3687f472012f4231773fe678d58c105aa95d9661ff72d07c61eefed1a6f009ab81533afdc38d401cf1eb16b603f
7
- data.tar.gz: bef7aa8acee94683807112bac4a19eba9d5f9b8ff2735b46186ac2eed4979140d8ea807dca0eb83f185f52b022b5ef7bbeb1c09fe27c2d496f13d1dc0ad4835e
6
+ metadata.gz: a647ad6ae68fe4fda78de921b5092f5795312572958516ac66f25672d4c62373df9f8eb45c7f111e54d2784db8d4534f6f95f7f0de822042ecbab27afe368915
7
+ data.tar.gz: 2e0cc6c118d0d43ed677238fcd06b85a9e9fd6d30cb27de04405dc507e34d02185ee53379cc20c18029b517209e05580b58ecd88e9283948894ef09c4bf70bf7
data/0.1.1 ADDED
@@ -0,0 +1 @@
1
+ Successfully installed randoq-0.1.1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # zadt
2
2
 
3
- Zagorski ADT is a collection of data types that are not included in the standard Ruby library.
3
+ Zagorski ADT is a collection of abstract data types that are not included in the standard Ruby library.
4
4
 
5
5
  ## Installation
6
6
 
@@ -113,7 +113,6 @@ A FaceGraph has the following methods, in addition to its inheritance from Graph
113
113
 
114
114
  Geometric objects, contained within a universe.
115
115
 
116
-
117
116
  #### Universe
118
117
 
119
118
  An universe is a Euclidean coordinate system that can be any number of dimensions. When initialized, you can specify how many dimensions you want it, or you can leave it blank to have infinite dimensions. Once a dimension is set, all objects in it are limited to that many dimensions. A universe of infinite dimensions has no restrictions, and can hold objects of any number of dimensions.
@@ -122,31 +121,39 @@ Within the universe, you can create Points and Spheres (though the more proper t
122
121
 
123
122
  In addition, the universe has the class method Universe.distance(pointA, pointB), which will tell you the distance between any two points. This will work for points in any number of dimensions, so long as the two points are of the same.
124
123
 
125
- #### Sphere
124
+ #### HyperSphere
125
+
126
+ A HyperSphere is a set of points within a certain number of dimensions that are equidistant (equal distance) from a given point. The number of dimensions is defined by the number of coordinates in its center. For example, a two-dimensional sphere (called a Circle) has a center of (x,y).
126
127
 
127
- A Sphere is a set of points within a certain number of dimensions that are equidistant (equal distance) from a given point. The number of dimensions is defined by the number of coordinates in its center. For example, a two-dimensional sphere (called a Circle) has a center of (x,y). This leads to the more proper term of HyperSphere, though that is not used in syntax.
128
+ Upon creation, a HyperSphere is given a radius and a center (default is the 4-dimensional Unit Sphere, of radius 1 and center [0,0,0,0]). HyperSpheres are immutable.
128
129
 
129
- Upon creation, a sphere is given a radius and a center (default is the 3-dimensional Unit Sphere, of radius 1 and center [0,0,0]). Spheres are immutable, as of yet, and though the number of dimensions is limitless certain functionalities will only apply to a 3-dimensional sphere.
130
+ A HyperSphere has the following methods
131
+ * on?(point) will return if a point is on the HyperSphere.
132
+ * inside?(point) will return if a point is within the boundaries of the HyperSphere.
133
+ * outside?(point) will return if a point is outside the boundaries of the HyperSphere.
134
+ * how_far(point) will return how far a point is from the boundaries of the HyperSphere.
130
135
 
131
- A Sphere has the following methods
132
- * on_sphere?(point) will return if a point is on the sphere.
133
- * in_sphere?(point) will return if a point is within the boundaries of the sphere.
134
- * how_far_from_sphere(point) will return how far a point is from the boundaries of the sphere.
136
+ ##### Sphere
135
137
 
136
- The following methods are available exclusively for 3-dimensional spheres.
138
+ A Sphere is a sub-class of the HyperSphere that has 3 dimensions and the following additional methods.
137
139
  * volume, returns the volume of the sphere
138
140
  * surface_area, returns the surface area of the sphere
139
141
  * equation, returns a string of the standard equation of the sphere. For example, a sphere with Radius 2 and Center [0,1,-2] will return "x^2 + (y - 1)^2 + (z + 2)^2 = 4".
140
142
 
141
- ## Development
143
+ ##### Circle
142
144
 
143
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
145
+ A Circle is a sub-class of the HyperSphere that has 2 dimensions and the following additional methods.
146
+ * area, returns the area of the sphere
147
+ * circumference, returns the circumference of the sphere
148
+ * equation, returns a string of the standard equation of the sphere. For example, a sphere with Radius 2 and Center [0,1] will return "x^2 + (y - 1)^2 = 4".
149
+ <!-- ## Development
144
150
 
145
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org]("https://rubygems.org").
151
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
146
152
 
153
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org]("https://rubygems.org"). -->
147
154
  ## Contributing
148
155
 
149
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zadt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
156
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mrmicrowaveoven/zadt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
150
157
 
151
158
 
152
159
  ## License
@@ -155,4 +162,4 @@ The gem is available as open source under the terms of the [MIT License](http://
155
162
 
156
163
  ## Contact
157
164
 
158
- This gem was written in its entirety by Benjamin Zagorski, who can be contacted at Benj@Zagorski.com. Feel free to contact me with any questions or comments, as I'm very open to suggestions.
165
+ This gem was written in its entirety by Benjamin Zagorski, who can be contacted at Benj@Zagorski.com. My portfolio can be found at [BenjZagorski.online](http://benjzagorski.online). Feel free to contact me with any questions or comments, as I'm very open to suggestions.
@@ -0,0 +1,63 @@
1
+ require_relative "hypersphere.rb"
2
+
3
+ class Circle < HyperSphere
4
+
5
+ def initialize(radius = 1, center = [0,0], pct_error = 1)
6
+ super(radius, center, pct_error)
7
+ end
8
+
9
+ def help
10
+ Circle.help
11
+ end
12
+
13
+ def self.help
14
+ Circle.show_help_message
15
+ end
16
+
17
+ def area
18
+ dim_check(2)
19
+ Math::PI * (@radius ** 2)
20
+ end
21
+
22
+ def circumference
23
+ dim_check(2)
24
+ 2 * Math::PI * @radius
25
+ end
26
+
27
+ def inspect
28
+ "Circle: #{equation}"
29
+ end
30
+
31
+ private
32
+
33
+ def self.show_help_message
34
+ super
35
+ Zadt::ADT::show_circle_help_message
36
+ end
37
+
38
+ def circle_equation
39
+ dim_check(2)
40
+ center_point = @center.dup
41
+ coord_names = ["x", "y"]
42
+ center_point.coords.each_with_index do |center_coord, index|
43
+ if center_coord == 0
44
+ # coord_name is fine
45
+ elsif center_coord < 0
46
+ coord_names[index] = "(#{coord_names[index]} + #{-center_coord})"
47
+ else
48
+ coord_names[index] = "(#{coord_names[index]} - #{center_coord})"
49
+ end
50
+ end
51
+ "#{coord_names[0]}^2 + #{coord_names[1]}^2 = #{@radius ** 2}"
52
+ end
53
+
54
+ def close_enough(guess, exact)
55
+ range = Array.new
56
+ range[0] = exact *(100.0 - @pct_error)/100.0
57
+ range[1] = exact * (100.0 + @pct_error)/100.0
58
+ guess.between?(range[0], range[1])
59
+ end
60
+
61
+
62
+
63
+ end
@@ -0,0 +1,72 @@
1
+ require_relative 'point.rb'
2
+
3
+ class HyperSphere
4
+ attr_reader :radius, :center
5
+ attr_accessor :pct_error
6
+
7
+ def initialize(radius = 1, center = [0,0,0,0], pct_error = 1)
8
+ @radius = radius
9
+ @center = Point.new(center)
10
+ @pct_error = pct_error
11
+ end
12
+
13
+ def self.help
14
+ Sphere.show_help_message
15
+ end
16
+
17
+ def help
18
+ Sphere.help
19
+ end
20
+
21
+ def on?(point)
22
+ Zadt::Universe.distance(@center, point).round(2) == radius.round(2)
23
+ end
24
+
25
+ def inside?(point)
26
+ Zadt::Universe.distance(@center, point) <= @radius
27
+ end
28
+
29
+ def outside?(point)
30
+ !inside?(point)
31
+ end
32
+
33
+ def how_far(point)
34
+ (@radius - Zadt::Universe.distance(@center, point)).abs
35
+ end
36
+
37
+ def equation
38
+ dims = @center.dims
39
+ return circle_equation if dims == 2
40
+ center_point = @center.dup
41
+ # Only get the variables used in that dimension
42
+ coord_names = ("a".."z").to_a.slice(-dims, dims)
43
+ center_point.coords.each_with_index do |center_coord, index|
44
+ if center_coord == 0
45
+ # coord_name is fine
46
+ elsif center_coord < 0
47
+ coord_names[index] = "(#{coord_names[index]} + #{-center_coord})"
48
+ else
49
+ coord_names[index] = "(#{coord_names[index]} - #{center_coord})"
50
+ end
51
+ end
52
+ final_string = ""
53
+ (dims - 1).times do |index|
54
+ final_string += "#{coord_names[index]}^2 + "
55
+ end
56
+ final_string += "#{coord_names[dims - 1]}^2"
57
+ final_string += " = "
58
+ final_string += "#{@radius ** 2}"
59
+ final_string
60
+ end
61
+
62
+ private
63
+
64
+ def dim_check(num)
65
+ raise "dimension error" unless num == @center.dims
66
+ end
67
+
68
+ def self.show_help_message
69
+ Zadt::ADT::show_hypersphere_help_message
70
+ end
71
+
72
+ end
@@ -1,34 +1,9 @@
1
- require_relative 'point.rb'
1
+ require_relative "hypersphere.rb"
2
2
 
3
- class Sphere
4
-
5
- attr_reader :radius, :center
6
- attr_accessor :pct_error
3
+ class Sphere < HyperSphere
7
4
 
8
5
  def initialize(radius = 1, center = [0,0,0], pct_error = 1)
9
- @radius = radius
10
- @center = Point.new(center)
11
- @pct_error = pct_error
12
- end
13
-
14
- def self.help
15
- Sphere.show_help_message
16
- end
17
-
18
- def help
19
- Sphere.help
20
- end
21
-
22
- def on_sphere?(point)
23
- Zadt::Universe.distance(@center, point).round(2) == radius.round(2)
24
- end
25
-
26
- def in_sphere?(point)
27
- Zadt::Universe.distance(@center, point) <= @radius
28
- end
29
-
30
- def how_far_from_sphere(point)
31
- (@radius - Zadt::Universe.distance(@center, point)).abs
6
+ super(radius, center, pct_error)
32
7
  end
33
8
 
34
9
  def volume
@@ -41,22 +16,6 @@ class Sphere
41
16
  4.0 * Math::PI * (@radius ** 2)
42
17
  end
43
18
 
44
- def equation
45
- dim_check(3)
46
- center_point = @center.dup
47
- coord_names = ["x", "y", "z"]
48
- center_point.coords.each_with_index do |center_coord, index|
49
- if center_coord == 0
50
- # coord_name is fine
51
- elsif center_coord < 0
52
- coord_names[index] = "(#{coord_names[index]} + #{-center_coord})"
53
- else
54
- coord_names[index] = "(#{coord_names[index]} - #{center_coord})"
55
- end
56
- end
57
- "#{coord_names[0]}^2 + #{coord_names[1]}^2 + #{coord_names[2]}^2 = #{@radius ** 2}"
58
- end
59
-
60
19
  def inspect
61
20
  "Sphere: #{equation}"
62
21
  end
@@ -64,6 +23,7 @@ class Sphere
64
23
  private
65
24
 
66
25
  def self.show_help_message
26
+ super
67
27
  Zadt::ADT::show_sphere_help_message
68
28
  end
69
29
 
@@ -74,8 +34,4 @@ class Sphere
74
34
  guess.between?(range[0], range[1])
75
35
  end
76
36
 
77
- def dim_check(num)
78
- raise "dimension error" unless num == @center.dims
79
- end
80
-
81
37
  end
@@ -1,4 +1,5 @@
1
1
  require_relative 'point.rb'
2
+ require_relative 'circle.rb'
2
3
  require_relative 'sphere.rb'
3
4
 
4
5
  module Zadt
@@ -0,0 +1,9 @@
1
+ module Zadt
2
+ class SinglyLinkedListNode
3
+ attr_accessor :val, :next
4
+ def initialize(val = nil, next_ = nil)
5
+ @val = val
6
+ @next = next_
7
+ end
8
+ end
9
+ end
@@ -7,15 +7,26 @@ module Zadt
7
7
  puts "#self.distance(pointA, pointB)"
8
8
  end
9
9
 
10
+ def self.show_hypersphere_help_message
11
+ puts "Here are the methods for HyperSphere:"
12
+ puts "#on?(point)"
13
+ puts "#inside?(point)"
14
+ puts "#outside?(point)"
15
+ puts "#how_far(point)"
16
+ end
17
+
10
18
  def self.show_sphere_help_message
11
- puts "Here are the methods for Sphere:"
12
- puts "#on_sphere(point)"
13
- puts "#in_sphere(point)"
14
- puts "#how_far_from_sphere(point)"
15
- puts "The following methods are also included in a 3-dimensional sphere:"
19
+ puts "The following methods are specific to a 3-dimensional Sphere:"
16
20
  puts "#volume"
17
21
  puts "#surface_area"
18
22
  puts "#equation, which returns a string in the form of (x-a)^2 + (y-b)^2 + (z-c)^2 = r^2"
19
23
  end
24
+
25
+ def self.show_circle_help_message
26
+ puts "The following methods are specific to a Circle (2-dimensions):"
27
+ puts "#area"
28
+ puts "#circumference"
29
+ puts "#equation, which returns a string in the form of (x-a)^2 + (y-b)^2 = r^2"
30
+ end
20
31
  end
21
32
  end
@@ -1,3 +1,3 @@
1
1
  module Zadt
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zadt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Zagorski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-10 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,6 +69,7 @@ files:
69
69
  - ".gitignore"
70
70
  - ".rspec"
71
71
  - ".travis.yml"
72
+ - 0.1.1
72
73
  - CODE_OF_CONDUCT.md
73
74
  - Gemfile
74
75
  - LICENSE.txt
@@ -79,6 +80,8 @@ files:
79
80
  - lib/ADT_requireables.rb
80
81
  - lib/helper_functions.rb
81
82
  - lib/zadt.rb
83
+ - lib/zadt/AbstractDataTypes/Geometrics/circle.rb
84
+ - lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb
82
85
  - lib/zadt/AbstractDataTypes/Geometrics/point.rb
83
86
  - lib/zadt/AbstractDataTypes/Geometrics/sphere.rb
84
87
  - lib/zadt/AbstractDataTypes/Geometrics/universe.rb
@@ -88,6 +91,7 @@ files:
88
91
  - lib/zadt/AbstractDataTypes/Graph/face_graph.rb
89
92
  - lib/zadt/AbstractDataTypes/Graph/graph.rb
90
93
  - lib/zadt/AbstractDataTypes/Graph/vertex.rb
94
+ - lib/zadt/AbstractDataTypes/LinkedList/SinglyLinkedList.rb
91
95
  - lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb
92
96
  - lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb
93
97
  - lib/zadt/AbstractDataTypes/StackQueue/Queue.rb