aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2022-11-02 17:07:24 +0330
committerdeadmarshal <adeadmarshal@gmail.com>2022-11-02 17:07:24 +0330
commitef01370b70103b4ce222158b23a27b8a5cf19789 (patch)
tree2622b515d09ab9750cae4fb8f34a0ffe7337719f
parent0c702901ccc86d908ce0bb77de5698f555b3c958 (diff)
downloadperlweeklychallenge-club-ef01370b70103b4ce222158b23a27b8a5cf19789.tar.gz
perlweeklychallenge-club-ef01370b70103b4ce222158b23a27b8a5cf19789.tar.bz2
perlweeklychallenge-club-ef01370b70103b4ce222158b23a27b8a5cf19789.zip
Fixed nim, added nelua
-rw-r--r--challenge-189/deadmarshal/nelua/ch-1.nelua35
-rw-r--r--challenge-189/deadmarshal/nelua/ch-2.nelua34
-rw-r--r--challenge-189/deadmarshal/nim/ch2.nim10
3 files changed, 74 insertions, 5 deletions
diff --git a/challenge-189/deadmarshal/nelua/ch-1.nelua b/challenge-189/deadmarshal/nelua/ch-1.nelua
new file mode 100644
index 0000000000..dd8dcf9f51
--- /dev/null
+++ b/challenge-189/deadmarshal/nelua/ch-1.nelua
@@ -0,0 +1,35 @@
+require'string'
+
+local function quick_sort(s:sequence(string),
+ left:integer,
+ right:integer):void
+ local i,j:integer = left,right
+ local pivot = s[(left + right) // 2]
+ repeat
+ while string.byte(pivot) > string.byte(s[i]) do i = i + 1 end
+ while string.byte(pivot) < string.byte(s[j]) do j = j - 1 end
+ if i <= j then
+ s[i],s[j] = s[j],s[i]
+ i = i + 1
+ j = j - 1
+ end
+ until i > j
+ if left < j then quick_sort(s,left,j) end
+ if i < right then quick_sort(s,i,right) end
+end
+
+local function greater_character(s:sequence(string),
+ target:string):string
+ quick_sort(s,0,#s)
+ for i=1, #s do
+ if s[i] > target then return s[i] end
+ end
+ return target
+end
+
+print(greater_character({'e','m','u','g'}, 'b'))
+print(greater_character({'d','c','e','f'}, 'a'))
+print(greater_character({'j','a','r'}, 'o'))
+print(greater_character({'d','c','a','f'}, 'a'))
+print(greater_character({'t','g','a','l'}, 'v'))
+
diff --git a/challenge-189/deadmarshal/nelua/ch-2.nelua b/challenge-189/deadmarshal/nelua/ch-2.nelua
new file mode 100644
index 0000000000..f39cfa2e89
--- /dev/null
+++ b/challenge-189/deadmarshal/nelua/ch-2.nelua
@@ -0,0 +1,34 @@
+require'io'
+
+local function array_degree(s:sequence(integer)):void
+ local left:hashmap(integer,integer)
+ local count:hashmap(integer,integer)
+ local index,max,min:integer
+ for i=1, #s do
+ if not count:has(s[i]) then
+ left[s[i]] = i
+ count[s[i]] = 1
+ else
+ count[s[i]] = count[s[i]] + 1
+ end
+ if count[s[i]] > max then
+ max = count[s[i]]
+ min = i - left[s[i]]
+ index = left[s[i]]
+ elseif(count[s[i]] == max) and (i - left[s[i]] < min) then
+ min = i - left[s[i]]
+ index = left[s[i]]
+ end
+ end
+ for i=index, index+min do
+ io.write(s[i], ' ')
+ end
+ print()
+end
+
+array_degree({1,3,3,2})
+array_degree({1,2,1,3})
+array_degree({1,3,2,1,2})
+array_degree({1,1,2,3,2})
+array_degree({2,1,2,1,1})
+
diff --git a/challenge-189/deadmarshal/nim/ch2.nim b/challenge-189/deadmarshal/nim/ch2.nim
index 4e1d9f540d..fc4465b570 100644
--- a/challenge-189/deadmarshal/nim/ch2.nim
+++ b/challenge-189/deadmarshal/nim/ch2.nim
@@ -25,8 +25,8 @@ proc arrayDegree(s:seq[int]) =
stdout.write(s[i], ' ')
echo ""
-arrayDegree(@[1,3,3,2]);
-arrayDegree(@[1,2,1,3]);
-arrayDegree(@[1,3,2,1,2]);
-arrayDegree(@[1,1,2,3,2]);
-arrayDegree(@[2,1,2,1,1]);
+arrayDegree(@[1,3,3,2])
+arrayDegree(@[1,2,1,3])
+arrayDegree(@[1,3,2,1,2])
+arrayDegree(@[1,1,2,3,2])
+arrayDegree(@[2,1,2,1,1])