aboutsummaryrefslogtreecommitdiff
path: root/challenge-100
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-02-20 01:18:05 +0000
committerGitHub <noreply@github.com>2021-02-20 01:18:05 +0000
commit2102fa481829f30d4e6ec37d04fa77f87e7e9a50 (patch)
tree158db5e61a8ba4e27e57b0feb52c6673a65af476 /challenge-100
parent468bc290d602b49bc9c51d8905d7e389e931806e (diff)
parent798c5692eb4c43474a1ba230bb93f9fdfc3fd311 (diff)
downloadperlweeklychallenge-club-2102fa481829f30d4e6ec37d04fa77f87e7e9a50.tar.gz
perlweeklychallenge-club-2102fa481829f30d4e6ec37d04fa77f87e7e9a50.tar.bz2
perlweeklychallenge-club-2102fa481829f30d4e6ec37d04fa77f87e7e9a50.zip
Merge pull request #3576 from pauloscustodio/paulo-custodio
Paulo Custodio
Diffstat (limited to 'challenge-100')
-rw-r--r--challenge-100/paulo-custodio/ada/ch_1.adb122
-rw-r--r--challenge-100/paulo-custodio/ada/ch_2.adb129
-rw-r--r--challenge-100/paulo-custodio/awk/ch-1.awk74
-rw-r--r--challenge-100/paulo-custodio/awk/ch-2.awk66
-rw-r--r--challenge-100/paulo-custodio/basic/ch-1.bas72
-rw-r--r--challenge-100/paulo-custodio/basic/ch-2.bas80
-rw-r--r--challenge-100/paulo-custodio/c/ch-1.c2
-rw-r--r--challenge-100/paulo-custodio/c/ch-2.c2
-rw-r--r--challenge-100/paulo-custodio/cpp/ch-1.cpp4
-rw-r--r--challenge-100/paulo-custodio/cpp/ch-2.cpp2
-rw-r--r--challenge-100/paulo-custodio/forth/ch-1.fs16
-rw-r--r--challenge-100/paulo-custodio/forth/ch-2.fs30
-rw-r--r--challenge-100/paulo-custodio/lua/ch-1.lua62
-rw-r--r--challenge-100/paulo-custodio/lua/ch-2.lua46
-rw-r--r--challenge-100/paulo-custodio/perl/ch-1.pl8
-rw-r--r--challenge-100/paulo-custodio/perl/ch-2.pl26
-rw-r--r--challenge-100/paulo-custodio/python/ch-1.py16
-rw-r--r--challenge-100/paulo-custodio/python/ch-2.py54
18 files changed, 519 insertions, 292 deletions
diff --git a/challenge-100/paulo-custodio/ada/ch_1.adb b/challenge-100/paulo-custodio/ada/ch_1.adb
new file mode 100644
index 0000000000..e5f362c639
--- /dev/null
+++ b/challenge-100/paulo-custodio/ada/ch_1.adb
@@ -0,0 +1,122 @@
+-- TASK #1 > Fun Time
+-- Submitted by: Mohammad S Anwar
+-- You are given a time (12 hour / 24 hour).
+--
+-- Write a script to convert the given time from 12 hour format to 24 hour format
+-- and vice versa.
+--
+-- Ideally we expect a one-liner.
+--
+-- Example 1:
+-- Input: 05:15 pm or 05:15pm
+-- Output: 17:15
+-- Example 2:
+-- Input: 19:15
+-- Output: 07:15 pm or 07:15pm
+
+with Ada.Characters.Handling; use Ada.Characters.Handling;
+with Ada.Command_Line;
+with Ada.Strings.Bounded;
+with Ada.Strings.Fixed; use Ada.Strings.Fixed;
+with Ada.Text_IO; use Ada.Text_IO; use Ada;
+
+procedure ch_1 is
+ -- command line arguments
+ package CL renames Ada.Command_Line;
+
+ -- strings
+ package SB is new Ada.Strings.Bounded.Generic_Bounded_Length(Max => 100);
+ use SB;
+
+ -- integer formatting
+ package Integer_IO is new Ada.Text_IO.Integer_IO (Integer);
+
+ -- parse time
+ procedure parse_time(text : String;
+ hour, minute : out Integer;
+ am, pm: out Boolean) is
+ p_colon, p_am, p_pm, p_end_minute : Integer := 0;
+ begin
+ -- find bounds
+ p_colon := Index(text, ":");
+
+ p_am := Index(To_Lower(text), "am");
+ if p_am > p_colon then
+ am := True;
+ else
+ am := False;
+ end if;
+
+ p_pm := Index(To_Lower(text), "pm");
+ if p_pm > p_colon then
+ pm := True;
+ else
+ pm := False;
+ end if;
+
+ p_end_minute := text'Last;
+ if p_am > p_colon then
+ p_end_minute := Integer'Min(p_end_minute, p_am-1);
+ elsif p_pm > p_colon then
+ p_end_minute := Integer'Min(p_end_minute, p_pm-1);
+ end if;
+
+ -- parse time
+ hour := Integer'Value(text(text'First .. p_colon-1));
+ minute := Integer'Value(text(p_colon+1 .. p_end_minute));
+
+ -- convert 12->24
+ if am then
+ if hour = 12 then
+ hour := 0;
+ end if;
+ elsif pm then
+ if hour /= 12 then
+ hour := hour + 12;
+ end if;
+ end if;
+ end parse_time;
+
+ -- output hh:mm
+ procedure print_hhmm(hour, minute: Integer) is
+ begin
+ if hour < 10 then
+ Integer_IO.Put(0, 0);
+ end if;
+ Integer_IO.Put(hour, 0);
+ Text_IO.Put(":");
+ if minute < 10 then
+ Integer_IO.Put(0, 0);
+ end if;
+ Integer_IO.Put(minute, 0);
+ end print_hhmm;
+
+ -- convert time
+ procedure convert_time(text: String) is
+ hour, minute : Integer := 0;
+ am, pm : Boolean := False;
+ ampm : String := "am";
+ begin
+ parse_time(text, hour, minute, am, pm);
+
+ if not (am or pm) then
+ -- convert 24->12
+ if hour = 0 then
+ hour := 12;
+ elsif hour = 12 then
+ ampm := "pm";
+ elsif hour > 12 then
+ hour := hour - 12;
+ ampm := "pm";
+ end if;
+
+ print_hhmm(hour, minute);
+ Text_IO.Put(ampm);
+ else
+ print_hhmm(hour, minute);
+ end if;
+ end convert_time;
+
+begin
+ convert_time(CL.Argument(1));
+end ch_1;
diff --git a/challenge-100/paulo-custodio/ada/ch_2.adb b/challenge-100/paulo-custodio/ada/ch_2.adb
new file mode 100644
index 0000000000..36d95ef473
--- /dev/null
+++ b/challenge-100/paulo-custodio/ada/ch_2.adb
@@ -0,0 +1,129 @@
+-- TASK #2 > Triangle Sum
+-- Submitted by: Mohammad S Anwar
+-- You are given triangle array.
+--
+-- Write a script to find the minimum path sum from top to bottom.
+--
+-- When you are on index i on the current row then you may move to either
+-- index i or index i + 1 on the next row.
+--
+-- Example 1:
+-- Input: Triangle = [ [1], [2,4], [6,4,9], [5,1,7,2] ]
+-- Output: 8
+--
+-- Explanation: The given triangle
+--
+-- 1
+-- 2 4
+-- 6 4 9
+-- 5 1 7 2
+--
+-- The minimum path sum from top to bottom: 1 + 2 + 4 + 1 = 8
+--
+-- [1]
+-- [2] 4
+-- 6 [4] 9
+-- 5 [1] 7 2
+-- Example 2:
+-- Input: Triangle = [ [3], [3,1], [5,2,3], [4,3,1,3] ]
+-- Output: 7
+--
+-- Explanation: The given triangle
+--
+-- 3
+-- 3 1
+-- 5 2 3
+-- 4 3 1 3
+--
+-- The minimum path sum from top to bottom: 3 + 1 + 2 + 1 = 7
+--
+-- [3]
+-- 3 [1]
+-- 5 [2] 3
+-- 4 3 [1] 3
+
+with Ada.Command_Line;
+with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
+with Ada.Strings.Fixed; use Ada.Strings.Fixed;
+with Ada.Text_IO; use Ada.Text_IO;
+use Ada;
+
+procedure ch_2 is
+ -- command line arguments
+ package CL renames Ada.Command_Line;
+
+ -- integer formatting
+ package Integer_IO is new Ada.Text_IO.Integer_IO (Integer);
+
+ -- triangle data
+ Max_Rows : constant Integer := 20;
+ triangle : array(1 .. Max_Rows, 1 .. Max_Rows) of Integer;
+ rows : Integer := 0;
+
+ -- parse number
+ function parse_number(text : in out String) return Integer is
+ i : Integer;
+ value : Integer := 0;
+ begin
+ -- skip non-digits
+ i := text'First;
+ while text(i) < '0' or text(i) > '9' loop
+ i := i + 1;
+ end loop;
+
+ -- find end of digits and parse value
+ while i <= text'Last loop
+ if text(i) >= '0' and text(i) <= '9' then
+ if i = text'Last then
+ value := Integer'Value(text);
+ Delete(text, text'First, text'Last);
+ exit;
+ else
+ i := i + 1;
+ end if;
+ else
+ value := Integer'Value(text(text'First .. i-1));
+ Delete(text, Text'First, i);
+ exit;
+ end if;
+ end loop;
+
+ return value;
+ end parse_number;
+
+ -- add row
+ procedure add_row(row : Integer; text1 : String) is
+ n : Integer;
+ text : String := text1;
+ begin
+ rows := row;
+ for col in 1 .. row loop
+ n := parse_number(text);
+ triangle(row, col) := n;
+ end loop;
+ end add_row;
+
+ -- compute minimum sum
+ function min_sum return Integer is
+ function min_sum_1(sum, row, col : Integer) return Integer is
+ sum0, sum1, sum2 : Integer;
+ begin
+ sum0 := sum + triangle(row, col);
+ if row = rows then
+ return sum0;
+ else
+ sum1 := min_sum_1(sum0, row+1, col);
+ sum2 := min_sum_1(sum0, row+1, col+1);
+ return Integer'Min(sum1, sum2);
+ end if;
+ end min_sum_1;
+ begin
+ return min_sum_1(0, 1, 1);
+ end min_sum;
+
+begin
+ for i in 1 .. CL.Argument_Count loop
+ add_row(i, CL.Argument(I));
+ end loop;
+ Integer_IO.Put(min_sum, 0);
+end ch_2;
diff --git a/challenge-100/paulo-custodio/awk/ch-1.awk b/challenge-100/paulo-custodio/awk/ch-1.awk
index 07cba14123..83c0caffe6 100644
--- a/challenge-100/paulo-custodio/awk/ch-1.awk
+++ b/challenge-100/paulo-custodio/awk/ch-1.awk
@@ -1,16 +1,14 @@
#!/usr/bin/gawk
-# Challenge 100
-#
# TASK #1 > Fun Time
# Submitted by: Mohammad S Anwar
# You are given a time (12 hour / 24 hour).
-#
+#
# Write a script to convert the given time from 12 hour format to 24 hour format
# and vice versa.
-#
+#
# Ideally we expect a one-liner.
-#
+#
# Example 1:
# Input: 05:15 pm or 05:15pm
# Output: 17:15
@@ -19,39 +17,39 @@
# Output: 07:15 pm or 07:15pm
function convert_time(text, hour, arr, pm) {
- text = tolower(text)
-
- # get hour
- match(text, /^([0-9]+)/, arr)
- hour = arr[1]
- if (text ~ /am|pm/) {
- # 12->24
- if (text ~ /pm/) {
- if (hour < 12) hour += 12;
- }
- else { /am/
- if (hour == 12) hour = 0;
- }
- gsub(/^[0-9]+/, "", text);
- gsub(/ *(am|pm)/, "", text);
- printf("%02d", hour); print text;
- }
- else {
- # 24->12
- pm = 0;
- if (hour == 0) hour = 12;
- else if (hour == 12) pm = 1;
- else if (hour > 12) { hour -= 12; pm = 1; }
- gsub(/^[0-9]+/, "", text);
- printf("%02d%s", hour, text);
- if (pm)
- print "pm";
- else
- print "am";
- }
+ text = tolower(text)
+
+ # get hour
+ match(text, /^([0-9]+)/, arr)
+ hour = arr[1]
+ if (text ~ /am|pm/) {
+ # 12->24
+ if (text ~ /pm/) {
+ if (hour < 12) hour += 12;
+ }
+ else { /am/
+ if (hour == 12) hour = 0;
+ }
+ gsub(/^[0-9]+/, "", text);
+ gsub(/ *(am|pm)/, "", text);
+ printf("%02d", hour); print text;
+ }
+ else {
+ # 24->12
+ pm = 0;
+ if (hour == 0) hour = 12;
+ else if (hour == 12) pm = 1;
+ else if (hour > 12) { hour -= 12; pm = 1; }
+ gsub(/^[0-9]+/, "", text);
+ printf("%02d%s", hour, text);
+ if (pm)
+ print "pm";
+ else
+ print "am";
+ }
}
BEGIN {
- convert_time(ARGV[1]);
- exit 0;
-} \ No newline at end of file
+ convert_time(ARGV[1]);
+ exit 0;
+}
diff --git a/challenge-100/paulo-custodio/awk/ch-2.awk b/challenge-100/paulo-custodio/awk/ch-2.awk
index aefd2cf858..77fac41676 100644
--- a/challenge-100/paulo-custodio/awk/ch-2.awk
+++ b/challenge-100/paulo-custodio/awk/ch-2.awk
@@ -1,29 +1,27 @@
#!/usr/bin/gawk
-# Challenge 100
-#
# TASK #2 > Triangle Sum
# Submitted by: Mohammad S Anwar
# You are given triangle array.
-#
+#
# Write a script to find the minimum path sum from top to bottom.
-#
-# When you are on index i on the current row then you may move to either
+#
+# When you are on index i on the current row then you may move to either
# index i or index i + 1 on the next row.
-#
+#
# Example 1:
# Input: Triangle = [ [1], [2,4], [6,4,9], [5,1,7,2] ]
# Output: 8
-#
+#
# Explanation: The given triangle
-#
+#
# 1
# 2 4
# 6 4 9
# 5 1 7 2
-#
+#
# The minimum path sum from top to bottom: 1 + 2 + 4 + 1 = 8
-#
+#
# [1]
# [2] 4
# 6 [4] 9
@@ -31,40 +29,40 @@
# Example 2:
# Input: Triangle = [ [3], [3,1], [5,2,3], [4,3,1,3] ]
# Output: 7
-#
+#
# Explanation: The given triangle
-#
+#
# 3
# 3 1
# 5 2 3
# 4 3 1 3
-#
+#
# The minimum path sum from top to bottom: 3 + 1 + 2 + 1 = 7
-#
+#
# [3]
# 3 [1]
# 5 [2] 3
# 4 3 [1] 3
function add_row(row, text, i, arr) {
- rows = row;
- for (i = 1; i <= row; i++) {
- gsub(/^[^0-9]*/, "", text);
- match(text, /^([0-9]+)/, arr);
- triangle[row][i] = arr[1];
- gsub(/^[0-9]*/, "", text);
- }
+ rows = row;
+ for (i = 1; i <= row; i++) {
+ gsub(/^[^0-9]*/, "", text);
+ match(text, /^([0-9]+)/, arr);
+ triangle[row][i] = arr[1];
+ gsub(/^[0-9]*/, "", text);
+ }
}
function min_sum_1(sum, row, col, sum1, sum2) {
- sum += triangle[row][col];
- if (row == rows)
- return sum;
- else {
- sum1 = min_sum_1(sum, row+1, col);
- sum2 = min_sum_1(sum, row+1, col+1);
- return (sum1 < sum2) ? sum1 : sum2;
- }
+ sum += triangle[row][col];
+ if (row == rows)
+ return sum;
+ else {
+ sum1 = min_sum_1(sum, row+1, col);
+ sum2 = min_sum_1(sum, row+1, col+1);
+ return (sum1 < sum2) ? sum1 : sum2;
+ }
}
function min_sum() {
@@ -72,9 +70,9 @@ function min_sum() {
}
BEGIN {
- rows = 0;
- for (i = 1; i < ARGC; i++)
- add_row(i, ARGV[i]);
- print min_sum();
- exit 0;
+ rows = 0;
+ for (i = 1; i < ARGC; i++)
+ add_row(i, ARGV[i]);
+ print min_sum();
+ exit 0;
}
diff --git a/challenge-100/paulo-custodio/basic/ch-1.bas b/challenge-100/paulo-custodio/basic/ch-1.bas
index 7c2b970b32..35cc526535 100644
--- a/challenge-100/paulo-custodio/basic/ch-1.bas
+++ b/challenge-100/paulo-custodio/basic/ch-1.bas
@@ -1,14 +1,14 @@
' Challenge 100
-'
+'
' TASK #1 > Fun Time
' Submitted by: Mohammad S Anwar
' You are given a time (12 hour / 24 hour).
-'
+'
' Write a script to convert the given time from 12 hour format to 24 hour format
' and vice versa.
-'
+'
' Ideally we expect a one-liner.
-'
+'
' Example 1:
' Input: 05:15 pm or 05:15pm
' Output: 17:15
@@ -17,40 +17,40 @@
' Output: 07:15 pm or 07:15pm
function format_nn(n as integer) as string
- format_nn = right("00" & trim(str(n)), 2)
-end function
+ format_nn = right("00" & trim(str(n)), 2)
+end function
function convert_time(text as string) as string
- dim hour as integer, minute as integer, am as boolean, pm as boolean
- dim ampm as string
-
- text = lcase(text)
- hour = val(text)
- minute = val(mid(text, instr(text, ":")+1))
- if instr(text, "am") > 0 then am = true
- if instr(text, "pm") > 0 then pm = true
- if am or pm then
- ' 12->24
- if pm then
- if hour < 12 then hour = hour + 12
- else
- if hour = 12 then hour = 0
- end if
- convert_time = format_nn(hour) & ":" & format_nn(minute)
- else
- ' 24->12
-
- ampm = "am"
- if hour = 0 then
- hour = 12
- elseif hour = 12 then
- ampm = "pm"
- elseif hour > 12 then
- hour = hour - 12
- ampm = "pm"
- end if
- convert_time = format_nn(hour) & ":" & format_nn(minute) & ampm
- end if
+ dim hour as integer, minute as integer, am as boolean, pm as boolean
+ dim ampm as string
+
+ text = lcase(text)
+ hour = val(text)
+ minute = val(mid(text, instr(text, ":")+1))
+ if instr(text, "am") > 0 then am = true
+ if instr(text, "pm") > 0 then pm = true
+ if am or pm then
+ ' 12->24
+ if pm then
+ if hour < 12 then hour = hour + 12
+ else
+ if hour = 12 then hour = 0
+ end if
+ convert_time = format_nn(hour) & ":" & format_nn(minute)
+ else
+ ' 24->12
+
+ ampm = "am"
+ if hour = 0 then
+ hour = 12
+ elseif hour = 12 then
+ ampm = "pm"
+ elseif hour > 12 then
+ hour = hour - 12
+ ampm = "pm"
+ end if
+ convert_time = format_nn(hour) & ":" & format_nn(minute) & ampm
+ end if
end function
print convert_time(command(1))
diff --git a/challenge-100/paulo-custodio/basic/ch-2.bas b/challenge-100/paulo-custodio/basic/ch-2.bas
index 07a9496a04..6ba0800802 100644
--- a/challenge-100/paulo-custodio/basic/ch-2.bas
+++ b/challenge-100/paulo-custodio/basic/ch-2.bas
@@ -1,25 +1,25 @@
' TASK #2 > Triangle Sum
' Submitted by: Mohammad S Anwar
' You are given triangle array.
-'
+'
' Write a script to find the minimum path sum from top to bottom.
-'
-' When you are on index i on the current row then you may move to either
+'
+' When you are on index i on the current row then you may move to either
' index i or index i + 1 on the next row.
-'
+'
' Example 1:
' Input: Triangle = [ [1], [2,4], [6,4,9], [5,1,7,2] ]
' Output: 8
-'
+'
' Explanation: The given triangle
-'
+'
' 1
' 2 4
' 6 4 9
' 5 1 7 2
-'
+'
' The minimum path sum from top to bottom: 1 + 2 + 4 + 1 = 8
-'
+'
' [1]
' [2] 4
' 6 [4] 9
@@ -27,16 +27,16 @@
' Example 2:
' Input: Triangle = [ [3], [3,1], [5,2,3], [4,3,1,3] ]
' Output: 7
-'
+'
' Explanation: The given triangle
-'
+'
' 3
' 3 1
' 5 2 3
' 4 3 1 3
-'
+'
' The minimum path sum from top to bottom: 3 + 1 + 2 + 1 = 7
-'
+'
' [3]
' 3 [1]
' 5 [2] 3
@@ -47,45 +47,45 @@ const as integer MAX_ROWS = 20
dim shared rows as integer
sub add_row(row as integer, text as string)
- dim as integer i, n
- rows = row
- for i = 1 to row
- do while left(text,1)<"0" or left(text,1)>"9"
- text = mid(text,2)
- loop
- n = val(text)
- do while left(text,1)>="0" and left(text,1)<="9"
- text = mid(text,2)
- loop
- triangle(row, i) = n
- next i
+ dim as integer i, n
+ rows = row
+ for i = 1 to row
+ do while left(text,1)<"0" or left(text,1)>"9"
+ text = mid(text,2)
+ loop
+ n = val(text)
+ do while left(text,1)>="0" and left(text,1)<="9"
+ text = mid(text,2)
+ loop
+ triangle(row, i) = n
+ next i
end sub
function min_sum_1(sum as integer, row as integer, col as integer) as integer
- dim as integer sum1, sum2
- sum = sum + triangle(row, col)
- if row = rows then
- min_sum_1 = sum
- else
- sum1 = min_sum_1(sum, row+1, col)
- sum2 = min_sum_1(sum, row+1, col+1)
- if sum1 < sum2 then
- min_sum_1 = sum1
- else
- min_sum_1 = sum2
- end if
- end if
+ dim as integer sum1, sum2
+ sum = sum + triangle(row, col)
+ if row = rows then
+ min_sum_1 = sum
+ else
+ sum1 = min_sum_1(sum, row+1, col)
+ sum2 = min_sum_1(sum, row+1, col+1)
+ if sum1 < sum2 then
+ min_sum_1 = sum1
+ else
+ min_sum_1 = sum2
+ end if
+ end if
end function
function min_sum() as integer
- min_sum = min_sum_1(0, 1, 1)
+ min_sum = min_sum_1(0, 1, 1)
end function
dim i as integer
i = 1
do while command(i) <> ""
- add_row(i, command(i))
- i = i + 1
+ add_row(i, command(i))
+ i = i + 1
loop
print trim(str(min_sum()))
diff --git a/challenge-100/paulo-custodio/c/ch-1.c b/challenge-100/paulo-custodio/c/ch-1.c
index 9638b7d656..d0a33a1f36 100644
--- a/challenge-100/paulo-custodio/c/ch-1.c
+++ b/challenge-100/paulo-custodio/c/ch-1.c
@@ -1,6 +1,4 @@
/*
-Challenge 100
-
TASK #1 > Fun Time
Submitted by: Mohammad S Anwar
You are given a time (12 hour / 24 hour).
diff --git a/challenge-100/paulo-custodio/c/ch-2.c b/challenge-100/paulo-custodio/c/ch-2.c
index 6a772d3a01..1d68e1d2d6 100644
--- a/challenge-100/paulo-custodio/c/ch-2.c
+++ b/challenge-100/paulo-custodio/c/ch-2.c
@@ -1,6 +1,4 @@
/*
-Challenge 100
-
TASK #2 > Triangle Sum
Submitted by: Mohammad S Anwar
You are given triangle array.
diff --git a/challenge-100/paulo-custodio/cpp/ch-1.cpp b/challenge-100/paulo-custodio/cpp/ch-1.cpp
index 9f4bcbd5e5..0516a4bd31 100644
--- a/challenge-100/paulo-custodio/cpp/ch-1.cpp
+++ b/challenge-100/paulo-custodio/cpp/ch-1.cpp
@@ -1,6 +1,4 @@
/*
-Challenge 100
-
TASK #1 > Fun Time
Submitted by: Mohammad S Anwar
You are given a time (12 hour / 24 hour).
@@ -74,7 +72,7 @@ std::istream& operator>>(std::istream& is, Time& time) {
// get optional am|pm
std::string ampm;
- is >> ampm;
+ is >> ampm;
// convert from 12 to 24 format
if (!ampm.empty()) {
diff --git a/challenge-100/paulo-custodio/cpp/ch-2.cpp b/challenge-100/paulo-custodio/cpp/ch-2.cpp
index c94b0355a3..b672a5cffe 100644
--- a/challenge-100/paulo-custodio/cpp/ch-2.cpp
+++ b/challenge-100/paulo-custodio/cpp/ch-2.cpp
@@ -1,6 +1,4 @@
/*
-Challenge 100
-
TASK #2 > Triangle Sum
Submitted by: Mohammad S Anwar
You are given triangle array.
diff --git a/challenge-100/paulo-custodio/forth/ch-1.fs b/challenge-100/paulo-custodio/forth/ch-1.fs
index fe0e8f1e76..a4008e5be2 100644
--- a/challenge-100/paulo-custodio/forth/ch-1.fs
+++ b/challenge-100/paulo-custodio/forth/ch-1.fs
@@ -1,15 +1,13 @@
#! /usr/bin/env gforth
-\ Challenge 100
-\
\ TASK #1 > Fun Time
\ Submitted by: Mohammad S Anwar
\ You are given a time (12 hour / 24 hour).
-\
+\
\ Write a script to convert the given time from 12 hour format to 24 hour format and vice versa.
-\
+\
\ Ideally we expect a one-liner.
-\
+\
\ Example 1:
\ Input: 05:15 pm or 05:15pm
\ Output: 17:15
@@ -26,7 +24,7 @@
AGAIN
;
-\ parse a time string, return number of minutes since midnight
+\ parse a time string, return number of minutes since midnight
\ and true if it was in AM/PM format
: parse-time { str len -- hours minutes f-am-pm }
0 0 { hours minutes }
@@ -56,12 +54,12 @@
: print12 { hours minutes -- }
FALSE { pm } \ assume AM
- hours DUP 12 > IF
+ hours DUP 12 > IF
DROP hours 12 - TO hours TRUE TO pm ELSE
- DUP 12 = IF
+ DUP 12 = IF
DROP TRUE TO pm ELSE
DUP 0= IF
- DROP 12 TO HOURS
+ DROP 12 TO HOURS
ELSE DROP THEN THEN THEN
hours minutes print24
diff --git a/challenge-100/paulo-custodio/forth/ch-2.fs b/challenge-100/paulo-custodio/forth/ch-2.fs
index 54939601a9..7592af483c 100644
--- a/challenge-100/paulo-custodio/forth/ch-2.fs
+++ b/challenge-100/paulo-custodio/forth/ch-2.fs
@@ -1,29 +1,27 @@
#! /usr/bin/env gforth
-\ Challenge 100
-\
\ TASK #2 > Triangle Sum
\ Submitted by: Mohammad S Anwar
\ You are given triangle array.
-\
+\
\ Write a script to find the minimum path sum from top to bottom.
-\
-\ When you are on index i on the current row then you may move to either
+\
+\ When you are on index i on the current row then you may move to either
\ index i or index i + 1 on the next row.
-\
+\
\ Example 1:
\ Input: Triangle = [ [1], [2,4], [6,4,9], [5,1,7,2] ]
\ Output: 8
-\
+\
\ Explanation: The given triangle
-\
+\
\ 1
\ 2 4
\ 6 4 9
\ 5 1 7 2
-\
+\
\ The minimum path sum from top to bottom: 1 + 2 + 4 + 1 = 8
-\
+\
\ [1]
\ [2] 4
\ 6 [4] 9
@@ -31,16 +29,16 @@
\ Example 2:
\ Input: Triangle = [ [3], [3,1], [5,2,3], [4,3,1,3] ]
\ Output: 7
-\
+\
\ Explanation: The given triangle
-\
+\
\ 3
\ 3 1
\ 5 2 3
\ 4 3 1 3
-\
+\
\ The minimum path sum from top to bottom: 3 + 1 + 2 + 1 = 7
-\
+\
\ [3]
\ 3 [1]
\ 5 [2] 3
@@ -80,7 +78,7 @@ CREATE triangle max-height DUP * CELLS ALLOT
\ parse and store triangle
: parse-triangle ( -- )
- -1 TO last-row
+ -1 TO last-row
BEGIN NEXT-ARG DUP 0> WHILE
parse-line
REPEAT 2DROP
@@ -92,7 +90,7 @@ CREATE triangle max-height DUP * CELLS ALLOT
row col triangle[] @ sum + TO sum
row last-row = IF
sum
- ELSE
+ ELSE
sum row 1+ col RECURSE \ compute left sum
sum row 1+ col 1+ RECURSE \ comppute right sum
MIN
diff --git a/challenge-100/paulo-custodio/lua/ch-1.lua b/challenge-100/paulo-custodio/lua/ch-1.lua
index 69527e9fe2..f83035128c 100644
--- a/challenge-100/paulo-custodio/lua/ch-1.lua
+++ b/challenge-100/paulo-custodio/lua/ch-1.lua
@@ -21,37 +21,37 @@ Output: 07:15 pm or 07:15pm
--]]
function convert_time(text)
- text = string.lower(text)
- local hour, minute = string.match(text, "(%d+):(%d+)")
- hour = tonumber(hour)
- minute = tonumber(minute)
- local am = string.match(text, "am")
- local pm = string.match(text, "pm")
- if am or pm then
- -- 12->24
- if pm then
- if hour < 12 then
- hour = hour + 12
- end
- else
- if hour == 12 then
- hour = 0
- end
- end
- return string.format("%02d:%02d", hour, minute)
- else
- -- 24->12
- local ampm = "am"
- if hour == 0 then
- hour = 12
- elseif hour == 12 then
- ampm = "pm"
- elseif hour > 12 then
- hour = hour - 12
- ampm = "pm"
- end
- return string.format("%02d:%02d%s", hour, minute, ampm)
- end
+ text = string.lower(text)
+ local hour, minute = string.match(text, "(%d+):(%d+)")
+ hour = tonumber(hour)
+ minute = tonumber(minute)
+ local am = string.match(text, "am")
+ local pm = string.match(text, "pm")
+ if am or pm then
+ -- 12->24
+ if pm then
+ if hour < 12 then
+ hour = hour + 12
+ end
+ else
+ if hour == 12 then
+ hour = 0
+ end
+ end
+ return string.format("%02d:%02d", hour, minute)
+ else
+ -- 24->12
+ local ampm = "am"
+ if hour == 0 then
+ hour = 12
+ elseif hour == 12 then
+ ampm = "pm"
+ elseif hour > 12 then
+ hour = hour - 12
+ ampm = "pm"
+ end
+ return string.format("%02d:%02d%s", hour, minute, ampm)
+ end
end
io.write(convert_time(arg[1]))
diff --git a/challenge-100/paulo-custodio/lua/ch-2.lua b/challenge-100/paulo-custodio/lua/ch-2.lua
index c8da806390..9f917fe53a 100644
--- a/challenge-100/paulo-custodio/lua/ch-2.lua
+++ b/challenge-100/paulo-custodio/lua/ch-2.lua
@@ -7,7 +7,7 @@ You are given triangle array.
Write a script to find the minimum path sum from top to bottom.
-When you are on index i on the current row then you may move to either
+When you are on index i on the current row then you may move to either
index i or index i + 1 on the next row.
Example 1:
@@ -48,32 +48,32 @@ The minimum path sum from top to bottom: 3 + 1 + 2 + 1 = 7
<