Problem 1108: defanging an ip address
This commit is contained in:
parent
25a578a8fb
commit
907dfdf070
3 changed files with 29 additions and 0 deletions
6
problems/1108-defanging-an-ip-address/main.rb
Normal file
6
problems/1108-defanging-an-ip-address/main.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
# @param {String} address
|
||||
# @return {String}
|
||||
def defang_i_paddr(address)
|
||||
new_addr = address.gsub(".", "[.]")
|
||||
return new_addr
|
||||
end
|
11
problems/1108-defanging-an-ip-address/test.rb
Normal file
11
problems/1108-defanging-an-ip-address/test.rb
Normal 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
|
12
readme.md
12
readme.md
|
@ -19,6 +19,13 @@ cd problems/random-problem
|
|||
cargo test
|
||||
```
|
||||
|
||||
For programs written in Ruby:
|
||||
|
||||
```bash
|
||||
cd problems/random-problem
|
||||
ruby test.rb
|
||||
```
|
||||
|
||||
## Solution structure
|
||||
|
||||
For programs written in C:
|
||||
|
@ -29,3 +36,8 @@ For programs written in C:
|
|||
For programs written in Rust:
|
||||
|
||||
- `src/lib.rs` - solution and tests
|
||||
|
||||
For programs written in Ruby:
|
||||
|
||||
- `main.rb` - the solution itself
|
||||
- `test.rb` - tests
|
||||
|
|
Loading…
Reference in a new issue