quadratic 1.0
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.
- data/bin/quadratic +38 -0
- data/lib/quadratic.rb +38 -0
- metadata +64 -0
data/bin/quadratic
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "cmath"
|
4
|
+
|
5
|
+
if ARGV.empty?
|
6
|
+
puts "Usage: quadratic [nonzero number] [integer] [integer]\n"
|
7
|
+
puts "Example: quadratic 1 2 -15"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
# get variables
|
12
|
+
|
13
|
+
a = ARGV[0].to_f
|
14
|
+
b = ARGV[1].to_f
|
15
|
+
c = ARGV[2].to_f
|
16
|
+
|
17
|
+
# do the quadratic formula
|
18
|
+
|
19
|
+
d = CMath.sqrt(b**2 - (4 * a * c))
|
20
|
+
|
21
|
+
e = (-b + d) / (2 * a)
|
22
|
+
|
23
|
+
f = (-b - d) / (2 * a)
|
24
|
+
|
25
|
+
# result
|
26
|
+
|
27
|
+
if a == 0
|
28
|
+
puts "a must be nonzero."
|
29
|
+
puts "Usage: quadratic [nonzero number] [integer] [integer]\n"
|
30
|
+
puts "Example: quadratic 1 2 -15"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
if e != f
|
35
|
+
puts "The answers are #{e} and #{f}."
|
36
|
+
else
|
37
|
+
puts "The answer is #{e}."
|
38
|
+
end
|
data/lib/quadratic.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "cmath"
|
4
|
+
|
5
|
+
if ARGV.empty?
|
6
|
+
puts "Usage: quadratic [nonzero number] [integer] [integer]\n"
|
7
|
+
puts "Example: quadratic 1 2 -15"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
# get variables
|
12
|
+
|
13
|
+
a = ARGV[0].to_f
|
14
|
+
b = ARGV[1].to_f
|
15
|
+
c = ARGV[2].to_f
|
16
|
+
|
17
|
+
# do the quadratic formula
|
18
|
+
|
19
|
+
d = CMath.sqrt(b**2 - (4 * a * c))
|
20
|
+
|
21
|
+
e = (-b + d) / (2 * a)
|
22
|
+
|
23
|
+
f = (-b - d) / (2 * a)
|
24
|
+
|
25
|
+
# result
|
26
|
+
|
27
|
+
if a == 0
|
28
|
+
puts "a must be nonzero."
|
29
|
+
puts "Usage: quadratic [nonzero number] [integer] [integer]\n"
|
30
|
+
puts "Example: quadratic 1 2 -15"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
if e != f
|
35
|
+
puts "The answers are #{e} and #{f}."
|
36
|
+
else
|
37
|
+
puts "The answer is #{e}."
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quadratic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Avery Magnotti
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2016-04-01 00:00:00 -04:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: Easily solve for x by using the quadratic formula.
|
21
|
+
email: averymagnotti@outlook.com
|
22
|
+
executables:
|
23
|
+
- quadratic
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files: []
|
27
|
+
|
28
|
+
files:
|
29
|
+
- lib/quadratic.rb
|
30
|
+
- bin/quadratic
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: https://github.com/citrusui/quadratic
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.7
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: The quadratic formula, made easy
|
63
|
+
test_files: []
|
64
|
+
|