Class: Three141
- Inherits:
-
Object
- Object
- Three141
- Defined in:
- lib/three141.rb
Constant Summary collapse
- VERSION =
'1.0.1'
Instance Method Summary collapse
-
#digits(id) ⇒ Object
It returns the first 10 pi digits (hex) starting from position = id.
-
#initialize ⇒ Three141
constructor
A new instance of Three141.
Constructor Details
#initialize ⇒ Three141
Returns a new instance of Three141.
5 6 7 8 |
# File 'lib/three141.rb', line 5 def initialize @tp = Array.new @tp1 = 0 end |
Instance Method Details
#digits(id) ⇒ Object
It returns the first 10 pi digits (hex) starting from position = id
eg: Three141.new.digits(2)
=> ["3", "F", "6", "A", "8", "8", "8", "5", "A", "3", "0", "8", "E", "0", "0", "0"]
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/three141.rb', line 16 def digits(id) s1 = series(1, id).to_f; s2 = series(4, id).to_f; s3 = series(5, id).to_f; s4 = series(6, id).to_f; pid = (4.0 * s1 - 2.0 * s2 - s3 - s4).to_f; pid = pid - pid.to_i; if (pid < 0.0) pid = pid + 1.0; end chx = ihex(pid, 16); return chx[0..10] end |