aboutsummaryrefslogtreecommitdiff
path: root/challenge-074/bob-lied/README
diff options
context:
space:
mode:
authorboblied <boblied@gmail.com>2020-08-18 07:14:56 -0500
committerboblied <boblied@gmail.com>2020-08-18 07:14:56 -0500
commit2f73a24a034bdf7a47ce74eb86e2c828dabc1aea (patch)
tree61950caa04566e467769916ae35bf04461fb1dcd /challenge-074/bob-lied/README
parent14f5ddd9f2717ef95d836b06941a97a2e9e2b737 (diff)
downloadperlweeklychallenge-club-2f73a24a034bdf7a47ce74eb86e2c828dabc1aea.tar.gz
perlweeklychallenge-club-2f73a24a034bdf7a47ce74eb86e2c828dabc1aea.tar.bz2
perlweeklychallenge-club-2f73a24a034bdf7a47ce74eb86e2c828dabc1aea.zip
Set up for challenge 74
Diffstat (limited to 'challenge-074/bob-lied/README')
-rw-r--r--challenge-074/bob-lied/README67
1 files changed, 20 insertions, 47 deletions
diff --git a/challenge-074/bob-lied/README b/challenge-074/bob-lied/README
index be171d638e..289b995df4 100644
--- a/challenge-074/bob-lied/README
+++ b/challenge-074/bob-lied/README
@@ -1,65 +1,38 @@
-Solutions to weekly challenge 72 by Bob Lied.
+Solutions to weekly challenge 74 by Bob Lied.
-https://perlweeklychallenge.org/blog/perl-weekly-challenge-072/
+https://perlweeklychallenge.org/blog/perl-weekly-challenge-074/
-This week, I would like to add two personal elements to the problem:
-(1) create a template for perl-vim that sets up these weekly challenges
-(includes Test::More, a skeleton for checking ARGV, and whatever else
-is quickly becoming a pattern; and (2) use a github issue in the submission
-process, just to learn more about using git and github.
-
-* TASK #1 > Trailing Zeroes
+* TASK #1 > Majority Element
** Initial thoughts
-Too easy, unless I'm missing something. The result gets a zero on the end every time
-it's multiplied by 10, and since we're doing factorials, that will happen every time N
-rolls past a multiple of 5. The answer is int(N/5), I think, but I'll need to convince
-myself completely.
-
-We could make it a little tougher by actually calculating N!, and maybe using Memoize
-as an optimization. And maybe finding out how high N can be until overflow or waiting time
-make it impractical.
-
** Post Solution Thoughts
-Yep, it was really that easy. I implemented the factorial using Memoize just
-for fun. The highest number that didn't roll over to floating point was 20!.
-
-
** Problem Statement
-You are given a positive integer $N (<= 10).
+You are given an array of integers of size $N.
+Write a script to find the majority element. If none found then print -1.
+Majority element in the list is the one that appears more than floor(size_of_list/2).
-Write a script to print number of trailing zeroes in $N!.
-* TASK #2 > Lines Range
-** Initial Thoughts
+* TASK #2 > FNR Character
-This has come up often enough that I know I've done it in sed and awk; and in
-a pipeline with head and tail. The flip-flop operator comes to mind, but
-there'll be some experimentation for boundary conditions. Also some test
-cases for A or B being outside the range of the file or having an empty file.
+** Initial Thoughts
** Post Solution Thoughts
-The hardest part of this turned out to be how to set up tests. I wanted the
-testing to be self-contained, so I put the test data into __DATA__. But then
-re-reading that repeatedly for different tests required seeking back to the
-start and also resetting $. A couple of trips to Google there.
-
-I also wanted to capture the output in a variable and not just print to the
-console. I knew that a string could be opened as a file handle using a
-reference to the string. It should have been easy; but I spent a long time
-debugging before I realized that I had typed \&TestResult instead of
-\$TestResult.
-
-
** Problem Statement
-You are given a text file name $file and range $A - $B where $A <= $B.
-
-Write a script to display lines range $A and $B in the given file.
-
-(That's A and B inclusive, from the examples.)
+You are given a string $S.
+
+Write a script to print the series of first non-repeating character
+(left -> right) for the given string. Print # if none found.
+Example 1
+Input: $S = ‘ababc’
+Output: ‘abb#c’
+Pass 1: “a”, the FNR character is ‘a’
+Pass 2: “ab”, the FNR character is ‘b’
+Pass 3: “aba”, the FNR character is ‘b’
+Pass 4: “abab”, no FNR found, hence ‘#’
+Pass 5: “ababc” the FNR character is ‘c’