diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-06-23 22:57:43 +0200 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-06-23 22:57:43 +0200 |
| commit | 23c4072589a8078e66e079e33bcfeda88afff3ff (patch) | |
| tree | e8a01336cd561cc8a1cb3324b3899b4ff5d06cb6 | |
| parent | 01294d2b2783bb8216defdec8ddbaa57eac54e82 (diff) | |
| download | perlweeklychallenge-club-23c4072589a8078e66e079e33bcfeda88afff3ff.tar.gz perlweeklychallenge-club-23c4072589a8078e66e079e33bcfeda88afff3ff.tar.bz2 perlweeklychallenge-club-23c4072589a8078e66e079e33bcfeda88afff3ff.zip | |
feat: add solutions for challenge 274 from BarrOff
| -rw-r--r-- | challenge-274/barroff/julia/ch-1.jl | 24 | ||||
| -rw-r--r-- | challenge-274/barroff/raku/ch-1.p6 | 33 |
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-274/barroff/julia/ch-1.jl b/challenge-274/barroff/julia/ch-1.jl new file mode 100644 index 0000000000..a2fcb694bd --- /dev/null +++ b/challenge-274/barroff/julia/ch-1.jl @@ -0,0 +1,24 @@ +#!/usr/bin/env julia + +using Test: @test, @testset + +function goat_latin(str::AbstractString)::String + as = "" + result = "" + for word in split(str) + as *= 'a' + if lowercase(word[1]) in ['a', 'e', 'i', 'o', 'u'] + skip + else + word = word[2:end] * word[1] + end + result = result * " " * word * "ma" * as + end + return strip(result) +end + +@testset "goat latin" begin + @test goat_latin("I love Perl") == "Imaa ovelmaaa erlPmaaaa" + @test goat_latin("Perl and Raku are friends") == "erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa" + @test goat_latin("The Weekly Challenge") == "heTmaa eeklyWmaaa hallengeCmaaaa" +end diff --git a/challenge-274/barroff/raku/ch-1.p6 b/challenge-274/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..17218783e0 --- /dev/null +++ b/challenge-274/barroff/raku/ch-1.p6 @@ -0,0 +1,33 @@ +#!/usr/bin/env raku + +use v6.d; + +sub goat-latin(Str $str --> Str) { + my $vowels = Set(['a', 'e', 'i', 'o', 'u']); + my $as = ""; + my &goat = sub ($word) { + $as = $as ~ 'a'; + my $result = $word.comb[0] ∈ $vowels ?? $word !! rotate($word.comb, 1).join; + $result ~ 'ma' ~ $as; + } + map({ &goat($_) }, words($str)).join(' '); +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 4; + + is goat-latin("I love Perl"), "Imaa ovelmaaa erlPmaaaa", + 'works for "I love Perl"'; + is goat-latin("Perl and Raku are friends"), + "erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa", + 'works for "Perl and Raku are friends"'; + is goat-latin("The Weekly Challenge"), "heTmaa eeklyWmaaa hallengeCmaaaa", + 'works for "The Weekly Challenge"'; +} + +#| Take user provided number like 10 1 111 24 1000 +multi sub MAIN(Str $str) { + say goat-latin($str); +} |
