Problem 1108: defanging an ip address

This commit is contained in:
Ivan R. 2022-11-25 23:43:40 +05:00
parent 25a578a8fb
commit 907dfdf070
No known key found for this signature in database
GPG key ID: 56C7BAAE859B302C
3 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# @param {String} address
# @return {String}
def defang_i_paddr(address)
new_addr = address.gsub(".", "[.]")
return new_addr
end

View file

@ -0,0 +1,11 @@
require_relative "main"
require "test/unit"
class TestDefangIpAddr < Test::Unit::TestCase
def test_simple
assert_equal("1[.]1[.]1[.]1", defang_i_paddr("1.1.1.1") )
assert_equal("255[.]100[.]50[.]0", defang_i_paddr("255.100.50.0") )
end
end

View file

@ -19,6 +19,13 @@ cd problems/random-problem
cargo test cargo test
``` ```
For programs written in Ruby:
```bash
cd problems/random-problem
ruby test.rb
```
## Solution structure ## Solution structure
For programs written in C: For programs written in C:
@ -29,3 +36,8 @@ For programs written in C:
For programs written in Rust: For programs written in Rust:
- `src/lib.rs` - solution and tests - `src/lib.rs` - solution and tests
For programs written in Ruby:
- `main.rb` - the solution itself
- `test.rb` - tests