A collection of Ruby solutions for programming challenges from Codewars, a platform for improving coding skills through practice and community-driven kata (coding exercises).
This repository serves as a reference for algorithmic problem-solving approaches in Ruby. Each solution demonstrates idiomatic Ruby techniques including method chaining, blocks, and functional programming patterns.
codewars-solutions/
├── arithmetic_list.rb # Generate arithmetic sequences
├── arithmetic_sequence.rb # Find nth term of arithmetic sequence
├── digital_root.rb # Calculate recursive digit sum
├── digitize.rb # Convert number to digit array
├── fluent_calculator.rb # Fluent interface calculator
├── jaden_casing_trings.rb # Capitalize each word in string
├── name_array_capping.rb # Capitalize names in array
├── strip_comments.rb # Remove comments from text
├── throwing_darts.rb # Dart game scoring system
├── validate_credit_card_number.rb # Luhn algorithm validation
├── LICENSE # MIT License
└── README.md # This file
- Ruby 2.0 or higher
No external dependencies are required. All solutions use Ruby's standard library.
git clone https://github.com/your-username/codewars-solutions.git
cd codewars-solutionsEach file is a standalone solution that can be loaded into IRB or required in other Ruby files.
# In IRB or a Ruby file
require_relative 'digital_root'
digital_root(942)
# => 6Recursively sums digits until a single digit remains:
digital_root(16) # => 7 (1 + 6 = 7)
digital_root(942) # => 6 (9 + 4 + 2 = 15, 1 + 5 = 6)Calculator with natural language-like syntax:
Calc.new.one.plus.two # => 3
Calc.new.five.minus.six # => -1
Calc.new.seven.times.two # => 14
Calc.new.nine.divided_by.three # => 3validate(4532049659615906) # => true
validate(1714) # => falsescoreThrows([1, 5, 11]) # => 15
scoreThrows([1, 2, 3, 4]) # => 140 (40 + 100 bonus for all bullseyes)"how can mirrors be real".toJadenCase
# => "How Can Mirrors Be Real"Uses recursive digit summation. Converts number to string, splits into characters, maps to integers, sums them, and repeats until single digit.
- Double every second digit from the right
- If doubled value > 9, sum its digits
- Sum all digits
- Valid if sum is divisible by 10
- Radius < 5: 10 points
- Radius 5-10: 5 points
- Radius > 10: 0 points
- Bonus: +100 if all throws score 10 points
Implements a state machine using method chaining. Number methods set or evaluate based on current state; operator methods set the pending operation.
| File | Function/Class | Parameters | Returns | Description |
|---|---|---|---|---|
arithmetic_list.rb |
seqlist |
first, c, l |
Array | Generates arithmetic sequence of length l |
arithmetic_sequence.rb |
nthterm |
first, n, c |
Number | Returns value at index n in arithmetic sequence |
digital_root.rb |
digital_root |
n |
Number | Recursive sum of digits until single digit |
digitize.rb |
digitize |
n |
Array | Converts number to array of digits |
fluent_calculator.rb |
Calc |
- | Number | Calculator class with fluent interface |
jaden_casing_trings.rb |
String#toJadenCase |
- | String | Capitalizes each word in string |
name_array_capping.rb |
cap_me |
array |
Array | Capitalizes each name in array |
strip_comments.rb |
solution |
input, markers |
String | Strips text after comment markers |
throwing_darts.rb |
scoreThrows |
radiuses |
Number | Calculates dart game score |
validate_credit_card_number.rb |
validate |
n |
Boolean | Validates credit card using Luhn algorithm |
This project is licensed under the MIT License - see the LICENSE file for details.