aboutsummaryrefslogtreecommitdiff
path: root/challenge-093/jaime/README
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-12-28 14:22:24 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-12-28 14:22:24 +0000
commitb331c6e73978bb3f2331eda1f4a2d2df03fd30b7 (patch)
tree2a412bc7f03d33e261f8f7db37cca4aa7cb442c0 /challenge-093/jaime/README
parentcc27effc2827d8bf6d3f940743870a1b3df0c697 (diff)
downloadperlweeklychallenge-club-b331c6e73978bb3f2331eda1f4a2d2df03fd30b7.tar.gz
perlweeklychallenge-club-b331c6e73978bb3f2331eda1f4a2d2df03fd30b7.tar.bz2
perlweeklychallenge-club-b331c6e73978bb3f2331eda1f4a2d2df03fd30b7.zip
- Added template for Challenge 93.
Diffstat (limited to 'challenge-093/jaime/README')
-rw-r--r--challenge-093/jaime/README59
1 files changed, 59 insertions, 0 deletions
diff --git a/challenge-093/jaime/README b/challenge-093/jaime/README
new file mode 100644
index 0000000000..007cb58459
--- /dev/null
+++ b/challenge-093/jaime/README
@@ -0,0 +1,59 @@
+# Task #1
+
+Write a script to display months from the year 1900 to 2019 where you
+find 5 weekends i.e. 5 Friday, 5 Saturday and 5 Sunday.
+
+## Solution
+
+Months that contain five full weekends have 31 days and start on a Friday. Use `cal` to display March 2019 as an example.
+
+```
+#$ cal -h -m 3 2019 # cal is a UNIX utility
+ March 2019
+Su Mo Tu We Th Fr Sa
+ 1 2
+ 3 4 5 6 7 8 9
+10 11 12 13 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+31
+```
+
+The solution runs `cal` and displays months that match this unique
+layout.
+
+# Task #2
+
+Write a script that can wrap the given paragraph at a specified column
+using the greedy algorithm.
+
+A simple way to do word wrapping is to use a greedy algorithm that
+puts as many words on a line as possible, then moving on to the next
+line to do the same until there are no more words left to place. This
+method is used by many modern word processors, such as OpenOffice.org
+Writer and Microsoft Word[citation needed]. This algorithm always uses
+the minimum possible number of lines but may lead to lines of widely
+varying lengths. The following pseudocode implements this algorithm:
+
+```
+SpaceLeft := LineWidth
+for each Word in Text
+ if (Width(Word) + SpaceWidth) > SpaceLeft
+ insert line break before Word in Text
+ SpaceLeft := LineWidth - Width(Word)
+ else
+ SpaceLeft := SpaceLeft - (Width(Word) + SpaceWidth)
+```
+
+Where LineWidth is the width of a line, SpaceLeft is the remaining
+width of space on the line to fill, SpaceWidth is the width of a
+single space character, Text is the input text to iterate over and
+Word is a word in this text.
+
+## Solution
+
+The solution follows the recommended pseudocode. Minor improvements
+avoid trailing whitespace.
+
+The script uses `Text::ParseWords::shellwords` from the standard
+library to extract chunks of words from `<STDIN>`.