From 38d82321ddc0f1b10d9c8e97ebbcbfbfa5d5a8d9 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Thu, 2 Mar 2023 21:32:53 +0000 Subject: whitespace --- challenge-204/paulo-custodio/c/ch-1.c | 40 ++++++++-------- challenge-204/paulo-custodio/c/ch-2.c | 74 +++++++++++++++--------------- challenge-204/paulo-custodio/cpp/ch-1.cpp | 36 +++++++-------- challenge-204/paulo-custodio/cpp/ch-2.cpp | 62 ++++++++++++------------- challenge-204/paulo-custodio/perl/ch-1.pl | 44 +++++++++--------- challenge-204/paulo-custodio/perl/ch-2.pl | 62 ++++++++++++------------- challenge-204/paulo-custodio/t/test-1.yaml | 7 ++- challenge-204/paulo-custodio/t/test-2.yaml | 6 +-- 8 files changed, 165 insertions(+), 166 deletions(-) diff --git a/challenge-204/paulo-custodio/c/ch-1.c b/challenge-204/paulo-custodio/c/ch-1.c index fb1bac1842..83f6c3e260 100644 --- a/challenge-204/paulo-custodio/c/ch-1.c +++ b/challenge-204/paulo-custodio/c/ch-1.c @@ -30,33 +30,33 @@ Input: @nums = (6,5,5,4) Output: 1 */ -#define MAX_DATA 1024 +#define MAX_DATA 1024 #include #include #include int is_monotonic(int size, int data[]) { - if (size < 2) - return 1; - else { - int climb = 0, descend = 0; - for (int i = 0; i < size - 1; i++) { - int delta = data[i+1]-data[i]; - if (delta > 0) climb++; - else if (delta < 0) descend++; - if (climb && descend) return 0; - } - return 1; - } + if (size < 2) + return 1; + else { + int climb = 0, descend = 0; + for (int i = 0; i < size - 1; i++) { + int delta = data[i+1]-data[i]; + if (delta > 0) climb++; + else if (delta < 0) descend++; + if (climb && descend) return 0; + } + return 1; + } } int main(int argc, char* argv[]) { - argv++; argc--; - assert(argc <= MAX_DATA); - int data[MAX_DATA]; - - for (int i = 0; i < argc; i++) - data[i] = atoi(argv[i]); - printf("%d\n", is_monotonic(argc, data)); + argv++; argc--; + assert(argc <= MAX_DATA); + int data[MAX_DATA]; + + for (int i = 0; i < argc; i++) + data[i] = atoi(argv[i]); + printf("%d\n", is_monotonic(argc, data)); } diff --git a/challenge-204/paulo-custodio/c/ch-2.c b/challenge-204/paulo-custodio/c/ch-2.c index d722b21321..2a25716deb 100644 --- a/challenge-204/paulo-custodio/c/ch-2.c +++ b/challenge-204/paulo-custodio/c/ch-2.c @@ -45,8 +45,8 @@ Input: [ 1 2 ] Output: 0 */ -#define MAX_DATA 1024 -#define BLANKS " \t\r\n\v\f" +#define MAX_DATA 1024 +#define BLANKS " \t\r\n\v\f" #include #include @@ -56,45 +56,45 @@ Output: 0 int data[MAX_DATA], size = 0, rows = 0, cols = 0; void parse_data() { - char line[MAX_DATA], *p; - while (fgets(line, sizeof(line), stdin)) { - if (strchr(line, '[') != NULL) { - while ((p = strchr(line, '[')) != NULL) *p = ' '; - while ((p = strchr(line, ']')) != NULL) *p = ' '; - char* p = strtok(line, BLANKS); - while (p) { - assert(size < MAX_DATA); - data[size++] = atoi(p); - p = strtok(NULL, BLANKS); - } - } - else { - char* p = strtok(line, BLANKS); - assert(p); - rows = atoi(p); - p = strtok(NULL, BLANKS); - assert(p); - cols = atoi(p); - break; - } - } + char line[MAX_DATA], *p; + while (fgets(line, sizeof(line), stdin)) { + if (strchr(line, '[') != NULL) { + while ((p = strchr(line, '[')) != NULL) *p = ' '; + while ((p = strchr(line, ']')) != NULL) *p = ' '; + char* p = strtok(line, BLANKS); + while (p) { + assert(size < MAX_DATA); + data[size++] = atoi(p); + p = strtok(NULL, BLANKS); + } + } + else { + char* p = strtok(line, BLANKS); + assert(p); + rows = atoi(p); + p = strtok(NULL, BLANKS); + assert(p); + cols = atoi(p); + break; + } + } } void output_data() { - if (size != rows*cols) - printf("0\n"); - else { - for (int i = 0; i < rows; i++) { - printf("[ "); - for (int j = 0; j < cols; j++) { - printf("%d ", data[i*cols+j]); - } - printf("]\n"); - } - } + if (size != rows*cols) + printf("0\n"); + else { + for (int i = 0; i < rows; i++) { + printf("[ "); + for (int j = 0; j < cols; j++) { + printf("%d ", data[i*cols+j]); + } + printf("]\n"); + } + } } int main() { - parse_data(); - output_data(); + parse_data(); + output_data(); } diff --git a/challenge-204/paulo-custodio/cpp/ch-1.cpp b/challenge-204/paulo-custodio/cpp/ch-1.cpp index e877007577..116518bb22 100644 --- a/challenge-204/paulo-custodio/cpp/ch-1.cpp +++ b/challenge-204/paulo-custodio/cpp/ch-1.cpp @@ -34,25 +34,25 @@ Output: 1 #include int is_monotonic(const std::vector& data) { - if (data.size() < 2) - return 1; - else { - int climb = 0, descend = 0; - for (size_t i = 0; i < data.size() - 1; i++) { - int delta = data[i+1]-data[i]; - if (delta > 0) climb++; - else if (delta < 0) descend++; - if (climb && descend) return 0; - } - return 1; - } + if (data.size() < 2) + return 1; + else { + int climb = 0, descend = 0; + for (size_t i = 0; i < data.size() - 1; i++) { + int delta = data[i+1]-data[i]; + if (delta > 0) climb++; + else if (delta < 0) descend++; + if (climb && descend) return 0; + } + return 1; + } } int main(int argc, char* argv[]) { - argv++; argc--; - std::vector data; - - for (int i = 0; i < argc; i++) - data.push_back(atoi(argv[i])); - std::cout << is_monotonic(data) << std::endl; + argv++; argc--; + std::vector data; + + for (int i = 0; i < argc; i++) + data.push_back(atoi(argv[i])); + std::cout << is_monotonic(data) << std::endl; } diff --git a/challenge-204/paulo-custodio/cpp/ch-2.cpp b/challenge-204/paulo-custodio/cpp/ch-2.cpp index 331715e1c7..0904357163 100644 --- a/challenge-204/paulo-custodio/cpp/ch-2.cpp +++ b/challenge-204/paulo-custodio/cpp/ch-2.cpp @@ -54,41 +54,41 @@ std::vector data; size_t rows = 0, cols = 0; void parse_data() { - std::string line; - while (std::getline(std::cin, line)) { - if (line.find('[') != std::string::npos) { - size_t pos; - while ((pos = line.find('[')) != std::string::npos) line[pos] = ' '; - while ((pos = line.find(']')) != std::string::npos) line[pos] = ' '; - std::istringstream iss{ line }; - int n; - while (iss >> n) { - data.push_back(n); - } - } - else { - std::istringstream iss{ line }; - iss >> rows >> cols; - break; - } - } + std::string line; + while (std::getline(std::cin, line)) { + if (line.find('[') != std::string::npos) { + size_t pos; + while ((pos = line.find('[')) != std::string::npos) line[pos] = ' '; + while ((pos = line.find(']')) != std::string::npos) line[pos] = ' '; + std::istringstream iss{ line }; + int n; + while (iss >> n) { + data.push_back(n); + } + } + else { + std::istringstream iss{ line }; + iss >> rows >> cols; + break; + } + } } void output_data() { - if (data.size() != rows*cols) - std::cout << "0" << std::endl; - else { - for (int i = 0; i < rows; i++) { - std::cout << "[ "; - for (int j = 0; j < cols; j++) { - std::cout << data[i*cols+j] << " "; - } - std::cout << "]" << std::endl; - } - } + if (data.size() != rows*cols) + std::cout << "0" << std::endl; + else { + for (int i = 0; i < rows; i++) { + std::cout << "[ "; + for (int j = 0; j < cols; j++) { + std::cout << data[i*cols+j] << " "; + } + std::cout << "]" << std::endl; + } + } } int main() { - parse_data(); - output_data(); + parse_data(); + output_data(); } diff --git a/challenge-204/paulo-custodio/perl/ch-1.pl b/challenge-204/paulo-custodio/perl/ch-1.pl index 9dbd93f7a4..a71fd4767b 100644 --- a/challenge-204/paulo-custodio/perl/ch-1.pl +++ b/challenge-204/paulo-custodio/perl/ch-1.pl @@ -4,46 +4,46 @@ # # Task 1: Monotonic Array # Submitted by: Mohammad S Anwar -# +# # You are given an array of integers. -# +# # Write a script to find out if the given array is Monotonic. Print 1 if it is otherwise 0. -# +# # An array is Monotonic if it is either monotone increasing or decreasing. -# +# # Monotone increasing: for i <= j , nums[i] <= nums[j] # Monotone decreasing: for i <= j , nums[i] >= nums[j] -# -# +# +# # Example 1 -# +# # Input: @nums = (1,2,2,3) # Output: 1 -# +# # Example 2 -# +# # Input: @nums = (1,3,2) # Output: 0 -# +# # Example 3 -# +# # Input: @nums = (6,5,5,4) # Output: 1 use Modern::Perl; sub is_monotonic { - my(@list) = @_; - return 1 if @list < 2; - my $climb = 0; - my $descend = 0; - for my $i (0..$#list-1) { - my $delta = $list[$i+1]-$list[$i]; - if ($delta > 0) { $climb++; } - elsif ($delta < 0) { $descend++; } - if ($climb && $descend) { return 0; } - } - return 1; + my(@list) = @_; + return 1 if @list < 2; + my $climb = 0; + my $descend = 0; + for my $i (0..$#list-1) { + my $delta = $list[$i+1]-$list[$i]; + if ($delta > 0) { $climb++; } + elsif ($delta < 0) { $descend++; } + if ($climb && $descend) { return 0; } + } + return 1; } say is_monotonic(@ARGV); diff --git a/challenge-204/paulo-custodio/perl/ch-2.pl b/challenge-204/paulo-custodio/perl/ch-2.pl index dcd0fadaab..9a5b64567b 100644 --- a/challenge-204/paulo-custodio/perl/ch-2.pl +++ b/challenge-204/paulo-custodio/perl/ch-2.pl @@ -1,48 +1,48 @@ #!/usr/bin/perl # Challenge 204 -# +# # Task 2: Reshape Matrix # Submitted by: Mohammad S Anwar -# +# # You are given a matrix (m x n) and two integers (r) and (c). -# +# # Write a script to reshape the given matrix in form (r x c) with the original value in the given matrix. If you can’t reshape print 0. -# +# # Example 1 -# +# # Input: [ 1 2 ] # [ 3 4 ] -# +# # $matrix = [ [ 1, 2 ], [ 3, 4 ] ] # $r = 1 # $c = 4 -# +# # Output: [ 1 2 3 4 ] -# +# # Example 2 -# +# # Input: [ 1 2 3 ] # [ 4 5 6 ] -# +# # $matrix = [ [ 1, 2, 3 ] , [ 4, 5, 6 ] ] # $r = 3 # $c = 2 -# +# # Output: [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -# +# # [ 1 2 ] # [ 3 4 ] # [ 5 6 ] -# +# # Example 3 -# +# # Input: [ 1 2 ] -# +# # $matrix = [ [ 1, 2 ] ] # $r = 3 # $c = 2 -# +# # Output: 0 use Modern::Perl; @@ -50,23 +50,23 @@ use Modern::Perl; my @list; my($r, $c); while (<>) { - if (s/[\[\]]//g) { - push @list, split(' ', $_); - } - else { - ($r, $c) = split(' ', $_); - last; - } + if (s/[\[\]]//g) { + push @list, split(' ', $_); + } + else { + ($r, $c) = split(' ', $_); + last; + } } if ($r*$c == @list) { - for (1..$r) { - print "[ "; - for (1..$c) { - print shift(@list), " "; - } - print "]\n"; - } + for (1..$r) { + print "[ "; + for (1..$c) { + print shift(@list), " "; + } + print "]\n"; + } } else { - print 0; + print 0; } diff --git a/challenge-204/paulo-custodio/t/test-1.yaml b/challenge-204/paulo-custodio/t/test-1.yaml index 1ffd89f985..ba7f2b8199 100644 --- a/challenge-204/paulo-custodio/t/test-1.yaml +++ b/challenge-204/paulo-custodio/t/test-1.yaml @@ -15,17 +15,16 @@ output: 1 - setup: cleanup: - args: + args: input: output: 1 - setup: - cleanup: + cleanup: args: 1 input: output: 1 - setup: - cleanup: + cleanup: args: 1 1 1 1 input: output: 1 - diff --git a/challenge-204/paulo-custodio/t/test-2.yaml b/challenge-204/paulo-custodio/t/test-2.yaml index 9ca698d882..7e4e9a19e7 100644 --- a/challenge-204/paulo-custodio/t/test-2.yaml +++ b/challenge-204/paulo-custodio/t/test-2.yaml @@ -1,6 +1,6 @@ - setup: cleanup: - args: + args: input: | |[ 1 2 ] |[ 3 4 ] @@ -9,7 +9,7 @@ |[ 1 2 3 4 ] - setup: cleanup: - args: + args: input: | |[ 1 2 3 ] |[ 4 5 6 ] @@ -20,7 +20,7 @@ |[ 5 6 ] - setup: cleanup: - args: + args: input: | |[ 1 2 ] |3 2 -- cgit