RubMat 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", ">= 1.0.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "rcov", ">= 0"
14
+ gem "commander", "~> 4.1.0"
15
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Mahmut Bulut
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = rubmat
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to rubmat
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Mahmut Bulut. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile CHANGED
@@ -1,26 +1,55 @@
1
+ # encoding: utf-8
1
2
 
2
3
  require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
3
12
  require 'rake'
4
- require 'rake/clean'
5
- require 'rake/gempackagetask'
6
- require 'rake/rdoctask'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "RubMat"
18
+ gem.homepage = "http://github.com/regularlambda/RubMat"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Discrete Mathematics REPL and built-in usable library}
21
+ gem.description = %Q{Discrete Mathematics REPL and built-in usable library for experimental and experimental projects}
22
+ gem.email = "mahmutbulut0@gmail.com"
23
+ gem.authors = ["Mahmut Bulut"]
24
+ gem.add_dependency "commander", "~> 4.1.0"
25
+ gem.executables = ['rubmat']
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
7
30
  require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
8
36
 
9
- Rake::GemPackageTask.new(spec) do |p|
10
- p.gem_spec = spec
11
- p.need_tar = true
12
- p.need_zip = true
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ test.rcov_opts << '--exclude "gems/*"'
13
43
  end
14
44
 
15
- #Rake::RDocTask.new do |rdoc|
16
- # files =['README.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/*.yml']
17
- # rdoc.rdoc_files.add(files)
18
- # rdoc.main = "README" # page to start on
19
- # rdoc.title = "RubMat Docs"
20
- # rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
21
- # rdoc.options << '--line-numbers'
22
- #end
45
+ task :default => :test
46
+
47
+ require 'rdoc/task'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
23
50
 
24
- Rake::TestTask.new do |t|
25
- t.test_files = FileList['test/**/*.rb']
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "rubmat #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
55
  end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/bin/rubmat CHANGED
@@ -1,129 +1,5 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib', 'lib/rubmat')
3
+ require 'rubmat'
2
4
 
3
- require 'rubygems'
4
- require 'bundler/setup'
5
- Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file }
6
-
7
- # AUTHOR: Mahmut Bulut
8
- #$LOAD_PATH.unshift File.dirname(__FILE__)
9
- #require File.dirname(__FILE__) + '/lib/librbdiscrete.rb'
10
- #require File.expand_path(File.join(File.dirname(__FILE__)))
11
- #require 'librbdiscrete'
12
- #require 'fixnumexpand'
13
- #require 'commander'
14
- #require 'help'
15
-
16
- puts "===RubMat===
17
- Copyright (C) <2011> <Mahmut Bulut>
18
- This program comes with ABSOLUTELY NO WARRANTY; for details type 'help'.
19
- This is free software, and you are welcome to redistribute it
20
- under certain conditions; type `certain' for details."
21
- puts ""
22
- begin
23
- command = ask(">=> ")
24
- #command = commn.chomp!
25
- # Read arguments and defines commands
26
- # Will handle command line whitespaces
27
-
28
- if (command == 'help')
29
- puts help()
30
- end
31
- if (command == 'certain')
32
- puts "To see certain conditions please visit http://www.gnu.org/licenses/gpl-2.0.html#SEC3"
33
- end
34
- if (command == 'factorial')
35
- n = ask("Enter N value: ", Integer)
36
- puts factorial(n)
37
- end
38
- if (command == 'binsearch')
39
- begin
40
- binary = ask("Enter array name with [ & ] suffix: ")
41
- size = ask("Enter size of search range: ", Integer)
42
- search_key = ask("Enter search delimiter key", Integer)
43
- low = ask("Lower limit: ", Integer)
44
- middle = ask("Medium limit: ", Integer)
45
- high = ask("High limit: ", Integer)
46
- puts binary_search(binary, size, search_key, low, middle, high)
47
- rescue => error
48
- puts error
49
- end
50
- end
51
- if (command == 'birdseye')
52
- n = ask("Enter workspace mass number: ", Integer)
53
- k = ask("Enter selection mass number: ", Integer)
54
- puts birds_eye(n, k)
55
- end
56
- if (command == 'combinatorial')
57
- glb = ask("Enter global set objects number: ", Integer)
58
- ksb = ask("Enter k-subset objects number: ", Integer)
59
- puts combinatorial(glb, ksb)
60
- end
61
- if (command == 'distpres')
62
- presnum = ask("Present number: ", Integer)
63
- puts dist_pres(presnum)
64
- end
65
- if (command == 'eagleview')
66
- m = ask("Enter m value: ", Integer)
67
- t = ask("Enter t value: ", Integer)
68
- puts eagle_view(m, t)
69
- end
70
- if (command == 'fermatlittle')
71
- p = ans("Enter power number: ", Integer)
72
- a = ans("Enter base number:", Integer)
73
- puts fermat_little(p, a)
74
- end
75
- if (command == 'fib')
76
- n = ans("Enter the last incremental number: ", Integer)
77
- puts fib(n)
78
- end
79
- if (command == 'isprime')
80
- raise RuntimeError.new("Have some critical issues closed to next minor version")
81
- # nb = ask("Control number: ", Integer)
82
- # puts is_prime(nb)
83
- end
84
- if (command == 'iterativefact')
85
- begin
86
- itrtnum = ask("Enter the factorial input: ", Integer)
87
- throw :ball if (itrtnum >= MAX_INTEGER)
88
- puts iterative_fact(itrtnum)
89
- end
90
- catch(:ball) do
91
- raise ArgumentError.new("iterative factorial couldn't take this value's load. Terminated.")
92
- end
93
- end
94
- if (command == 'sigma')
95
- inta = ask("Enter a value: ", Integer)
96
- intx = ask("Enter x value: ", Integer)
97
- intb = ask("Enter b value: ", Integer)
98
- pw = ask("Enter power value: ", Integer)
99
- puts sigma(inta, intx, intb, pw)
100
- end
101
- if (command == 'stirling')
102
- begin
103
- strln = ask("Enter stirling procedure value: ", Integer)
104
- throw :glass if (strln >= MAX_INTEGER)
105
- puts stirling(strln)
106
- end
107
- catch(:glass) do
108
- raise ArgumentError.new("stirling couldn't take this value's load. Terminated.")
109
- end
110
- end
111
- if (command == 'subset')
112
- gen = ask("Enter mass objects number: ", Integer)
113
- zerosbst = agree("Include zero subset?")
114
- puts subset(gen, zerosbst)
115
- end
116
- if (command == 'fibsum')
117
- n = ask("Enter n value: ", Integer)
118
- puts sum_of_fib(n)
119
- end
120
- if (command == 'twinprdx')
121
- mass = ask("Enter mass number: ", Integer)
122
- puts twin_prdx(mass)
123
- end
124
- if (command == 'uipow')
125
- base = ask("Enter base value: ", Integer)
126
- exp = ask("Enter power value: ", Integer)
127
- puts ui_pow(base, exp)
128
- end
129
- end until(command == 'exit')
5
+ MathRub.run
@@ -1,13 +1,504 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- # AUTHOR: Mahmut Bulut
4
2
  require 'rubygems'
5
- require 'yaml'
6
- require 'librbdiscrete.rb'
7
- require 'fixnumexpand.rb'
8
3
  require 'commander'
9
- require 'help'
10
4
 
5
+ ##require 'rubmat/main'
6
+
7
+ module MathRub
8
+
9
+
10
+ ## HELP
11
+ def self.help
12
+ puts "
13
+ Valid Commands
14
+ ===============
15
+ help Show this manpage
16
+ certain Show certain conditions page
17
+ factorial Recursive definition of factorial
18
+ 'n' is the number which will calculated in procedure
19
+ binsearch *binary => array
20
+ *size => binary array's size
21
+ *search_key => Compare string
22
+ *General values
23
+ *low => low value representation
24
+ *middle => middle value representation
25
+ *high => high value representation
26
+ birdseye Bird's Eye View Procedure
27
+ combinatorial 'glb' represents is General mass of combinatorial approach
28
+ 'klb' represents is Selection mass of combinatorial approach
29
+ distpres 'presnum' value represents Present count.
30
+ eagleview Eagle View Procedure
31
+ fermatlittle Fermat Little Theorem's Procedural Representation
32
+ fib Additive recursive definition of Fibonacci
33
+ isprime Is Prime Procedure
34
+ 'nb' is the input argument number of procedure
35
+ iterativefact Iterative factorial of procedural representation
36
+ sigma Sigma procedure's simple procedure is rely on '(ax+b)^pw'
37
+ a represented by inta;
38
+ b represented by intb;
39
+ x represented by intx;
40
+ power represented by pw.
41
+ stirling 'strln' is the stirling number in stirling formula
42
+ subset 'zerosbst' variable, decision mechanism of zero subset is included or not included
43
+ 'gen' is the general mass elements(objects) number
44
+ fibsum Fibonacci Sum Procedure
45
+ twinprdx Twin Paradox Lemma Solution Procedure
46
+ Selection mass represented by 'mass' value
47
+ uipow Non-balanced power calculation procedure
48
+ "
49
+ end
50
+
51
+ EVALUE = 2.718281828459045235360287471352662497757247093
52
+ PIVALUE = 3.141592653589793238462643383279502884197169399
53
+ MAX_INTEGER = 1073741823
54
+
55
+ err = "An error occured during during procedure"
56
+
57
+ =begin
58
+ = NAME
59
+ Recursive Factorial Procedure Definition v1.1.3
60
+
61
+ = SYNOPSIS
62
+ factorial(n)
63
+ 'n' is the number which will calculated in procedure
64
+
65
+ = DESCRIPTION
66
+ Iterative factorial definition
67
+ =end
68
+ def self.factorial( n )
69
+ if (n <= 1)
70
+ return 1
71
+ else
72
+ return n*factorial( n-1 ).to_i
73
+ end
74
+ end
75
+
76
+ =begin
77
+ = NAME
78
+ Power procedure of two input arguments v2.1.3
79
+
80
+ = SYNOPSIS
81
+ ui_pow(base, exp)
82
+ 'base' argument is the base of power procedure
83
+ 'exp' argument is the upscript of power procedure
84
+
85
+ = DESCRIPTION
86
+ Wide representation of power procedure
87
+ =end
88
+ def self.ui_pow(base, exp)
89
+ result = 1;
90
+ while (exp)
91
+ if (exp & 1)
92
+ result *= base
93
+ end
94
+ exp >>= 1;
95
+ base *= base
96
+ end
97
+ if(exp==0)
98
+ result=base
99
+ end
100
+ return result
101
+ end
102
+
103
+ =begin
104
+ = NAME
105
+ Iterative Factorial Procedure v1.0.3
106
+
107
+ = SYNOPSIS
108
+ Get input arguments from simple argument
109
+
110
+ = DESCRIPTION
111
+ Iterative factorial of procedural representation
112
+ =end
113
+ def self.iterative_fact(itrtnum)
114
+ itrtnum.downto(1) do
115
+ total *= factorial(itrtnum)
116
+ end
117
+ return total
118
+ end
119
+
120
+ =begin
121
+ = NAME
122
+ Subset Procedure v1.1.3
123
+
124
+ = SYNOPSIS
125
+ subset(gen, zerosbst)
126
+ 'zerosbst' variable, decision mechanism of zero subset is included or not included
127
+ 'gen' is the general mass elements(objects) number
128
+
129
+ = DESCRIPTION
130
+ Calculate subset number of input arguments
131
+ =end
132
+ def self.subset(gen, zerosbst)
133
+ main = case (zerosbst)
134
+ when zerosbst == true
135
+ rslt = ui_pow(2, gen) - 1
136
+ return rslt
137
+ when zerosbst == false
138
+ rslt = ui_pow(2, gen)
139
+ return rslt
140
+ end
141
+ return main
142
+ end
143
+
144
+ #/*
145
+ #int subset(void){
146
+ # char zerosbst;
147
+ # float rslt=0;int gen=0;
148
+ # printf("Enter the mass elements number: ");
149
+ # scanf("%d", &gen);
150
+ # //Dönmeleri düzelt formatlamaları düzelt, cast ı düzelt
151
+ # //Elemanları binary string olarak döndür
152
+ # printf("Want to get subsets?(y/n)\n");
153
+ # zerosbst=getchar();
154
+ # switch (zerosbst){
155
+ #
156
+ # case 'y':
157
+ # rslt = ui_pow(2, gen) - 1;
158
+ # int rslt = rslt;
159
+ # printf("%d", rslt);
160
+ # break;
161
+ # case 'n':
162
+ # rslt = ui_pow(2, gen);
163
+ # //printf("%f", rslt);
164
+ # break;
165
+ # default:
166
+ # puts("Enter y or n char");
167
+ # break;
168
+ # }
169
+ # return EXIT_SUCCESS;
170
+ #}
171
+ #*/
172
+
173
+ ## Combinatorial problems solver
174
+ #
175
+ #
176
+
177
+ =begin
178
+ = NAME
179
+ Combinatorial Procedure v1.1.5
180
+
181
+ = SYNOPSIS
182
+ combinatorial(glb, ksb)
183
+ 'glb' represents is General mass of combinatorial approach
184
+ 'klb' represents is Selection mass of combinatorial approach
185
+
186
+ = DESCRIPTION
187
+ Combinatorial selection number of a input argument mass
188
+ =end
189
+ def self.combinatorial(glb, ksb)
190
+ if(glb < ksb)
191
+ raise RuntimeError.new("Global set cannot be greater than k-subsets")
192
+ end
193
+ sbst_given_size = factorial(glb)/(factorial(ksb)*factorial(glb-ksb)).to_f
194
+ return sbst_given_size
195
+ end
196
+
197
+ =begin
198
+ = NAME
199
+ Sigma Procedure v1.1.5
200
+
201
+ = SYNOPSIS
202
+ sigma(inta, intx, intb, pw)
203
+ Sigma procedure's simple procedure is rely on '(ax+b)^pw'
204
+ a represented by inta;
205
+ b represented by intb;
206
+ x represented by intx;
207
+ power represented by pw.
208
+
209
+ = DESCRIPTION
210
+ 'Sigma of the one unknowned equation' procedure
211
+ =end
212
+
213
+ def self.sigma(inta, intx, intb, pw)
214
+ ttl = 0
215
+ for i in 1..intx
216
+ ttl += (inta*intx+intb)
217
+ end
218
+ if(pw == 1)
219
+ return ttl
220
+ end
221
+ if(pw > 1)
222
+ ttl=ui_pow(ttl, pw)
223
+ return ttl
224
+ end
225
+ if(pw == 0)
226
+ return 1
227
+ end
228
+ end
229
+
230
+ =begin
231
+ = NAME
232
+ Stirling Procedure v1.1.5
233
+
234
+ = SYNOPSIS
235
+ stirling(strln)
236
+ 'strln' is the stirling number in stirling formula
237
+
238
+ = DESCRIPTION
239
+ Stirling Procedure for Stirling Lemma
240
+ =end
241
+ def self.stirling(strln)
242
+ return (strln/constants1.EVALUE**strln)*Math.sqrt(2*constants1.PIVALUE*strln);
243
+ end
244
+
245
+ =begin
246
+ = NAME
247
+ Twin Paradox Lemma Solver v1.1.5
248
+
249
+ = SYNOPSIS
250
+ twin_prdx(mass)
251
+ Selection mass represented by 'mass' value
252
+
253
+ = DESCRIPTION
254
+ Twin Paradox Lemma Solution Procedure
255
+ =end
256
+ def self.twin_prdx(mass)
257
+ top=1
258
+ for i in 366..366-mass
259
+ top *= i
260
+ end
261
+ return top/ui_pow(366, mass)
262
+ end
263
+
264
+ =begin
265
+ = NAME
266
+ Distrubuting Presents Procedure v1.1.3
267
+
268
+ = SYNOPSIS
269
+ dist_pres(presnum)
270
+ 'presnum' value represents Present count.
271
+
272
+ = DESCRIPTION
273
+ Use of Sequence of factorial and iterative_fact procedures for
274
+ distributing presents.
275
+ =end
276
+ def self.dist_pres(presnum)
277
+ return factorial(presnum)/iterative_fact(presnum);
278
+ end
279
+
280
+ =begin
281
+ = NAME
282
+ Recursive adding of procedure fibonacci
283
+
284
+ = SYNOPSIS
285
+ fib(n)
286
+ 'n' represents recursive definition
287
+
288
+ = DESCRIPTION
289
+ Additive recursive definition of Fibonacci
290
+ =end
291
+ def self.fib(n)
292
+ if (n <= 1)
293
+ return n;
294
+ else
295
+ return fib(n-1)+fib(n-2);
296
+ end
297
+ end
298
+
299
+ =begin
300
+ = NAME
301
+ Printing Row v1.5.5
302
+
303
+ = SYNOPSIS
304
+ print_row(binary, size, low, mid, high)
305
+ 'binary' represents binary array
306
+ 'size' represents general size
307
+ 'low' represents minimum value of binary array
308
+ 'mid' represents middle value of binary array
309
+ 'high' represents maximum value of binary array
310
+
311
+ = DESCRIPTION
312
+ Underly array for printing.
313
+ =end
314
+ def self.print_row(binary, size, low, mid, high)
315
+ for i in 0..size-1
316
+ if (i <low || i > high)
317
+ print " "
318
+ end
319
+ if(i == mid)
320
+ puts binary[i]
321
+ end
322
+ if(nil)
323
+ puts binary[i]
324
+ end
325
+ end
326
+ end
327
+
328
+ =begin
329
+ = NAME
330
+ Binary Search Spec. Procedure v1.5.9
331
+
332
+ = SYNOPSIS
333
+ binary_search(binary, size, search_key, low, middle, high)
334
+ == Binary search
335
+ *binary => array
336
+ *size => binary array's size
337
+ *search_key => Compare string
338
+ *General values
339
+ *low => low value representation
340
+ *middle => middle value representation
341
+ *high => high value representation
342
+
343
+ = DESCRIPTION
344
+ Binary search
345
+ =end
346
+ def self.binary_search(binary, size, search_key, low, middle, high)
347
+ while (low <= high)
348
+ middle=(low+high)/2;
349
+ print_row(binary, size, low, middle, high);
350
+ if (search_key == binary[middle])
351
+ return middle;
352
+ elsif (search_key <= binary[middle])
353
+ high=middle-1
354
+ else
355
+ low=middle+1
356
+ end
357
+ end
358
+ end
359
+
360
+ =begin
361
+ = NAME
362
+ Bird's Eye View v1.1.3
363
+
364
+ = SYNOPSIS
365
+ Basic rep.s
366
+
367
+ = DESCRIPTION
368
+ Bird's Eye View Procedure
369
+ =end
370
+ def self.birds_eye(n, k)
371
+ return ((n-k)/(k+1));
372
+ end
373
+
374
+ =begin
375
+ = NAME
376
+ Eagle View v1.1.3
377
+
378
+ = SYNOPSIS
379
+ Basic rep.s
380
+
381
+ = DESCRIPTION
382
+ Eagle View Procedure
383
+ =end
384
+ def self.eagle_view(m, t)
385
+ return (EVALUE**((t*t)/m));
386
+ end
387
+
388
+ =begin
389
+ = NAME
390
+ Sum of Fibonacci Procedure v1.1.1
391
+
392
+ = SYNOPSIS
393
+ sum_of_fib(n)
394
+ 'n' is the number
395
+ Basic reps
396
+
397
+ = DESCRIPTION
398
+ Fibonacci Sum Procedure
399
+ =end
400
+ def self.sum_of_fib(n)
401
+ return fib(n+2)-1;
402
+ end
403
+
404
+ #
405
+ #def fibFormula(long int n)
406
+ # return (1/Math.sqrt(5))*(powl(((1+sqrt(5))/2), n)-powl(((1-sqrt(5))/2), n));
407
+ #end
408
+
409
+ =begin
410
+ = NAME
411
+ Is Prime Procedure v1.1.5
412
+
413
+ = SYNOPSIS
414
+ is_prime(nb)
415
+ 'nb' is the input argument number of procedure
416
+
417
+ = DESCRIPTION
418
+ Is Prime Procedure
419
+ =end
420
+ def self.is_prime(nb)
421
+ test = count = 0
422
+ if (nb == 1)
423
+ return -1
424
+ end
425
+ for i in 2..nb-1
426
+ count++
427
+ if (nb % i == 0)
428
+ test = false
429
+ end
430
+ end
431
+ if (!test)
432
+ return 1
433
+ else
434
+ return 0
435
+ end
436
+ end
437
+
438
+ =begin
439
+ = NAME
440
+ Fermat's Little Theorem v1.1.3
441
+
442
+ = SYNOPSIS
443
+ fermat_little(p, a)
444
+
445
+ = DESCRIPTION
446
+ Fermat Little Theorem's Procedural Representation
447
+
448
+ (('WARNING'))((-Modular representation maybe couldn't evaluated-))
449
+ =end
450
+ def self.fermat_little(p, a)
451
+ begin
452
+ if(p%(ui_pow(a, (p-1))-1) == 0)
453
+ return 0
454
+ else
455
+ return 1
456
+ end
457
+ end
458
+ rescue
459
+ begin
460
+ ArgumentError.new("High load. Terminated.")
461
+ end
462
+ end
463
+
464
+ =begin
465
+ = NAME
466
+ to_bool v.0.0.1
467
+
468
+ =SYNOPSIS
469
+ to_bool(void)
470
+ =DESCRIPTION
471
+ to bool is convert integer valus to string boolean
472
+ =end
473
+ def self.to_bool
474
+ if (self.to_bool == 1)
475
+ puts "TRUE"
476
+ elsif (self.to_bool == 0)
477
+ puts "FALSE"
478
+ elsif (self.to_bool == -1)
479
+ puts "NaN"
480
+ end
481
+ end
482
+
483
+ class Fixnum
484
+ def seconds
485
+ self
486
+ end
487
+ def minutes
488
+ self * 60
489
+ end
490
+ def hours
491
+ self * 60 * 60
492
+ end
493
+ def days
494
+ self * 60 * 60 * 24
495
+ end
496
+ def weeks
497
+ self * 60 * 60 * 24 * 7
498
+ end
499
+ end
500
+
501
+ def self.run
11
502
  puts "===RubMat===
12
503
  Copyright (C) <2011> <Mahmut Bulut>
13
504
  This program comes with ABSOLUTELY NO WARRANTY; for details type 'help'.
@@ -15,110 +506,114 @@ puts "===RubMat===
15
506
  under certain conditions; type `certain' for details."
16
507
  puts ""
17
508
  begin
18
- command = ask(">=> ")
509
+ command = ask(">=> ")
19
510
  #command = commn.chomp!
20
511
  # Read arguments and defines commands
21
512
  # Will handle command line whitespaces
22
513
 
23
- if (command == 'help')
24
- puts help()
25
- end
26
- if (command == 'certain')
27
- puts "To see certain conditions please visit http://www.gnu.org/licenses/gpl-2.0.html#SEC3"
28
- end
29
- if (command == 'factorial')
30
- n = ask("Enter N value: ", Integer)
31
- puts factorial(n)
32
- end
33
- if (command == 'binsearch')
34
- begin
35
- binary = ask("Enter array name with [ & ] suffix: ")
36
- size = ask("Enter size of search range: ", Integer)
37
- search_key = ask("Enter search delimiter key", Integer)
38
- low = ask("Lower limit: ", Integer)
39
- middle = ask("Medium limit: ", Integer)
40
- high = ask("High limit: ", Integer)
41
- puts binary_search(binary, size, search_key, low, middle, high)
42
- rescue => error
43
- puts error
514
+ if (command == 'help')
515
+ puts help()
44
516
  end
45
- end
46
- if (command == 'birdseye')
47
- n = ask("Enter workspace mass number: ", Integer)
48
- k = ask("Enter selection mass number: ", Integer)
49
- puts birds_eye(n, k)
50
- end
51
- if (command == 'combinatorial')
52
- glb = ask("Enter global set objects number: ", Integer)
53
- ksb = ask("Enter k-subset objects number: ", Integer)
54
- puts combinatorial(glb, ksb)
55
- end
56
- if (command == 'distpres')
57
- presnum = ask("Present number: ", Integer)
58
- puts dist_pres(presnum)
59
- end
60
- if (command == 'eagleview')
61
- m = ask("Enter m value: ", Integer)
62
- t = ask("Enter t value: ", Integer)
63
- puts eagle_view(m, t)
64
- end
65
- if (command == 'fermatlittle')
66
- p = ans("Enter power number: ", Integer)
67
- a = ans("Enter base number:", Integer)
68
- puts fermat_little(p, a)
69
- end
70
- if (command == 'fib')
71
- n = ans("Enter the last incremental number: ", Integer)
72
- puts fib(n)
73
- end
74
- if (command == 'isprime')
75
- raise RuntimeError.new("Have some critical issues closed to next minor version")
517
+ if (command == 'certain')
518
+ puts "To see certain conditions please visit http://www.gnu.org/licenses/gpl-2.0.html#SEC3"
519
+ end
520
+ if (command == 'factorial')
521
+ n = ask("Enter N value: ", Integer)
522
+ puts factorial(n)
523
+ end
524
+ if (command == 'binsearch')
525
+ begin
526
+ binary = ask("Enter array name with [ & ] suffix: ")
527
+ size = ask("Enter size of search range: ", Integer)
528
+ search_key = ask("Enter search delimiter key", Integer)
529
+ low = ask("Lower limit: ", Integer)
530
+ middle = ask("Medium limit: ", Integer)
531
+ high = ask("High limit: ", Integer)
532
+ puts binary_search(binary, size, search_key, low, middle, high)
533
+ rescue => error
534
+ puts error
535
+ end
536
+ end
537
+ if (command == 'birdseye')
538
+ n = ask("Enter workspace mass number: ", Integer)
539
+ k = ask("Enter selection mass number: ", Integer)
540
+ puts birds_eye(n, k)
541
+ end
542
+ if (command == 'combinatorial')
543
+ glb = ask("Enter global set objects number: ", Integer)
544
+ ksb = ask("Enter k-subset objects number: ", Integer)
545
+ puts combinatorial(glb, ksb)
546
+ end
547
+ if (command == 'distpres')
548
+ presnum = ask("Present number: ", Integer)
549
+ puts dist_pres(presnum)
550
+ end
551
+ if (command == 'eagleview')
552
+ m = ask("Enter m value: ", Integer)
553
+ t = ask("Enter t value: ", Integer)
554
+ puts eagle_view(m, t)
555
+ end
556
+ if (command == 'fermatlittle')
557
+ p = ans("Enter power number: ", Integer)
558
+ a = ans("Enter base number:", Integer)
559
+ puts fermat_little(p, a)
560
+ end
561
+ if (command == 'fib')
562
+ n = ans("Enter the last incremental number: ", Integer)
563
+ puts fib(n)
564
+ end
565
+ if (command == 'isprime')
566
+ raise RuntimeError.new("Have some critical issues closed to next minor version")
76
567
  # nb = ask("Control number: ", Integer)
77
568
  # puts is_prime(nb)
78
- end
79
- if (command == 'iterativefact')
80
- begin
81
- itrtnum = ask("Enter the factorial input: ", Integer)
82
- throw :ball if (itrtnum >= MAX_INTEGER)
83
- puts iterative_fact(itrtnum)
84
569
  end
85
- catch(:ball) do
86
- raise ArgumentError.new("iterative factorial couldn't take this value's load. Terminated.")
570
+ if (command == 'iterativefact')
571
+ begin
572
+ itrtnum = ask("Enter the factorial input: ", Integer)
573
+ throw :ball if (itrtnum >= MAX_INTEGER)
574
+ puts iterative_fact(itrtnum)
575
+ end
576
+ catch(:ball) do
577
+ raise ArgumentError.new("iterative factorial couldn't take this value's load. Terminated.")
578
+ end
87
579
  end
88
- end
89
- if (command == 'sigma')
90
- inta = ask("Enter a value: ", Integer)
91
- intx = ask("Enter x value: ", Integer)
92
- intb = ask("Enter b value: ", Integer)
93
- pw = ask("Enter power value: ", Integer)
94
- puts sigma(inta, intx, intb, pw)
95
- end
96
- if (command == 'stirling')
97
- begin
98
- strln = ask("Enter stirling procedure value: ", Integer)
99
- throw :glass if (strln >= MAX_INTEGER)
100
- puts stirling(strln)
580
+ if (command == 'sigma')
581
+ inta = ask("Enter a value: ", Integer)
582
+ intx = ask("Enter x value: ", Integer)
583
+ intb = ask("Enter b value: ", Integer)
584
+ pw = ask("Enter power value: ", Integer)
585
+ puts sigma(inta, intx, intb, pw)
101
586
  end
102
- catch(:glass) do
103
- raise ArgumentError.new("stirling couldn't take this value's load. Terminated.")
587
+ if (command == 'stirling')
588
+ begin
589
+ strln = ask("Enter stirling procedure value: ", Integer)
590
+ throw :glass if (strln >= MAX_INTEGER)
591
+ puts stirling(strln)
592
+ end
593
+ catch(:glass) do
594
+ raise ArgumentError.new("stirling couldn't take this value's load. Terminated.")
595
+ end
104
596
  end
105
- end
106
- if (command == 'subset')
107
- gen = ask("Enter mass objects number: ", Integer)
108
- zerosbst = agree("Include zero subset?")
109
- puts subset(gen, zerosbst)
110
- end
111
- if (command == 'fibsum')
112
- n = ask("Enter n value: ", Integer)
113
- puts sum_of_fib(n)
114
- end
115
- if (command == 'twinprdx')
116
- mass = ask("Enter mass number: ", Integer)
117
- puts twin_prdx(mass)
118
- end
119
- if (command == 'uipow')
120
- base = ask("Enter base value: ", Integer)
121
- exp = ask("Enter power value: ", Integer)
122
- puts ui_pow(base, exp)
123
- end
124
- end until(command == 'exit')
597
+ if (command == 'subset')
598
+ gen = ask("Enter mass objects number: ", Integer)
599
+ zerosbst = agree("Include zero subset?")
600
+ puts subset(gen, zerosbst)
601
+ end
602
+ if (command == 'fibsum')
603
+ n = ask("Enter n value: ", Integer)
604
+ puts sum_of_fib(n)
605
+ end
606
+ if (command == 'twinprdx')
607
+ mass = ask("Enter mass number: ", Integer)
608
+ puts twin_prdx(mass)
609
+ end
610
+ if (command == 'uipow')
611
+ base = ask("Enter base value: ", Integer)
612
+ exp = ask("Enter power value: ", Integer)
613
+ puts ui_pow(base, exp)
614
+ end
615
+ end until(command == 'exit')
616
+ end
617
+
618
+ ##MODULE END
619
+ end