aboutsummaryrefslogtreecommitdiff
path: root/challenge-006
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-05-05 20:18:03 +0100
committerGitHub <noreply@github.com>2019-05-05 20:18:03 +0100
commitdeb699cff62dc7bcc195b92b1066d64cc6503c58 (patch)
tree38b6e263ae7adff35ef56ad45dca10dc55afe1e0 /challenge-006
parentbed576b04fc7d250c2d0fe5a9b6f2c5cefb758f4 (diff)
parent090fea7e78705f579d9be367510335bd86192d92 (diff)
downloadperlweeklychallenge-club-deb699cff62dc7bcc195b92b1066d64cc6503c58.tar.gz
perlweeklychallenge-club-deb699cff62dc7bcc195b92b1066d64cc6503c58.tar.bz2
perlweeklychallenge-club-deb699cff62dc7bcc195b92b1066d64cc6503c58.zip
Merge pull request #122 from dmanto/branch-for-challenge-006
solution challenge 006-1
Diffstat (limited to 'challenge-006')
-rw-r--r--challenge-006/daniel-mantovani/perl5/ch-1.pl41
-rw-r--r--challenge-006/daniel-mantovani/perl5/perltidy.LOG58
2 files changed, 99 insertions, 0 deletions
diff --git a/challenge-006/daniel-mantovani/perl5/ch-1.pl b/challenge-006/daniel-mantovani/perl5/ch-1.pl
new file mode 100644
index 0000000000..f220d0f17d
--- /dev/null
+++ b/challenge-006/daniel-mantovani/perl5/ch-1.pl
@@ -0,0 +1,41 @@
+#
+# Create a script which takes a list of numbers from command line and print the same in the compact form.
+# For example, if you pass “1,2,3,4,9,10,14,15,16” then it should print the compact form like “1-4,9,10,14-16”.
+#
+use strict;
+use warnings;
+
+my $inp = $ARGV[0];
+die "Usage perl $0 <commma separated number list>"
+ unless defined $inp && $inp =~ /^(\d+,?)+$/;
+#
+# for all numbers, calculate adjacency as:
+# 0b00 no adjacent numbers
+# 0b10 adjacency on lower side
+# 0b01 adjacency on upper side
+# 0b11 adjacency on both sides
+#
+my %adj;
+$adj{$_} = 0 for split ',', $inp;
+for my $n ( keys %adj ) {
+ $adj{$n} |= 0b10 if exists $adj{ $n - 1 };
+ $adj{$n} |= 0b01 if exists $adj{ $n + 1 };
+}
+#
+# now calculate an ordered array with all numbers that have to be printed
+#
+my @edges = grep { $adj{$_} != 3 } sort { $a <=> $b } keys %adj;
+#
+# if got here, there is a first number to print
+#
+print $edges[0];
+for my $i ( 1 .. $#edges ) {
+ my $current = $edges[$i];
+
+# if current number - 1 exists and have adjacency type '3', separator is '-', otherwise it is ','
+ print exists $adj{ $current - 1 }
+ && $adj{ $current - 1 } == 3 ? '-' : ',';
+ print $current;
+}
+
+print "\n" if defined $inp;
diff --git a/challenge-006/daniel-mantovani/perl5/perltidy.LOG b/challenge-006/daniel-mantovani/perl5/perltidy.LOG
new file mode 100644
index 0000000000..d97eac0c88
--- /dev/null
+++ b/challenge-006/daniel-mantovani/perl5/perltidy.LOG
@@ -0,0 +1,58 @@
+perltidy version 20180220 log file on a darwin system, OLD_PERL_VERSION=5.028000
+Configuration and command line parameters for this run:
+-st -profile=.../.perltidyrc
+To find error messages search for 'WARNING' with your editor
+Indentation will be with 4 spaces
+Line 5 implies starting-indentation-level = 0
+
+######################## WARNING #########################
+There is no previous '{' to match a '}' on line 31
+31: }
+ ^
+############################################################
+WARNING: Starting negative indentation
+WARNING: final indentation level: -1
+The nesting depths in the table below are at the start of the lines.
+The indicated output line numbers are not always exact.
+ci = levels of continuation indentation; bk = 1 if in BLOCK, 0 if not.
+
+in:out indent c b nesting code + messages; (messages begin with >>>)
+lines levels i k (code begins with one '.' per indent level)
+------ ----- - - -------- -------------------------------------------
+L5:5 i0:0 0 1 >>>Line length exceeded by 25 characters
+L5:5 i0:0 0 1 >>>Line length exceeded by 39 characters
+L29:30 i1:1 0 1 { >>>Added ';' here
+L30:31 i1:0 0 1 { >>>Start indentation disagreement: input=1; output=0
+L31:31 i0:-1 0 1 >>>WARNING: Program bug in scan_list: hit nesting error which should have been caught
+L33:34 i0:-1 0 1 } >>>Last line
+
+1 semicolon was added:
+ at input line 29
+ (Use -nasc to prevent semicolon addition)
+
+First indentation disagreement seen at input line 30
+Ending with indentation disagreement which started at input line 30
+Note: Indentation disagreement detection is not accurate for outdenting and -lp.
+
+4 long lines were outdented:
+ First at output line 1
+ Last at output line 1
+ use -noll to prevent outdenting, -l=n to increase line length
+
+2 output lines exceeded 80 characters:
+ First at line 2 by 25 characters
+ Maximum at line 3 by 39 characters
+ Last at line 3 by 39 characters
+WARNING: To save a full .LOG file rerun with -g
+WARNING:
+Oops, you seem to have encountered a bug in perltidy. Please check the
+BUGS file at http://perltidy.sourceforge.net. If the problem is not
+listed there, please report it so that it can be corrected. Include the
+smallest possible script which produces this message, along with the
+.LOG file if appropriate. See the manual pages for contact information.
+Your efforts are appreciated.
+Thank you!
+WARNING:
+The log file shows that perltidy added 1 semicolons.
+Please rerun with -nasc to see if that is the cause of the syntax error. Even
+if that is the problem, please report it so that it can be fixed.