commit e3ec80d
Artur Manuel
·
2025-12-21 23:02:12 +0000 UTC
parent 757c0be
feat(ruby): add ruby
6 files changed,
+115,
-0
+56,
-0
1@@ -0,0 +1,56 @@
2+*.gem
3+*.rbc
4+/.config
5+/coverage/
6+/InstalledFiles
7+/pkg/
8+/spec/reports/
9+/spec/examples.txt
10+/test/tmp/
11+/test/version_tmp/
12+/tmp/
13+
14+# Used by dotenv library to load environment variables.
15+# .env
16+
17+# Ignore Byebug command history file.
18+.byebug_history
19+
20+## Specific to RubyMotion:
21+.dat*
22+.repl_history
23+build/
24+*.bridgesupport
25+build-iPhoneOS/
26+build-iPhoneSimulator/
27+
28+## Specific to RubyMotion (use of CocoaPods):
29+#
30+# We recommend against adding the Pods directory to your .gitignore. However
31+# you should judge for yourself, the pros and cons are mentioned at:
32+# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
33+#
34+# vendor/Pods/
35+
36+## Documentation cache and generated files:
37+/.yardoc/
38+/_yardoc/
39+/doc/
40+/rdoc/
41+
42+## Environment normalization:
43+/.bundle/
44+/vendor/bundle
45+/lib/bundler/man/
46+
47+# for a library or gem, you might want to ignore these files since the code is
48+# intended to run in multiple environments; otherwise, check them in:
49+# Gemfile.lock
50+# .ruby-version
51+# .ruby-gemset
52+
53+# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
54+.rvmrc
55+
56+# Used by RuboCop. Remote config files pulled in from inherit_from directive.
57+# .rubocop-https?--*
+2,
-0
1@@ -0,0 +1,2 @@
2+AllCops:
3+ TargetRubyVersion: '3.4.7'
+8,
-0
1@@ -0,0 +1,8 @@
2+#!/usr/bin/env ruby
3+# frozen_string_literal: true
4+
5+require 'rosetta_collatz'
6+
7+(1..10_000).each do |i|
8+ puts RosettaCollatz.collatz_sequence(i)
9+end
+27,
-0
1@@ -0,0 +1,27 @@
2+# frozen_string_literal: true
3+
4+# Collatz conjecture functions
5+module RosettaCollatz
6+ def self.collatz(num)
7+ raise 'num must be an Integer' unless num.is_a?(Integer)
8+
9+ if num.even?
10+ num / 2
11+ else
12+ 3 * num + 1
13+ end
14+ end
15+
16+ def self.collatz_sequence(num)
17+ raise 'num must be an Integer' unless num.is_a?(Integer)
18+
19+ res = "#{num}: "
20+ i = num
21+ while i != 1
22+ res << "#{i}, "
23+ i = collatz(i)
24+ end
25+ res << '1'
26+ res
27+ end
28+end
+5,
-0
1@@ -0,0 +1,5 @@
2+# frozen_string_literal: true
3+
4+module RosettaCollatz
5+ VERSION = '0.1.0'
6+end
+17,
-0
1@@ -0,0 +1,17 @@
2+# frozen_string_literal: true
3+
4+require_relative 'lib/rosetta_collatz/version'
5+
6+Gem::Specification.new do |s|
7+ s.name = 'rosetta-collatz'
8+ s.version = RosettaCollatz::VERSION
9+ s.licenses = ['EUPL-1.2']
10+ s.summary = 'Rosetta stone attempt at the Collatz conjecture'
11+ s.authors = ['Artur Manuel']
12+ s.email = 'amadaluzia@disroot.org'
13+ s.required_ruby_version = '3.4.7'
14+ s.files = [
15+ 'lib/rosetta_collatz.rb',
16+ 'lib/rosetta_collatz/version.rb'
17+ ]
18+end