tarai 0.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.
Files changed (5) hide show
  1. data/README +44 -0
  2. data/ext/extconf.rb +27 -0
  3. data/ext/tarai.c +58 -0
  4. data/test/test-tarai.rb +9 -0
  5. metadata +52 -0
data/README ADDED
@@ -0,0 +1,44 @@
1
+ = tarai
2
+
3
+ tarai function.
4
+
5
+ == Usage
6
+
7
+ require 'tarai'
8
+
9
+ p tarai(12, 6, 0)
10
+ #=> 12
11
+
12
+ == Install
13
+
14
+ gem install tarai
15
+
16
+ == Author
17
+
18
+ Tanaka Akira <akr@fsij.org>
19
+
20
+ == License
21
+
22
+ Redistribution and use in source and binary forms, with or without
23
+ modification, are permitted provided that the following conditions are met:
24
+
25
+ (1) Redistributions of source code must retain the above copyright notice, this
26
+ list of conditions and the following disclaimer.
27
+ (2) Redistributions in binary form must reproduce the above copyright notice,
28
+ this list of conditions and the following disclaimer in the documentation
29
+ and/or other materials provided with the distribution.
30
+ (3) The name of the author may not be used to endorse or promote products
31
+ derived from this software without specific prior written permission.
32
+
33
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
34
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
36
+ EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
38
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
42
+ OF SUCH DAMAGE.
43
+
44
+ (The modified BSD licence)
@@ -0,0 +1,27 @@
1
+ # Copyright (C) 2011 Tanaka Akira. All rights reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
5
+ #
6
+ # (1) Redistributions of source code must retain the above copyright notice, this
7
+ # list of conditions and the following disclaimer.
8
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ # (3) The name of the author may not be used to endorse or promote products
12
+ # derived from this software without specific prior written permission.
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
15
+ # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
+ # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17
+ # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
19
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22
+ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
23
+ # OF SUCH DAMAGE.
24
+
25
+ require 'mkmf'
26
+
27
+ create_makefile('tarai')
@@ -0,0 +1,58 @@
1
+ /*
2
+ Copyright (C) 2011 Tanaka Akira.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ (1) Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ (2) Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ (3) The name of the author may not be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18
+ EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
24
+ OF SUCH DAMAGE.
25
+ */
26
+
27
+ #include "ruby.h"
28
+
29
+ static long
30
+ tarai(long x, long y, long z)
31
+ {
32
+ if (x <= y)
33
+ return y;
34
+ else
35
+ return tarai(tarai(x-1, y, z),
36
+ tarai(y-1, z, x),
37
+ tarai(z-1, x, y));
38
+ }
39
+
40
+ /*
41
+ * call-seq:
42
+ * tarai(x,y,z) => integer
43
+ *
44
+ * computes the tarai function in recursive (naive) manner.
45
+ */
46
+
47
+ static VALUE
48
+ tarai_m(VALUE self, VALUE x, VALUE y, VALUE z)
49
+ {
50
+ return LONG2NUM(tarai(NUM2LONG(x), NUM2LONG(y), NUM2LONG(z)));
51
+ }
52
+
53
+ void
54
+ Init_tarai()
55
+ {
56
+ rb_define_global_function("tarai", tarai_m, 3);
57
+ }
58
+
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ require 'tarai'
4
+
5
+ class TestTarai < Test::Unit::TestCase
6
+ def test_tarai
7
+ assert_equal(12, tarai(12,6,0))
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tarai
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tanaka Akira
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-29 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'tarai provides the tarai function.
15
+
16
+ '
17
+ email: akr@fsij.org
18
+ executables: []
19
+ extensions:
20
+ - ext/extconf.rb
21
+ extra_rdoc_files: []
22
+ files:
23
+ - README
24
+ - ext/extconf.rb
25
+ - ext/tarai.c
26
+ - test/test-tarai.rb
27
+ homepage: https://github.com/akr/tarai
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.11
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Tarai Function
51
+ test_files:
52
+ - test/test-tarai.rb