Skip to content

Commit

Permalink
Merge pull request JuliaLang#40 from andrej-makarov-skrt/ex-atbash-ci…
Browse files Browse the repository at this point in the history
…pher

Add exercise: atbash-cipher
  • Loading branch information
SaschaMann authored Feb 10, 2017
2 parents de8f6d9 + c00fb78 commit 8459bde
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
23 changes: 16 additions & 7 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,24 @@
"arithmetics",
"control-flow (conditionals)"
]
},
{
"slug": "atbash-cipher",
"difficulty": 1,
"topics": [
"strings",
"control-flow (conditionals)",
"control-flow (loops)"
]
},
{
"slug": "roman-numerals",
"difficulty": 1,
"topics": [
"control-flow (loops)",
"strings",
"mathematics"
]
"slug": "roman-numerals",
"difficulty": 1,
"topics": [
"control-flow (loops)",
"strings",
"mathematics"
]
},
{
"slug": "isogram",
Expand Down
8 changes: 8 additions & 0 deletions exercises/atbash-cipher/atbash-cipher.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function encode(input::AbstractString)

end

function decode(input::AbstractString)

end

4 changes: 4 additions & 0 deletions exercises/atbash-cipher/example.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cipher(input::AbstractString) = map(x->isalpha(x)?Char(219-Int(x)):x, lowercase(filter(isalnum, input)))
encode(input::AbstractString) = join(matchall(r"(.{1,5})", cipher(input)), ' ')
decode(input::AbstractString) = cipher(input)

56 changes: 56 additions & 0 deletions exercises/atbash-cipher/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Base.Test

include("atbash-cipher.jl")

@testset "encoding from English to atbash" begin
@testset "encode yes" begin
@test encode("yes") == "bvh"
end

@testset "encode no" begin
@test encode("no") == "ml"
end

@testset "encode OMG" begin
@test encode("OMG") == "lnt"
end

@testset "encode spaces" begin
@test encode("O M G") == "lnt"
end

@testset "encode mindblowingly" begin
@test encode("mindblowingly") == "nrmwy oldrm tob"
end

@testset "encode numbers" begin
@test encode("Testing,1 2 3, testing.") == "gvhgr mt123 gvhgr mt"
end

@testset "encode deep thought" begin
@test encode("Truth is fiction.") == "gifgs rhurx grlm"
end

@testset "encode all the letters" begin
@test encode("The quick brown fox jumps over the lazy dog.") == "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
end
end

@testset "decoding from atbash to English" begin
@testset "decode exercism" begin
@test decode("vcvix rhn") == "exercism"
end

@testset "decode a sentence" begin
@test decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v") == "anobstacleisoftenasteppingstone"
end

@testset "decode numbers" begin
@test decode("gvhgr mt123 gvhgr mt") == "testing123testing"
end

@testset "decode all the letters" begin
@test decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt") == "thequickbrownfoxjumpsoverthelazydog"
end
end

0 comments on commit 8459bde

Please sign in to comment.