From 23c4072589a8078e66e079e33bcfeda88afff3ff Mon Sep 17 00:00:00 2001 From: BarrOff <58253563+BarrOff@users.noreply.github.com> Date: Sun, 23 Jun 2024 22:57:43 +0200 Subject: feat: add solutions for challenge 274 from BarrOff --- challenge-274/barroff/julia/ch-1.jl | 24 ++++++++++++++++++++++++ challenge-274/barroff/raku/ch-1.p6 | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 challenge-274/barroff/julia/ch-1.jl create mode 100644 challenge-274/barroff/raku/ch-1.p6 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); +} -- cgit