diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-03-09 20:01:18 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-03-09 20:01:18 +0000 |
| commit | c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84 (patch) | |
| tree | 9133aa3fc3d107c7b44de3905fc7b1d2ab307aaa | |
| parent | bfa8b8a3dda2ac37c22c7f4fc2867211f92f65e0 (diff) | |
| download | perlweeklychallenge-club-c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84.tar.gz perlweeklychallenge-club-c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84.tar.bz2 perlweeklychallenge-club-c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84.zip | |
Remove tabs
64 files changed, 595 insertions, 593 deletions
diff --git a/challenge-001/paulo-custodio/test.pl b/challenge-001/paulo-custodio/test.pl index 0d5a4711b0..ba7e6ee46f 100644 --- a/challenge-001/paulo-custodio/test.pl +++ b/challenge-001/paulo-custodio/test.pl @@ -20,6 +20,7 @@ our %LANG = ( basic => 'bas', c => 'c', cpp => 'cpp', + d => 'd', forth => 'fs', lua => 'lua', perl => 'pl', @@ -124,6 +125,10 @@ sub build { run("g++ $prog -o $prog_wo_ext") if (!-f $exe || -M $exe > -M $prog); return $exe; } + if (/^d$/) { + run("cd d; dmd $prog_base") if (!-f $exe || -M $exe > -M $prog); + return $exe; + } if (/forth/) { return "gforth $prog"; } diff --git a/challenge-090/paulo-custodio/lua/ch-1.lua b/challenge-090/paulo-custodio/lua/ch-1.lua index 021f4c3a90..8126c4a171 100644 --- a/challenge-090/paulo-custodio/lua/ch-1.lua +++ b/challenge-090/paulo-custodio/lua/ch-1.lua @@ -20,9 +20,9 @@ facing a cytosine (C) and vice versa. --]] function complement(seq) - local trans = {T = "A", A = "T", G = "C", C = "G"} - local compl = string.gsub(seq, "[TAGC]", trans) - return compl + local trans = {T = "A", A = "T", G = "C", C = "G"} + local compl = string.gsub(seq, "[TAGC]", trans) + return compl end seq = arg[1] diff --git a/challenge-090/paulo-custodio/lua/ch-2.lua b/challenge-090/paulo-custodio/lua/ch-2.lua index c93074b04f..d9e54b052f 100644 --- a/challenge-090/paulo-custodio/lua/ch-2.lua +++ b/challenge-090/paulo-custodio/lua/ch-2.lua @@ -11,18 +11,18 @@ Write a script to demonstrate Ethiopian Multiplication using the given numbers. --]] function mul(a, b) - local m = 0 - while (true) do - if ((a & 1) ~= 0) then - m = m + b - end - if (a <= 1) then - break - end - a = a >> 1 - b = b << 1 - end - return m + local m = 0 + while (true) do + if ((a & 1) ~= 0) then + m = m + b + end + if (a <= 1) then + break + end + a = a >> 1 + b = b << 1 + end + return m end io.write(mul(tonumber(arg[1]), tonumber(arg[2])), "\n") diff --git a/challenge-091/paulo-custodio/forth/ch-1.fs b/challenge-091/paulo-custodio/forth/ch-1.fs index e50b54ae75..43c3c2a76c 100644 --- a/challenge-091/paulo-custodio/forth/ch-1.fs +++ b/challenge-091/paulo-custodio/forth/ch-1.fs @@ -40,6 +40,6 @@ CR ; -NEXT-ARG S>NUMBER? 0= THROW DROP ( N ) -read_number +NEXT-ARG S>NUMBER? 0= THROW DROP ( N ) +read_number BYE diff --git a/challenge-091/paulo-custodio/forth/ch-2.fs b/challenge-091/paulo-custodio/forth/ch-2.fs index 69e6d49327..c88fb04ccb 100644 --- a/challenge-091/paulo-custodio/forth/ch-2.fs +++ b/challenge-091/paulo-custodio/forth/ch-2.fs @@ -13,15 +13,15 @@ 0 VALUE tbl-size \ save table size \ collect_args, append them to heap -: collect_args ( -- ) - 0 TO tbl-size - BEGIN NEXT-ARG DUP 0> WHILE - S>NUMBER? 0= THROW DROP , - tbl-size 1+ TO tbl-size - REPEAT +: collect_args ( -- ) + 0 TO tbl-size + BEGIN NEXT-ARG DUP 0> WHILE + S>NUMBER? 0= THROW DROP , + tbl-size 1+ TO tbl-size + REPEAT ; -CREATE tbl +CREATE tbl collect_args \ run the table diff --git a/challenge-091/paulo-custodio/lua/ch-1.lua b/challenge-091/paulo-custodio/lua/ch-1.lua index 96270413e7..0a3bf830c3 100644 --- a/challenge-091/paulo-custodio/lua/ch-1.lua +++ b/challenge-091/paulo-custodio/lua/ch-1.lua @@ -14,14 +14,14 @@ results and show them. --]] function count_number(n) - local inp, out = tostring(n), '' - while (inp ~= '') do - local digit = string.match(inp, "^%d") - local digits = string.match(inp, "^"..digit.."+") - out = out..tostring(#digits)..digit - inp = string.sub(inp, #digits+1) - end - return out + local inp, out = tostring(n), '' + while (inp ~= '') do + local digit = string.match(inp, "^%d") + local digits = string.match(inp, "^"..digit.."+") + out = out..tostring(#digits)..digit + inp = string.sub(inp, #digits+1) + end + return out end print(count_number(tonumber(arg[1]))) diff --git a/challenge-091/paulo-custodio/lua/ch-2.lua b/challenge-091/paulo-custodio/lua/ch-2.lua index cf1a47424e..c36f960435 100644 --- a/challenge-091/paulo-custodio/lua/ch-2.lua +++ b/challenge-091/paulo-custodio/lua/ch-2.lua @@ -14,16 +14,16 @@ index otherwise 0. N = {} for i=1,#arg do - table.insert(N, tonumber(arg[i])) + table.insert(N, tonumber(arg[i])) end p = 1 while (p < #N and N[p] ~= 0) do - p = p + N[p] + p = p + N[p] end if (p == #N) then - io.write(1, "\n") + io.write(1, "\n") else - io.write(0, "\n") + io.write(0, "\n") end diff --git a/challenge-092/paulo-custodio/basic/ch-1.bas b/challenge-092/paulo-custodio/basic/ch-1.bas index 1e042022ff..bfaafba85f 100644 --- a/challenge-092/paulo-custodio/basic/ch-1.bas +++ b/challenge-092/paulo-custodio/basic/ch-1.bas @@ -4,7 +4,7 @@ ' Submitted by: Mohammad S Anwar ' You are given two strings $A and $B. ' -' Write a script to check if the given strings are Isomorphic. Print 1 if they +' Write a script to check if the given strings are Isomorphic. Print 1 if they ' are otherwise 0. ' ' Example 1: @@ -18,30 +18,30 @@ ' Output: 0 function isomorphic(a as string, b as string) as integer - dim mapping(256) as integer, mapped(256) as integer - dim i as integer, ac as integer, bc as integer - - if a="" or len(a)<>len(b) then - isomorphic = 0: exit function - end if - - for i=1 to len(a) - ac = asc(mid(a,i,1)) - bc = asc(mid(b,i,1)) - if mapping(ac)=0 then ' a is new - if mapped(bc)<>0 then ' b already mapped to some other a - isomorphic = 0: exit function - else ' store mapping - mapping(ac) = bc - mapped(bc) = 1 - end if - else ' a already occurred - if mapping(ac)<>bc then ' previous mapping is different - isomorphic = 0: exit function - end if - end if - next - isomorphic = 1 + dim mapping(256) as integer, mapped(256) as integer + dim i as integer, ac as integer, bc as integer + + if a="" or len(a)<>len(b) then + isomorphic = 0: exit function + end if + + for i=1 to len(a) + ac = asc(mid(a,i,1)) + bc = asc(mid(b,i,1)) + if mapping(ac)=0 then ' a is new + if mapped(bc)<>0 then ' b already mapped to some other a + isomorphic = 0: exit function + else ' store mapping + mapping(ac) = bc + mapped(bc) = 1 + end if + else ' a already occurred + if mapping(ac)<>bc then ' previous mapping is different + isomorphic = 0: exit function + end if + end if + next + isomorphic = 1 end function -print trim(str(isomorphic(command(1), command(2))))
\ No newline at end of file +print trim(str(isomorphic(command(1), command(2)))) diff --git a/challenge-092/paulo-custodio/basic/ch-2.bas b/challenge-092/paulo-custodio/basic/ch-2.bas index a974817a64..dc292b2769 100644 --- a/challenge-092/paulo-custodio/basic/ch-2.bas +++ b/challenge-092/paulo-custodio/basic/ch-2.bas @@ -19,46 +19,46 @@ redim shared timeline(1) as Boolean sub fill_timeline() - dim i as integer, j as integer, p as integer, bg as integer, ed as integer - i=1 - do while command(i)<>"" - ' parse begin,end - p=instr(command(i),",") - if p=0 then error 5 - bg=val(command(i)) - ed=val(mid(command(i),p+1)) - ' resize timeline if needed - if 2*ed>ubound(timeline) then - redim preserve timeline(2*ed+2) - end if - - ' fill interval - for j=2*bg to 2*ed - timeline(j)=true - next - i=i+1 - loop + dim i as integer, j as integer, p as integer, bg as integer, ed as integer + i=1 + do while command(i)<>"" + ' parse begin,end + p=instr(command(i),",") + if p=0 then error 5 + bg=val(command(i)) + ed=val(mid(command(i),p+1)) + ' resize timeline if needed + if 2*ed>ubound(timeline) then + redim preserve timeline(2*ed+2) + end if + + ' fill interval + for j=2*bg to 2*ed + timeline(j)=true + next + i=i+1 + loop end sub sub print_timeline() - dim i as integer - redim intervals(0) as integer - - for i=lbound(timeline) to ubound(timeline)-1 - if timeline(i)=false and timeline(i+1)=true then - redim preserve intervals(ubound(intervals)+1) - intervals(ubound(intervals))=int(i/2)+1 - elseif timeline(i)=true and timeline(i+1)=false then - redim preserve intervals(ubound(intervals)+1) - intervals(ubound(intervals))=int(i/2) - end if - next - - for i=1 to ubound(intervals) step 2 - print "(";trim(str(intervals(i)));",";trim(str(intervals(i+1)));")"; - if i+2<ubound(intervals) then print ", "; - next - print + dim i as integer + redim intervals(0) as integer + + for i=lbound(timeline) to ubound(timeline)-1 + if timeline(i)=false and timeline(i+1)=true then + redim preserve intervals(ubound(intervals)+1) + intervals(ubound(intervals))=int(i/2)+1 + elseif timeline(i)=true and timeline(i+1)=false then + redim preserve intervals(ubound(intervals)+1) + intervals(ubound(intervals))=int(i/2) + end if + next + + for i=1 to ubound(intervals) step 2 + print "(";trim(str(intervals(i)));",";trim(str(intervals(i+1)));")"; + if i+2<ubound(intervals) then print ", "; + next + print end sub ' main diff --git a/challenge-092/paulo-custodio/lua/ch-1.lua b/challenge-092/paulo-custodio/lua/ch-1.lua index d93a4c24ae..335b640620 100644 --- a/challenge-092/paulo-custodio/lua/ch-1.lua +++ b/challenge-092/paulo-custodio/lua/ch-1.lua @@ -22,36 +22,36 @@ Output: 0 --]] function split_string(str) - local t = {} - string.gsub(str, ".", function(c) table.insert(t,c) end) - return t + local t = {} + string.gsub(str, ".", function(c) table.insert(t,c) end) + return t end function isomorphic(a, b) - if #a ~= #b then - return 0 - else - local a = split_string(a) - local b = split_string(b) - local mapping = {} - local mapped = {} - - for i=1, #a do - if mapping[a[i]] == nil then -- a is new - if mapped[b[i]] ~= nil then -- b already mapped to some other a - return 0 - else -- store mapping - mapping[a[i]] = b[i] - mapped[b[i]] = 1 - end - else -- a already occurred - if mapping[a[i]] ~= b[i] then -- previous mapping is different - return 0 - end - end - end - return 1 - end + if #a ~= #b then + return 0 + else + local a = split_string(a) + local b = split_string(b) + local mapping = {} + local mapped = {} + + for i=1, #a do + if mapping[a[i]] == nil then -- a is new + if mapped[b[i]] ~= nil then -- b already mapped to some other a + return 0 + else -- store mapping + mapping[a[i]] = b[i] + mapped[b[i]] = 1 + end + else -- a already occurred + if mapping[a[i]] ~= b[i] then -- previous mapping is different + return 0 + end + end + end + return 1 + end end io.write(isomorphic(arg[1], arg[2])) diff --git a/challenge-092/paulo-custodio/lua/ch-2.lua b/challenge-092/paulo-custodio/lua/ch-2.lua index a88de5aace..5df3153e72 100644 --- a/challenge-092/paulo-custodio/lua/ch-2.lua +++ b/challenge-092/paulo-custodio/lua/ch-2.lua @@ -23,40 +23,40 @@ Output: (1,5), (7,9), (10,11) timeline = {} function fill_timeline() - for i=1,#arg do - -- parse begin,end - local bg, ed = string.match(arg[i], "(%d+),(%d+)") - bg = tonumber(bg) - ed = tonumber(ed) - - -- resize timeline if needed - while 2*ed >= #timeline do - table.insert(timeline, false) - end - - -- fill interval - for j=2*bg, 2*ed do - timeline[j] = true - end - end + for i=1,#arg do + -- parse begin,end + local bg, ed = string.match(arg[i], "(%d+),(%d+)") + bg = tonumber(bg) + ed = tonumber(ed) + + -- resize timeline if needed + while 2*ed >= #timeline do + table.insert(timeline, false) + end + + -- fill interval + for j=2*bg, 2*ed do + timeline[j] = true + end + end end function print_timeline() - -- collect intervals - local intervals = {} - for i=1, #timeline-1 do - if timeline[i] == false and timeline[i+1] == true then - table.insert(intervals, math.floor(i/2)+1) - elseif timeline[i] == true and timeline[i+1] == false then - table.insert(intervals, math.floor(i/2)) - end - end - - -- print intervals - for i=1, #intervals, 2 do - io.write("(",intervals[i],",",intervals[i+1],")") - if i+2 < #intervals then io.write(", ") end - end + -- collect intervals + local intervals = {} + for i=1, #timeline-1 do + if timeline[i] == false and timeline[i+1] == true then + table.insert(intervals, math.floor(i/2)+1) + elseif timeline[i] == true and timeline[i+1] == false then + table.insert(intervals, math.floor(i/2)) + end + end + + -- print intervals + for i=1, #intervals, 2 do + io.write("(",intervals[i],",",intervals[i+1],")") + if i+2 < #intervals then io.write(", ") end + end end fill_timeline() diff --git a/challenge-092/paulo-custodio/python/ch-1.py b/challenge-092/paulo-custodio/python/ch-1.py index 73b5d30b43..70e334812e 100644 --- a/challenge-092/paulo-custodio/python/ch-1.py +++ b/challenge-092/paulo-custodio/python/ch-1.py @@ -22,21 +22,21 @@ import sys def isomorphic(a,b): - if len(a)!=len(b): - return 0 - else: - mapping = {} - mapped = {} - for i in range(0, len(a)): - if not a[i] in mapping: # a is new - if b[i] in mapped: # b already mapped to some other a - return 0 - else: # store mapping - mapping[a[i]] = b[i] - mapped[b[i]] = 1 - else: # a already occurred - if mapping[a[i]]!=b[i]: # previous mapping is different - return 0 - return 1 + if len(a)!=len(b): + return 0 + else: + mapping = {} + mapped = {} + for i in range(0, len(a)): + if not a[i] in mapping: # a is new + if b[i] in mapped: # b already mapped to some other a + return 0 + else: # store mapping + mapping[a[i]] = b[i] + mapped[b[i]] = 1 + else: # a already occurred + if mapping[a[i]]!=b[i]: # previous mapping is different + return 0 + return 1 print(isomorp |
