diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-06 23:07:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-06 23:07:02 +0100 |
| commit | 5bdec4d49ae89797e311113b7bff79814e32a5fe (patch) | |
| tree | 2dada90c202b3e215787c094d92a96f66b2d2b63 | |
| parent | 259e0413ae2d77dd21017d6ed5f1fc8bfaf98937 (diff) | |
| parent | 17808ae69b75b4f9675568f62052095daabb34ec (diff) | |
| download | perlweeklychallenge-club-5bdec4d49ae89797e311113b7bff79814e32a5fe.tar.gz perlweeklychallenge-club-5bdec4d49ae89797e311113b7bff79814e32a5fe.tar.bz2 perlweeklychallenge-club-5bdec4d49ae89797e311113b7bff79814e32a5fe.zip | |
Merge pull request #12293 from HVukman/branch-for-challenge-328
Branch for challenge 328
| -rw-r--r-- | challenge-328/hvukman/f#/328_p1.fs | 12 | ||||
| -rw-r--r-- | challenge-328/hvukman/lua/328_p2.lua | 55 | ||||
| -rw-r--r-- | challenge-328/hvukman/picolisp/328_p1.l | 34 |
3 files changed, 101 insertions, 0 deletions
diff --git a/challenge-328/hvukman/f#/328_p1.fs b/challenge-328/hvukman/f#/328_p1.fs new file mode 100644 index 0000000000..7c1ce7d3f7 --- /dev/null +++ b/challenge-328/hvukman/f#/328_p1.fs @@ -0,0 +1,12 @@ +open System +let example = "a?z" +let rnd = new Random() + +// choose random a-z +let rnd_char = ['a' .. 'z'].[rnd.Next(0, 25) ] + +// tailcall rec newchar; if n=x repeat newchar with new randomchar +[<TailCall>] +let rec newchar n x = if n=x then newchar rnd_char x else printfn "%c" n +// iterate over string +String.iter (fun x -> if x <> '?' then printfn "%c" x else newchar rnd_char x) example diff --git a/challenge-328/hvukman/lua/328_p2.lua b/challenge-328/hvukman/lua/328_p2.lua new file mode 100644 index 0000000000..b536078589 --- /dev/null +++ b/challenge-328/hvukman/lua/328_p2.lua @@ -0,0 +1,55 @@ + +function Bad (a) +local new_str = "" +local need = false +for i = 1, string.len(a)-1 do + local char = string.sub(a, i, i) + local char_next = string.sub(a, i+1, i+1) + + if string.match(char, "%u") and string.match(char_next, "%l") then + if char == string.lower(char_next) then + + local new = {} + for j = 0,string.len(a) do + if j ~= i and j~= i+1 then + + table.insert(new,string.sub(a, j, j)) + end + end + new_str = table.concat(new) + -- print ("maybe not here ", new_str) + need= true + break + end + + elseif string.match(char, "%l") and string.match(char_next, "%u") then + if string.upper(char) == char_next then + local new = {} + for j = 0,string.len(a) do + if j ~= i and j~= i+1 then + + table.insert(new,string.sub(a, j, j)) + end + end + new_str = (table.concat(new)) + --print ("maybe not ", new_str) + need=true + break + + end + end + + +end + -- print ("new " , new_str) + if need then + Bad(new_str) + else + print(a) + end +end + + +Bad("WeEeekly") +Bad("abc") +Bad("abBAdD") diff --git a/challenge-328/hvukman/picolisp/328_p1.l b/challenge-328/hvukman/picolisp/328_p1.l new file mode 100644 index 0000000000..b142747306 --- /dev/null +++ b/challenge-328/hvukman/picolisp/328_p1.l @@ -0,0 +1,34 @@ + +(setq choose "abcdefghijklmnopqrstuvwxyz") + +(de choose_letter (new after before) + (if (and (not (= new after) ) (not (= new before))) + new + (choose_letter (get (chop choose) (rand 1 26)) after before) + ) +) + +(de new_str (X) +(pack (make + (let list_str (chop X) + (for N (size list_str) + (let (before (get list_str (- N 1)) after (get list_str (+ N 1))) + (if (not (= (get list_str N) "?")) + (link (get list_str N) ) + (let new (get (chop choose) (rand 1 26)) + (if (and (not (= new after) ) (not (= new before))) + (link new ) + (link (choose_letter (get (chop choose) (rand 1 26)) after before)) + ) + ) + ) + ) + ) +) +) +) +) + +(println (new_str "a?z")) +(println (new_str "pe?k")) +(println (new_str "gra?te")) |
