aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2023-05-09 16:59:29 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2023-05-09 16:59:29 +0100
commite09d0c629d99aa5f6db10e7eac8569cea72aae3b (patch)
treeb1dd050fab0a287d00f738c3939698c559900324
parentbff180cd1b3410ae3851ed6638524029092f51ab (diff)
downloadperlweeklychallenge-club-e09d0c629d99aa5f6db10e7eac8569cea72aae3b.tar.gz
perlweeklychallenge-club-e09d0c629d99aa5f6db10e7eac8569cea72aae3b.tar.bz2
perlweeklychallenge-club-e09d0c629d99aa5f6db10e7eac8569cea72aae3b.zip
whitespace
-rw-r--r--challenge-025/paulo-custodio/c/ch-1.c144
-rw-r--r--challenge-025/paulo-custodio/perl/ch-1.pl26
-rw-r--r--challenge-215/paulo-custodio/perl/ch-2.pl2
3 files changed, 85 insertions, 87 deletions
diff --git a/challenge-025/paulo-custodio/c/ch-1.c b/challenge-025/paulo-custodio/c/ch-1.c
index feb2b11dae..709c9adc19 100644
--- a/challenge-025/paulo-custodio/c/ch-1.c
+++ b/challenge-025/paulo-custodio/c/ch-1.c
@@ -11,98 +11,98 @@ each name starts with the last letter of previous name.
#include "utarray.h"
static const char* names[] = {
- "audino", "bagon", "baltoy", "banette", "bidoof", "braviary", "bronzor",
- "carracosta", "charmeleon", "cresselia", "croagunk", "darmanitan",
- "deino", "emboar", "emolga", "exeggcute", "gabite", "girafarig",
- "gulpin", "haxorus", "heatmor", "heatran", "ivysaur", "jellicent",
- "jumpluff", "kangaskhan", "kricketune", "landorus", "ledyba", "loudred",
- "lumineon", "lunatone", "machamp", "magnezone", "mamoswine", "nosepass",
- "petilil", "pidgeotto", "pikachu", "pinsir", "poliwrath", "poochyena",
- "porygon2", "porygonz", "registeel", "relicanth", "remoraid", "rufflet",
- "sableye", "scolipede", "scrafty", "seaking", "sealeo", "silcoon",
- "simisear", "snivy", "snorlax", "spoink", "starly", "tirtouga",
- "trapinch", "treecko", "tyrogue", "vigoroth", "vulpix", "wailord",
- "wartortle", "whismur", "wingull", "yamask"
+ "audino", "bagon", "baltoy", "banette", "bidoof", "braviary", "bronzor",
+ "carracosta", "charmeleon", "cresselia", "croagunk", "darmanitan",
+ "deino", "emboar", "emolga", "exeggcute", "gabite", "girafarig",
+ "gulpin", "haxorus", "heatmor", "heatran", "ivysaur", "jellicent",
+ "jumpluff", "kangaskhan", "kricketune", "landorus", "ledyba", "loudred",
+ "lumineon", "lunatone", "machamp", "magnezone", "mamoswine", "nosepass",
+ "petilil", "pidgeotto", "pikachu", "pinsir", "poliwrath", "poochyena",
+ "porygon2", "porygonz", "registeel", "relicanth", "remoraid", "rufflet",
+ "sableye", "scolipede", "scrafty", "seaking", "sealeo", "silcoon",
+ "simisear", "snivy", "snorlax", "spoink", "starly", "tirtouga",
+ "trapinch", "treecko", "tyrogue", "vigoroth", "vulpix", "wailord",
+ "wartortle", "whismur", "wingull", "yamask"
};
int names_size = sizeof(names) / sizeof(char*);
UT_array* longest_seq;
void print_seq(UT_array* seq) {
- for (int* p = (int*)utarray_front(seq); p != NULL;
- p = (int*)utarray_next(seq, p)) {
- printf("%s ", names[*p]);
- }
- printf("\n");
+ for (int* p = (int*)utarray_front(seq); p != NULL;
+ p = (int*)utarray_next(seq, p)) {
+ printf("%s ", names[*p]);
+ }
+ printf("\n");
}
void copy_seq(UT_array* dst, UT_array* src) {
- utarray_clear(dst);
- for (int* p = (int*)utarray_front(src); p != NULL;
- p = (int*)utarray_next(src, p)) {
- utarray_push_back(dst, p);
- }
+ utarray_clear(dst);
+ for (int* p = (int*)utarray_front(src); p != NULL;
+ p = (int*)utarray_next(src, p)) {
+ utarray_push_back(dst, p);
+ }
}
char last_letter_seq(UT_array* seq) {
- char last_letter = '\0';
- if (utarray_len(seq) > 0) {
- const char* last_name = names[*(int*)utarray_back(seq)];
- last_letter = last_name[strlen(last_name) - 1];
- }
- return last_letter;
+ char last_letter = '\0';
+ if (utarray_len(seq) > 0) {
+ const char* last_name = names[*(int*)utarray_back(seq)];
+ last_letter = last_name[strlen(last_name) - 1];
+ }
+ return last_letter;
}
void find_longest_sequence(UT_array* seq, UT_array* pending) {
- char last_letter = last_letter_seq(seq);
-
- bool found_next = false;
- for (int* p = (int*)utarray_front(pending); p != NULL;
- p = (int*)utarray_next(pending, p)) {
- char first_letter = names[*p][0];
-
- if (last_letter == '\0' || last_letter == first_letter) {
- found_next = true;
-
- UT_array* new_seq;
- utarray_new(new_seq, &ut_int_icd);
- copy_seq(new_seq, seq);
- utarray_push_back(new_seq, p);
-
- UT_array* new_pending;
- utarray_new(new_pending, &ut_int_icd);
- copy_seq(new_pending, pending);
- utarray_erase(new_pending, p-(int*)utarray_front(pending), 1);
-
- find_longest_sequence(new_seq, new_pending);
-
- utarray_free(new_seq);
- utarray_free(new_pending);
- }
- }
-
- if (!found_next) {
- if (utarray_len(seq) > utarray_len(longest_seq)) {
- copy_seq(longest_seq, seq);
- }
- }
+ char last_letter = last_letter_seq(seq);
+
+ bool found_next = false;
+ for (int* p = (int*)utarray_front(pending); p != NULL;
+ p = (int*)utarray_next(pending, p)) {
+ char first_letter = names[*p][0];
+
+ if (last_letter == '\0' || last_letter == first_letter) {
+ found_next = true;
+
+ UT_array* new_seq;
+ utarray_new(new_seq, &ut_int_icd);
+ copy_seq(new_seq, seq);
+ utarray_push_back(new_seq, p);
+
+ UT_array* new_pending;
+ utarray_new(new_pending, &ut_int_icd);
+ copy_seq(new_pending, pending);
+ utarray_erase(new_pending, p-(int*)utarray_front(pending), 1);
+
+ find_longest_sequence(new_seq, new_pending);
+
+ utarray_free(new_seq);
+ utarray_free(new_pending);
+ }
+ }
+
+ if (!found_next) {
+ if (utarray_len(seq) > utarray_len(longest_seq)) {
+ copy_seq(longest_seq, seq);
+ }
+ }
}
int main() {
- utarray_new(longest_seq, &ut_int_icd);
+ utarray_new(longest_seq, &ut_int_icd);
- UT_array* seq;
- utarray_new(seq, &ut_int_icd);
+ UT_array* seq;
+ utarray_new(seq, &ut_int_icd);
- UT_array* pending;
- utarray_new(pending, &ut_int_icd);
- for (int i = 0; i < names_size; i++)
- utarray_push_back(pending, &i);
+ UT_array* pending;
+ utarray_new(pending, &ut_int_icd);
+ for (int i = 0; i < names_size; i++)
+ utarray_push_back(pending, &i);
- find_longest_sequence(seq, pending);
- print_seq(longest_seq);
+ find_longest_sequence(seq, pending);
+ print_seq(longest_seq);
- utarray_free(longest_seq);
- utarray_free(seq);
- utarray_free(pending);
+ utarray_free(longest_seq);
+ utarray_free(seq);
+ utarray_free(pending);
}
diff --git a/challenge-025/paulo-custodio/perl/ch-1.pl b/challenge-025/paulo-custodio/perl/ch-1.pl
index 7812bb0b8d..01eb44415e 100644
--- a/challenge-025/paulo-custodio/perl/ch-1.pl
+++ b/challenge-025/paulo-custodio/perl/ch-1.pl
@@ -25,23 +25,23 @@ sub find_longest_sequence1 {
my($longest_path, $current_path, @pending) = @_;
#say "(@$current_path) (@pending)";
- my $found_name = 0;
- for my $i (0 .. $#pending) {
- if (@$current_path == 0 ||
+ my $found_name = 0;
+ for my $i (0 .. $#pending) {
+ if (@$current_path == 0 ||
substr($current_path->[-1], -1, 1) eq substr($pending[$i], 0, 1)) {
- $found_name = 1;
-
- find_longest_sequence1($longest_path,
- [ @$current_path, $pending[$i] ],
- ( @pending[0..$i-1], @pending[$i+1..$#pending] ) );
- }
- }
-
- if (!$found_name) {
+ $found_name = 1;
+
+ find_longest_sequence1($longest_path,
+ [ @$current_path, $pending[$i] ],
+ ( @pending[0..$i-1], @pending[$i+1..$#pending] ) );
+ }
+ }
+
+ if (!$found_name) {
if (@$current_path > @$longest_path) {
@$longest_path = @$current_path;
}
- }
+ }
}
sub find_longest_sequence {
diff --git a/challenge-215/paulo-custodio/perl/ch-2.pl b/challenge-215/paulo-custodio/perl/ch-2.pl
index 9a55f27be1..2255a49608 100644
--- a/challenge-215/paulo-custodio/perl/ch-2.pl
+++ b/challenge-215/paulo-custodio/perl/ch-2.pl
@@ -49,5 +49,3 @@ sub can_place {
my @nums = split /,/, shift;
my $count = shift;
say can_place(\@nums, $count);
-
-