diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-03-09 20:01:18 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-03-09 20:01:18 +0000 |
| commit | c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84 (patch) | |
| tree | 9133aa3fc3d107c7b44de3905fc7b1d2ab307aaa /challenge-103 | |
| parent | bfa8b8a3dda2ac37c22c7f4fc2867211f92f65e0 (diff) | |
| download | perlweeklychallenge-club-c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84.tar.gz perlweeklychallenge-club-c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84.tar.bz2 perlweeklychallenge-club-c51f9bd979dbd79f20cb0abd543dc9b4df9f4e84.zip | |
Remove tabs
Diffstat (limited to 'challenge-103')
| -rw-r--r-- | challenge-103/paulo-custodio/lua/ch-1.lua | 2 | ||||
| -rw-r--r-- | challenge-103/paulo-custodio/lua/ch-2.lua | 38 | ||||
| -rw-r--r-- | challenge-103/paulo-custodio/perl/ch-1.pl | 10 | ||||
| -rw-r--r-- | challenge-103/paulo-custodio/perl/ch-2.pl | 64 | ||||
| -rw-r--r-- | challenge-103/paulo-custodio/python/ch-1.py | 14 | ||||
| -rw-r--r-- | challenge-103/paulo-custodio/python/ch-2.py | 80 |
6 files changed, 104 insertions, 104 deletions
diff --git a/challenge-103/paulo-custodio/lua/ch-1.lua b/challenge-103/paulo-custodio/lua/ch-1.lua index 1a0143f85f..b32c147d8a 100644 --- a/challenge-103/paulo-custodio/lua/ch-1.lua +++ b/challenge-103/paulo-custodio/lua/ch-1.lua @@ -7,7 +7,7 @@ TASK #1 › Chinese Zodiac Submitted by: Mohammad S Anwar You are given a year $year. -Write a script to determine the Chinese Zodiac for the given year $year. +Write a script to determine the Chinese Zodiac for the given year $year. Please check out wikipage for more information about it. The animal cycle: Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, diff --git a/challenge-103/paulo-custodio/lua/ch-2.lua b/challenge-103/paulo-custodio/lua/ch-2.lua index cb0a0f74a6..955beca20e 100644 --- a/challenge-103/paulo-custodio/lua/ch-2.lua +++ b/challenge-103/paulo-custodio/lua/ch-2.lua @@ -67,10 +67,10 @@ playlist_file = arg[3] playlist = {} playlist_total_secs = 0 for line in io.lines(playlist_file) do - local ms, title = line:match('%s*(.-),%s*"(.-)"') - local secs = math.floor(tonumber(ms)/1000+0.5) - table.insert(playlist, { secs, title }) - playlist_total_secs = playlist_total_secs + secs + local ms, title = line:match('%s*(.-),%s*"(.-)"') + local secs = math.floor(tonumber(ms)/1000+0.5) + table.insert(playlist, { secs, title }) + playlist_total_secs = playlist_total_secs + secs end -- compute location @@ -79,19 +79,19 @@ playlist_secs = total_secs % playlist_total_secs -- find current track for k, v in pairs(playlist) do - local secs, title = v[1], v[2] - if playlist_secs < secs then -- playing this title - io.write(title, "\n") - - local hh = math.floor(playlist_secs / 3600) - playlist_secs = playlist_secs % 3600 - local mm = math.floor(playlist_secs / 60) - playlist_secs = playlist_secs % 60 - local ss = playlist_secs - - io.write(string.format("%02d:%02d:%02d", hh, mm, ss), "\n") - break - else - playlist_secs = playlist_secs - secs - end + local secs, title = v[1], v[2] + if playlist_secs < secs then -- playing this title + io.write(title, "\n") + + local hh = math.floor(playlist_secs / 3600) + playlist_secs = playlist_secs % 3600 + local mm = math.floor(playlist_secs / 60) + playlist_secs = playlist_secs % 60 + local ss = playlist_secs + + io.write(string.format("%02d:%02d:%02d", hh, mm, ss), "\n") + break + else + playlist_secs = playlist_secs - secs + end end diff --git a/challenge-103/paulo-custodio/perl/ch-1.pl b/challenge-103/paulo-custodio/perl/ch-1.pl index 3587c47f0f..afb70678de 100644 --- a/challenge-103/paulo-custodio/perl/ch-1.pl +++ b/challenge-103/paulo-custodio/perl/ch-1.pl @@ -1,18 +1,18 @@ #!/usr/bin/perl # Challenge 103 -# +# # TASK #1 › Chinese Zodiac # Submitted by: Mohammad S Anwar # You are given a year $year. -# -# Write a script to determine the Chinese Zodiac for the given year $year. +# +# Write a script to determine the Chinese Zodiac for the given year $year. # Please check out wikipage for more information about it. -# +# # The animal cycle: Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, # Rooster, Dog, Pig. # The element cycle: Wood, Fire, Earth, Metal, Water. -# +# # Example 1: # Input: 2017 # Output: Fire Rooster diff --git a/challenge-103/paulo-custodio/perl/ch-2.pl b/challenge-103/paulo-custodio/perl/ch-2.pl index 0263997cb5..7fb36a2053 100644 --- a/challenge-103/paulo-custodio/perl/ch-2.pl +++ b/challenge-103/paulo-custodio/perl/ch-2.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Challenge 103 -# +# # TASK #2 › What’s playing? # Submitted by: Albert Croft # Working from home, you decided that on occasion you wanted some background @@ -9,18 +9,18 @@ # loop through the files and launched it in a tmux (or screen) session, giving # it a directory tree of files to play. During the day, you connected an audio # player to the stream, listening through the workday, closing it when done. -# +# # For weeks you connect to the stream daily, slowly noticing a gradual drift of # the media. After several weeks, you take vacation. When you return, you are # pleasantly surprised to find the streamer still running. Before connecting, # however, if you consider the puzzle of determining which track is playing. -# +# # After looking at a few modules to read info regarding the media, a quick bit # of coding gave you a file list. The file list is in a simple CSV format, each # line containing two fields: the first the number of milliseconds in length, # the latter the media’s title (this example is of several episodes available # from the MercuryTheatre.info): -# +# # 1709363,"Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)" # 1723781,"Les Miserables Episode 2: Javert (broadcast date: 1937-07-30)" # 1723781,"Les Miserables Episode 3: The Trial (broadcast date: 1937-08-06)" @@ -29,7 +29,7 @@ # 1714640,"Les Miserables Episode 6: The Barricade (broadcast date: 1937-08-27)" # 1714640,"Les Miserables Episode 7: Conclusion (broadcast date: 1937-09-03)" # For this script, you can assume to be provided the following information: -# +# # * the value of $^T ($BASETIME) of the streamer script, # * the value of time(), and # * a CSV file containing the media to play consisting of the length in @@ -37,26 +37,26 @@ # Write a program to output which file is currently playing. For purposes of # this script, you may assume gapless playback, and format the output as you # see fit. -# +# # Optional: Also display the current position in the media as a time-like value. -# +# # Example: -# +# # Input: 3 command line parameters: start time, current time, file name -# +# # # Streamer start time: Tue Nov 23 12:22:03 2020 # 1606134123 -# +# # # Current time: Mon Mar 1 09:34:36 2021 # 1614591276 -# +# # # filelist.csv -# +# # Output: -# +# # "Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)" # 00:17:33 - + use strict; use warnings; use 5.030; @@ -68,28 +68,28 @@ my @playlist; my $playlist_total_secs = 0; open(my $fh, "<", $playlist) or die "open file $playlist: $!\n"; while (<$fh>) { - chomp; - my($ms, $title) = split(/,/, $_, 2); - my $secs = int($ms/1000+0.5); - $title =~ s/^\"(.*)\"$/$1/; - push @playlist, [$secs, $title]; - $playlist_total_secs += $secs; + chomp; + my($ms, $title) = split(/,/, $_, 2); + my $secs = int($ms/1000+0.5); + $title =~ s/^\"(.*)\"$/$1/; + push @playlist, [$secs, $title]; + $playlist_total_secs += $secs; } my $total_secs = $current_secs - $start_secs; my $playlist_secs = $total_secs % $playlist_total_secs; for (@playlist) { - my($secs, $title) = @$_; - if ($playlist_secs < $secs) { # playing this title - say $title; - my $hh = int($playlist_secs/3600); $playlist_secs %= 3600; - my $mm = int($playlist_secs/60); $playlist_secs %= 60; - my $ss = $playlist_secs; - say sprintf("%02d:%02d:%02d", $hh, $mm, $ss); - last; - } - else { - $playlist_secs -= $secs; - } + my($secs, $title) = @$_; + if ($playlist_secs < $secs) { # playing this title + say $title; + my $hh = int($playlist_secs/3600); $playlist_secs %= 3600; + my $mm = int($playlist_secs/60); $playlist_secs %= 60; + my $ss = $playlist_secs; + say sprintf("%02d:%02d:%02d", $hh, $mm, $ss); + last; + } + else { + $playlist_secs -= $secs; + } } diff --git a/challenge-103/paulo-custodio/python/ch-1.py b/challenge-103/paulo-custodio/python/ch-1.py index 4231b5f109..4eed2f269d 100644 --- a/challenge-103/paulo-custodio/python/ch-1.py +++ b/challenge-103/paulo-custodio/python/ch-1.py @@ -1,18 +1,18 @@ #!/usr/bin/env python # Challenge 103 -# +# # TASK #1 > Chinese Zodiac # Submitted by: Mohammad S Anwar # You are given a year $year. -# -# Write a script to determine the Chinese Zodiac for the given year $year. +# +# Write a script to determine the Chinese Zodiac for the given year $year. # Please check out wikipage for more information about it. -# +# # The animal cycle: Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, # Rooster, Dog, Pig. # The element cycle: Wood, Fire, Earth, Metal, Water. -# +# # Example 1: # Input: 2017 # Output: Fire Rooster @@ -23,9 +23,9 @@ import sys; animals = ['Rat','Ox','Tiger','Rabbit','Dragon','Snake','Horse','Goat', - 'Monkey','Rooster','Dog','Pig'] + 'Monkey','Rooster','Dog','Pig'] elements = ['Wood','Wood','Fire','Fire','Earth','Earth','Metal','Metal', - 'Water','Water']; + 'Water','Water']; year = int(sys.argv[1]) num_years = year-1924; diff --git a/challenge-103/paulo-custodio/python/ch-2.py b/challenge-103/paulo-custodio/python/ch-2.py index abfa505427..c03a008efd 100644 --- a/challenge-103/paulo-custodio/python/ch-2.py +++ b/challenge-103/paulo-custodio/python/ch-2.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # Challenge 103 -# +# # TASK #2 > What's playing? # Submitted by: Albert Croft # Working from home, you decided that on occasion you wanted some background @@ -9,18 +9,18 @@ # loop through the files and launched it in a tmux (or screen) session, giving # it a directory tree of files to play. During the day, you connected an audio # player to the stream, listening through the workday, closing it when done. -# +# # For weeks you connect to the stream daily, slowly noticing a gradual drift of # the media. After several weeks, you take vacation. When you return, you are # pleasantly surprised to find the streamer still running. Before connecting, # however, if you consider the puzzle of determining which track is playing. -# +# # After looking at a few modules to read info regarding the media, a quick bit # of coding gave you a file list. The file list is in a simple CSV format, each # line containing two fields: the first the number of milliseconds in length, # the latter the media's title (this example is of several episodes available # from the MercuryTheatre.info): -# +# # 1709363,"Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)" # 1723781,"Les Miserables Episode 2: Javert (broadcast date: 1937-07-30)" # 1723781,"Les Miserables Episode 3: The Trial (broadcast date: 1937-08-06)" @@ -29,7 +29,7 @@ # 1714640,"Les Miserables Episode 6: The Barricade (broadcast date: 1937-08-27)" # 1714640,"Les Miserables Episode 7: Conclusion (broadcast date: 1937-09-03)" # For this script, you can assume to be provided the following information: -# +# # * the value of $^T ($BASETIME) of the streamer script, # * the value of time(), and # * a CSV file containing the media to play consisting of the length in @@ -37,23 +37,23 @@ # Write a program to output which file is currently playing. For purposes of # this script, you may assume gapless playback, and format the output as you # see fit. -# +# # Optional: Also display the current position in the media as a time-like value. -# +# # Example: -# +# # Input: 3 command line parameters: start time, current time, file name -# +# # # Streamer start time: Tue Nov 23 12:22:03 2020 # 1606134123 -# +# # # Current time: Mon Mar 1 09:34:36 2021 # 1614591276 -# +# # # filelist.csv -# +# # Output: -# +# # "Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)" # 00:17:33 @@ -61,36 +61,36 @@ import csv import sys def read_playlist(filename): - playlist = [] - with open(filename) as csv_file: - csv_reader = csv.reader(csv_file, delimiter=',') - for row in csv_reader: - playlist.append([int(int(row[0])/1000+0.5), row[1]]) - return playlist + playlist = [] + with open(filename) as csv_file: + csv_reader = csv.reader(csv_file, delimiter=',') + for row in csv_reader: + playlist.append([int(int(row[0])/1000+0.5), row[1]]) + return playlist def total_time(playlist): - sum = 0 - for x in playlist: - sum += x[0] - return sum + sum = 0 + for x in playlist: + sum += x[0] + return sum def show_title(start_secs, current_secs, playlist_file): - playlist = read_playlist('playlist.csv') - total_secs = current_secs - start_secs - playlist_total_secs = total_time(playlist) - playlist_secs = total_secs % playlist_total_secs - - for item in playlist: - if playlist_secs < item[0]: - print(item[1]) - hh = int(playlist_secs/3600) - playlist_secs %= 3600 - mm = int(playlist_secs/60) - playlist_secs %= 60 - ss = playlist_secs; - print("{:02}:{:02}:{:02}".format(hh, mm, ss)) - break - else: - playlist_secs -= item[0] + playlist = read_playlist('playlist.csv') + total_secs = current_secs - start_secs + playlist_total_secs = total_time(playlist) + playlist_secs = total_secs % playlist_total_secs + + for item in playlist: + if playlist_secs < item[0]: + print(item[1]) + hh = int(playlist_secs/3600) + playlist_secs %= 3600 + mm = int(playlist_secs/60) + playlist_secs %= 60 + ss = playlist_secs; + print("{:02}:{:02}:{:02}".format(hh, mm, ss)) + break + else: + playlist_secs -= item[0] show_title(int(sys.argv[1]), int(sys.argv[2]), sys.argv[3]) |
