aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-100/james-smith/perl/ch-1.pl2
-rw-r--r--challenge-102/james-smith/perl/ch-1.pl6
-rw-r--r--challenge-103/james-smith/perl/ch-1.pl30
-rw-r--r--challenge-103/james-smith/perl/ch-2.pl84
-rw-r--r--challenge-103/james-smith/perl/filelist.csv7
-rw-r--r--challenge-103/mark-anderson/raku/ch-1.raku27
-rw-r--r--challenge-103/mark-anderson/raku/ch-2.raku25
-rw-r--r--challenge-103/mark-anderson/raku/filelist.csv7
-rwxr-xr-xchallenge-103/roger-bell-west/perl/ch-1.pl24
-rwxr-xr-xchallenge-103/roger-bell-west/perl/ch-2.pl32
-rwxr-xr-xchallenge-103/roger-bell-west/python/ch-1.py22
-rwxr-xr-xchallenge-103/roger-bell-west/python/ch-2.py31
-rwxr-xr-xchallenge-103/roger-bell-west/raku/ch-1.p622
-rwxr-xr-xchallenge-103/roger-bell-west/raku/ch-2.p634
-rwxr-xr-xchallenge-103/roger-bell-west/ruby/ch-1.rb28
-rwxr-xr-xchallenge-103/roger-bell-west/ruby/ch-2.rb34
-rwxr-xr-xchallenge-103/roger-bell-west/rust/ch-1.rs29
-rw-r--r--challenge-103/roger-bell-west/rust/ch-2.rs47
-rw-r--r--challenge-103/roger-bell-west/t2.csv7
-rw-r--r--challenge-103/sgreen/README.md4
-rw-r--r--challenge-103/sgreen/blog.txt1
-rwxr-xr-xchallenge-103/sgreen/perl/ch-1.pl21
-rwxr-xr-xchallenge-103/sgreen/perl/ch-2.pl44
-rw-r--r--stats/pwc-current.json149
-rw-r--r--stats/pwc-language-breakdown-summary.json74
-rw-r--r--stats/pwc-language-breakdown.json1464
-rw-r--r--stats/pwc-leaders.json434
-rw-r--r--stats/pwc-summary-1-30.json102
-rw-r--r--stats/pwc-summary-121-150.json18
-rw-r--r--stats/pwc-summary-151-180.json110
-rw-r--r--stats/pwc-summary-181-210.json114
-rw-r--r--stats/pwc-summary-211-240.json76
-rw-r--r--stats/pwc-summary-31-60.json52
-rw-r--r--stats/pwc-summary-61-90.json100
-rw-r--r--stats/pwc-summary-91-120.json92
-rw-r--r--stats/pwc-summary.json54
36 files changed, 2023 insertions, 1384 deletions
diff --git a/challenge-100/james-smith/perl/ch-1.pl b/challenge-100/james-smith/perl/ch-1.pl
index cce37c7bd6..9ff8b14021 100644
--- a/challenge-100/james-smith/perl/ch-1.pl
+++ b/challenge-100/james-smith/perl/ch-1.pl
@@ -42,7 +42,7 @@ done_testing();
## 113 bytes total - 105 inside the curly braces..
sub ft{pop=~s/(.+)(:..)\s*(.m|)/sprintf'%02d%s%s',
-($1%12||(12*!$3))+12*('pm'eq$3),$2,$3?'':$1%24<12?'am':'pm'/re}
+ ($1%12||(12*!$3))+12*('pm'eq$3),$2,$3?'':$1%24<12?'am':'pm'/re}
## This is more readable version with notes...
sub fun_time {
diff --git a/challenge-102/james-smith/perl/ch-1.pl b/challenge-102/james-smith/perl/ch-1.pl
index 187ed6b95b..dcfb31af4d 100644
--- a/challenge-102/james-smith/perl/ch-1.pl
+++ b/challenge-102/james-smith/perl/ch-1.pl
@@ -41,10 +41,10 @@ sub rare_numbers {
my $x = shift;
return () if $F[$x%9]; ## Digit sum is wrong...
my $y = reverse $x;
- return () if $x == $y; ## Musn't be the same back and forth
- return $y if $x<$y && is_sq($x+$y) && is_sq($y-$x);
+ return () if $x == $y || ! is_sq($x+$y); ## Musn't be the same back and forth
+ return $y if $x<$y && is_sq($y-$x);
+ return $x if $y<$x && is_sq($x-$y);
## Check both ways round!
- return $x if $y<$x && is_sq($x+$y) && is_sq($x-$y);
return ();
}
diff --git a/challenge-103/james-smith/perl/ch-1.pl b/challenge-103/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..0d0382811f
--- /dev/null
+++ b/challenge-103/james-smith/perl/ch-1.pl
@@ -0,0 +1,30 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+
+## Slight extension - include the Yin/Yang prefix...
+
+is( year_name( 2017 ), 'Yin Fire Rooster' );
+is( year_name( 1938 ), 'Yang Earth Tiger' );
+
+done_testing();
+
+## Choose the order based on what would happen in years "0","60" -
+## this is "Yang Metal Monkey", so we make them the first entry in
+## the list - saves us doing a "shift" to get the right modulus key.
+
+## We have added in the last "classifier" - Yang/Yin which split the
+## element entry in two.
+
+sub year_name {
+ return join q( ),
+ qw( Yang Yin )[ $_[0] % 2 ],
+ qw( Metal Water Wood Fire Earth )[ ($_[0]/2) % 5 ],
+ qw( Monkey Rooster Dog Pig Rat Ox
+ Tiger Rabbit Dragon Snake Horse Goat )[ $_[0] % 12 ],
+}
+
diff --git a/challenge-103/james-smith/perl/ch-2.pl b/challenge-103/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..f924ef1806
--- /dev/null
+++ b/challenge-103/james-smith/perl/ch-2.pl
@@ -0,0 +1,84 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Data::Dumper qw(Dumper);
+
+is( position( 1606134123, 1614591276, 'filelist.csv'),
+ 'Les Miserables Episode 1: The Bishop (broadcast'.
+ ' date: 1937-07-23) @ 00:10:24' );
+
+done_testing();
+
+sub position {
+ my ($start, $now, $filename ) = @_;
+
+ ## Slurp in the durations and title's of the episodes,
+ ## and while doing this - computer the total length of
+ ## all the episodes.
+ ##
+ ## A neat feature of perl is that we can define
+ ## variables anywhere in the statement not just at the
+ ## beginning - so we can do the slurp in a single line
+ ##
+ ## Rather than using a full CSV library we split on ,"
+ ## as this works for the set of data that we have in
+ ## the problem but we could use Text::CSV for more
+ ## complex strings.
+ ##
+ ## Note values in @episodes are triples (the third is
+ ## any part of the string after the second " which
+ ## happens just to be "\n"
+
+ my $tot_duration = 0;
+ open my $fh, q(<), $filename;
+ $tot_duration += $_->[0]
+ foreach my @episodes = map { [split m{,?"}] } <$fh>;
+ close $fh;
+
+ ## We need the total duration of episodes to work out
+ ## how far we have wrapped around the time slots ....
+
+ ## Get the position through the current cycle...
+ ## Note we have to multiple the difference by 1000
+ ## as the as the tot_duration is in milliseconds and
+ ## now/start in seconds.
+
+ my $position = 1000 * ($now-$start) % $tot_duration;
+
+ ## Now find which episode that is at that time...
+
+ foreach( @episodes ) {
+
+ ## If the $position variable is less than the length
+ ## of the episode then this is the one we want to
+ ## return....
+ ##
+ ## $position value is the time after the start we
+ ## want to return... As it is milliseconds we don't
+ ## just divide by 60 & 3600 we have to multiply
+ ## these divisors by 1000
+ ##
+ ## Rather than return an array of two values name
+ ## and position - we return as a string - this is
+ ## to make the test call easier byt we could just
+ ## return [ $_->[0], $position ] which is the second
+ ## half of the sprintf '%02d:%02d:%02d', ....
+
+ return sprintf '%s @ %02d:%02d:%02d',
+ $_->[1],
+ int( $position/3600000 ) ,
+ int( $position/ 60000 ) % 60,
+ int( $position/ 1000 ) % 60 if $position < $_->[0];
+
+ ## OK - rather than "moving the start time" - we just
+ ## reduce position by the length of the episode and
+ ## try again....
+
+ $position -= $_->[0];
+ }
+}
+
diff --git a/challenge-103/james-smith/perl/filelist.csv b/challenge-103/james-smith/perl/filelist.csv
new file mode 100644
index 0000000000..9428b93004
--- /dev/null
+++ b/challenge-103/james-smith/perl/filelist.csv
@@ -0,0 +1,7 @@
+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)"
+1678356,"Les Miserables Episode 4: Cosette (broadcast date: 1937-08-13)"
+1646043,"Les Miserables Episode 5: The Grave (broadcast date: 1937-08-20)"
+1714640,"Les Miserables Episode 6: The Barricade (broadcast date: 1937-08-27)"
+1714640,"Les Miserables Episode 7: Conclusion (broadcast date: 1937-09-03)"
diff --git a/challenge-103/mark-anderson/raku/ch-1.raku b/challenge-103/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..7ee7b2a428
--- /dev/null
+++ b/challenge-103/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,27 @@
+#!/usr/bin/env raku
+
+use Test;
+plan 11;
+
+is zodiac(1924), "Wood Rat";
+is zodiac(1938), "Earth Tiger";
+is zodiac(1942), "Water Horse";
+is zodiac(1966), "Fire Horse";
+is zodiac(1984), "Wood Rat";
+is zodiac(1999), "Earth Rabbit";
+is zodiac(2001), "Metal Snake";
+is zodiac(2012), "Water Dragon";
+is zodiac(2017), "Fire Rooster";
+is zodiac(2021), "Metal Ox";
+is zodiac(2025), "Wood Snake";
+
+sub zodiac($year is copy)
+{
+ $year -= 1900;
+
+ my @elements = flat map { $_ xx 2 }, < Metal Water Wood Fire Earth >;
+
+ my @animals = < Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig >;
+
+ @elements[$year mod 10], @animals[$year mod 12] andthen .join(" ");
+}
diff --git a/challenge-103/mark-anderson/raku/ch-2.raku b/challenge-103/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..5176af00df
--- /dev/null
+++ b/challenge-103/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+
+my $start = 1606134123;
+
+say what's-playing($start, $start+1708, "filelist.csv");
+say what's-playing($start, $start+1709, "filelist.csv");
+say what's-playing($start, $start+1710, "filelist.csv");
+say what's-playing($start, $start+1711, "filelist.csv");
+say what's-playing($start, $start+1712, "filelist.csv");
+
+sub what's-playing($start is copy, $current, $file)
+{
+ for $file.IO.lines -> $line
+ {
+ my ($t, $f) = $line.split(",", 2);
+ $t /= 1000;
+ $start += $t;
+
+ if $start >= $current
+ {
+ my $pos = $t - ($start - $current);
+ return $f ~ "\n" ~ DateTime.new($pos).hh-mm-ss;
+ }
+ }
+}
diff --git a/challenge-103/mark-anderson/raku/filelist.csv b/challenge-103/mark-anderson/raku/filelist.csv
new file mode 100644
index 0000000000..9428b93004
--- /dev/null
+++ b/challenge-103/mark-anderson/raku/filelist.csv
@@ -0,0 +1,7 @@
+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)"
+1678356,"Les Miserables Episode 4: Cosette (broadcast date: 1937-08-13)"
+1646043,"Les Miserables Episode 5: The Grave (broadcast date: 1937-08-20)"
+1714640,"Les Miserables Episode 6: The Barricade (broadcast date: 1937-08-27)"
+1714640,"Les Miserables Episode 7: Conclusion (broadcast date: 1937-09-03)"
diff --git a/challenge-103/roger-bell-west/perl/ch-1.pl b/challenge-103/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..53d6dcaf63
--- /dev/null
+++ b/challenge-103/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+is(cz(2017),'Fire Rooster','example 1');
+is(cz(1938),'Earth Tiger','example 2');
+
+sub cz {
+ my $yy=shift;
+ my $y=$yy;
+ if ($y<0) {
+ $y++;
+ }
+ $y%=60;
+ while ($y<0) {
+ $y+=60;
+ }
+ return join(' ',
+ [qw(Metal Water Wood Fire Earth)]->[int($y/2)%5],
+ [qw(Monkey Rooster Dog Pig Rat),'Water Buffalo',qw(Tiger Cat Dragon Snake Horse Goat)]->[$y%12]);
+}
diff --git a/challenge-103/roger-bell-west/perl/ch-2.pl b/challenge-103/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..a99a672b78
--- /dev/null
+++ b/challenge-103/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+is(wp(1606134123,1614591276,'t2.csv'),'00:10:24 Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)','example 1');
+
+use Text::CSV_XS qw(csv);
+use List::Util qw(sum);
+
+sub wp {
+ my $ts=shift;
+ my $tn=shift;
+ my $csvfile=shift;
+ my $td=($tn-$ts)*1000;
+ my $aoa=csv(in => $csvfile);
+ my $tp=sum(map {$_->[0]} @{$aoa});
+ $td %= $tp;
+ foreach my $t (@{$aoa}) {
+ if ($td < $t->[0]) {
+ $td=int($td/1000);
+ my $h=int($td/3600);
+ my $m=int($td/60) % 60;
+ my $s=$td % 60;
+ return sprintf('%02d:%02d:%02d %s',$h,$m,$s,$t->[1]);
+ } else {
+ $td-=$t->[0];
+ }
+ }
+}
diff --git a/challenge-103/roger-bell-west/python/ch-1.py b/challenge-103/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..92708e26fa
--- /dev/null
+++ b/challenge-103/roger-bell-west/python/ch-1.py
@@ -0,0 +1,22 @@
+#! /usr/bin/python3
+
+def cz(yy):
+ y=int(yy)
+ if y<0:
+ y += 1
+ y %= 60
+ while y<0:
+ y += 60
+ return " ".join([['Metal','Water','Wood','Fire','Earth'][int(y/2)%5],['Monkey','Rooster','Dog','Pig','Rat','Water Buffalo','Tiger','Cat','Dragon','Snake','Horse','Goat'][y%12]])
+
+import unittest
+
+class TestCz(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(cz(2017),'Fire Rooster','example 1')
+
+ def test_ex2(self):
+ self.assertEqual(cz(1938),'Earth Tiger','example 2')
+
+unittest.main()
diff --git a/challenge-103/roger-bell-west/python/ch-2.py b/challenge-103/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..eb804da2eb
--- /dev/null
+++ b/challenge-103/roger-bell-west/python/ch-2.py
@@ -0,0 +1,31 @@
+#! /usr/bin/python3
+
+import csv
+def wp(ts,tn,csvfile):
+ td=(tn-ts)*1000;
+ aoa=list()
+ with open(csvfile) as csvfile:
+ cr=csv.reader(csvfile)
+ for row in cr:
+ aoa.append(row)
+ tp=sum(int(t[0]) for t in aoa)
+ td %= tp
+ for t in aoa:
+ t[0]=int(t[0])
+ if td < t[0]:
+ td=int(td/1000)
+ h=int(td/3600)
+ m=int(td/60) % 60
+ s=td % 60
+ return "{:02d}:{:02d}:{:02d} {:s}".format(h,m,s,t[1])
+ else:
+ td -= t[0]
+
+import unittest
+
+class TestWp(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(wp(1606134123,1614591276,'t2.csv'),'00:10:24 Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)','example 1')
+
+unittest.main()
diff --git a/challenge-103/roger-bell-west/raku/ch-1.p6 b/challenge-103/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..f75cbe4054
--- /dev/null
+++ b/challenge-103/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,22 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 2;
+
+is(cz(2017),'Fire Rooster','example 1');
+is(cz(1938),'Earth Tiger','example 2');
+
+sub cz($yy) {
+ my $y=$yy;
+ if ($y < 0) {
+ $y++;
+ }
+ $y%=60;
+ while ($y < 0) {
+ $y+=60;
+ }
+ return join(' ',
+ [qw|Metal Water Wood Fire Earth|].[floor($y/2)%5],
+ ['Monkey','Rooster','Dog','Pig','Rat','Water Buffalo','Tiger','Cat','Dragon','Snake','Horse','Goat'].[$y%12]);
+}
diff --git a/challenge-103/roger-bell-west/raku/ch-2.p6 b/challenge-103/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..5ed63d1a47
--- /dev/null
+++ b/challenge-103/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,34 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 1;
+
+is(wp(1606134123,1614591276,'t2.csv'),'00:10:24 Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)','example 1');
+
+sub wp($ts,$tn,$csvfile) {
+ my $td=($tn-$ts)*1000;
+ my $fh=open :r,$csvfile;
+ my @aoa;
+ for $fh.lines {
+ .chomp;
+ my ($len,$title)=$_.comb(/<-[,]>+/,2);
+ $title ~~ s/^\"//;
+ $title ~~ s/\"$//;
+ @aoa.push([$len,$title]);
+ }
+ my $tp=sum(map {$_[0]},@aoa);
+ $td %= $tp;
+ for @aoa -> @t {
+ if ($td < @t[0]) {
+ $td=floor($td/1000);
+ my $h=floor($td/3600);
+ my $m=floor($td/60) % 60;
+ my $s=$td % 60;
+ return sprintf('%02d:%02d:%02d %s',$h,$m,$s,@t[1]);
+ } else {
+ $td-=@t[0];
+ }
+ }
+}
+
diff --git a/challenge-103/roger-bell-west/ruby/ch-1.rb b/challenge-103/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..7b335d9cbe
--- /dev/null
+++ b/challenge-103/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,28 @@
+#! /usr/bin/ruby
+
+def cz(yy)
+ y=yy
+ if y<0 then
+ y += 1
+ end
+ y = y % 60
+ while y<0
+ y += 60
+ end
+ return [['Metal','Water','Wood','Fire','Earth'][(y/2).floor%5],
+ ['Monkey','Rooster','Dog','Pig','Rat','Water Buffalo','Tiger','Cat','Dragon','Snake','Horse','Goat'][y%12]].join(' ')
+end
+
+require 'test/unit'
+
+class TestCz < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal('Fire Rooster',cz(2017))
+ end
+
+ def test_ex2
+ assert_equal('Earth Tiger',cz(1938))
+ end
+
+end
diff --git a/challenge-103/roger-bell-west/ruby/ch-2.rb b/challenge-103/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..85778e0927
--- /dev/null
+++ b/challenge-103/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/ruby
+
+require 'csv'
+
+def wp(ts,tn,csvfile)
+ td=(tn-ts)*1000
+ aoa=Array.new
+ CSV.foreach(csvfile) do |row|
+ aoa.push([row[0].to_i,row[1]])
+ end
+ tp=aoa.map{|t| t[0]}.sum
+ td=td%tp
+ aoa.each do |t|
+ if td<t[0] then
+ td=(td/1000).floor
+ h=(td/3600).floor
+ m=(td/60).floor % 60
+ s=td % 60
+ return sprintf('%02d:%02d:%02d %s',h,m,s,t[1])
+ else
+ td -= t[0]
+ end
+ end
+end
+
+require 'test/unit'
+
+class TestWp < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal('00:10:24 Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)',wp(1606134123,1614591276,'t2.csv'))
+ end
+
+end
diff --git a/challenge-103/roger-bell-west/rust/ch-1.rs b/challenge-103/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..9d3efc7884
--- /dev/null
+++ b/challenge-103/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,29 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit
+
+#[test]
+fn test_ex1() {
+ assert_eq!(cz(2017),"Fire Rooster");
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(cz(1938),"Earth Tiger");
+}
+
+fn cz(yy: i32) -> String {
+ let mut y: i32=yy;
+ if y<0 {
+ y += 1;
+ }
+ y %= 60;
+ while y<0 {
+ y += 60;
+ }
+ let yu: usize=y as usize;
+ let mut out="".to_string();
+ out.push_str(vec!["Metal","Water","Wood","Fire","Earth"][(yu/2)%5]);
+ out.push_str(" ");
+ out.push_str(vec!["Monkey","Rooster","Dog","Pig","Rat","Water Buffalo","Tiger","Cat","Dragon","Snake","Horse","Goat"][yu%12]);
+ return out;
+}
diff --git a/challenge-103/roger-bell-west/rust/ch-2.rs b/challenge-103/roger-bell-west/rust/ch-2.rs
new file mode 100644
index 0000000000..c1b2015c9e
--- /dev/null
+++ b/challenge-103/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,47 @@
+// Cargo.toml needs:
+// [dependencies]
+// csv = "1.1"
+
+use std::fs::File;
+
+#[test]
+fn test_ex1() {
+ assert_eq!(wp(1606134123,1614591276,"t2.csv"),"00:10:24 Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)");
+}
+
+pub struct Track {
+ length: i64,
+ title: String
+}
+
+fn wp (ts: i64,tn: i64,csvfile: &str) -> String {
+ let mut td: i64=(tn-ts)*1000;
+ let file=File::open(&csvfile).unwrap();
+ let mut rdr = csv::ReaderBuilder::new()
+ .has_headers(false)
+ .from_reader(file);
+ let mut aoa: Vec<Track>=vec![];
+ for result in rdr.records() {
+ let record = result.unwrap();
+ aoa.push(Track {
+ length: record.get(0).unwrap().parse::<i64>().unwrap(),
+ title: record.get(1).unwrap().to_string()
+ });
+ }
+ let tp: i64=aoa.iter()
+ .map(|t| t.length)
+ .sum();
+ td %= tp;
+ for t in aoa {
+ if td < t.length {
+ td=td/1000;
+ let h=td/3600;
+ let m=(td/60) % 60;
+ let s=td % 60;
+ return format!("{:02}:{:02}:{:02} {}",h,m,s,t.title);
+ } else {
+ td -= t.length;
+ }
+ }
+ return "".to_string();
+}
diff --git a/challenge-103/roger-bell-west/t2.csv b/challenge-103/roger-bell-west/t2.csv
new file mode 100644
index 0000000000..4d66b079d7
--- /dev/null
+++ b/challenge-103/roger-bell-west/t2.csv
@@ -0,0 +1,7 @@
+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)"
+1678356,"Les Miserables Episode 4: Cosette (broadcast date: 1937-08-13)"
+1646043,"Les Miserables Episode 5: The Grave (broadcast date: 1937-08-20)"
+1714640,"Les Miserables Episode 6: The Barricade (broadcast date: 1937-08-27)"
+1714640,"Les Miserables Episode 7: Conclusion (broadcast date: 1937-09-03)"
diff --git a/challenge-103/sgreen/README.md b/challenge-103/sgreen/README.md
index 6fb5a4942c..96e32e9edb 100644
--- a/challenge-103/sgreen/README.md
+++ b/challenge-103/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 102
+# The Weekly Challenge 103
-Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-102-57jb)
+Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-103-1hpm)
diff --git a/challenge-103/sgreen/blog.txt b/challenge-103/sgreen/blog.txt
new file mode 100644
index 0000000000..82182bff1e
--- /dev/null
+++ b/challenge-103/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/weekly-challenge-103-1hpm
diff --git a/challenge-103/sgreen/perl/ch-1.pl b/challenge-103/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..a6f11e382b
--- /dev/null
+++ b/challenge-103/sgreen/perl/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+sub main {
+ my $year = shift;
+
+ # Sanity check
+ die "You must enter a year\n" if not defined $year;
+ die "The year does not look like a positive integer\n" unless $year =~ /^\d+$/;
+
+ my @zodiacs = (qw(Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat));
+ my @elements = (qw(Metal Water Wood Fire Earth));
+
+ # State the zodiac sign
+ say $elements[ int( $year / 2 ) % 5 ], ' ', $zodiacs[ $year % 12 ];
+}
+
+main(@ARGV);
diff --git a/challenge-103/sgreen/perl/ch-2.pl b/challenge-103/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..0cac111e8e
--- /dev/null
+++ b/challenge-103/sgreen/perl/ch-2.pl
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+use Text::CSV 'csv';
+use List::Util 'sum';
+
+sub main {
+ my ( $start, $now, $file ) = @_;
+
+ # Sanity check
+ die "You must enter the start time\n" unless $start;
+ die "You must enter the current time\n" unless $now;
+ die "You must enter the file name\n" unless $file;
+ die "The start time must be an integer (seconds since epoch)\n" unless $start =~ /^\d+$/;
+ die "The current time must be an integer (seconds since epoch)\n" unless $now =~ /^\d+$/;
+ die "The current time cannot be earlier than the start time\n" if $now < $start;
+ die "The file '$file' does not exist (or is not a file)\n" unless -f $file;
+
+ # Read the CSV file, and find out the total length
+ my $tracks = csv( { in => $file } );
+ my $playlist_length = sum( map { $_->[0] } @$tracks );
+
+ # Find out how far through the playlist we are
+ my $playlist_position = ( $now - $start ) * 1000 % $playlist_length;
+
+ # Work through the play list to see what song is playing
+ while ( my $row = shift @$tracks ) {
+ my ( $track_length, $track_name ) = @$row;
+ if ( $track_length <= $playlist_position ) {
+ $playlist_position -= $track_length;
+ next;
+ }
+
+ # We are playing this track. Get the number of seconds we are into the track and display this
+ my $secs = int( $playlist_position / 1000 );
+ say sprintf '%s %02d:%02d:%02d', $track_name, int( $secs / 3_600 ), int( $secs % 3_600 / 60 ), $secs % 60;
+ last;
+ }
+}
+
+main(@ARGV);
diff --git a/stats/pwc-current.json b/stats/pwc-current.json
index 11c61a31a0..48ad74a6e4 100644
--- a/stats/pwc-current.json
+++ b/stats/pwc-current.json
@@ -1,8 +1,39 @@
{
+ "chart" : {
+ "type" : "column"
+ },
+ "plotOptions" : {
+ "series" : {
+ "borderWidth" : 0,
+ "dataLabels" : {
+ "enabled" : 1,
+ "format" : "{point.y}"
+ }
+ }
+ },
"drilldown" : {
"series" : [
{
- "name" : "Luca Ferrari",
+ "name" : "E. Choroba",
+ "id" : "E. Choroba",
+ "data" : [
+ [
+ "Perl",
+ 2
+ ]
+ ]
+ },
+ {
+ "data" : [
+ [
+ "Perl",
+ 2
+ ]
+ ],
+ "id" : "James Smith",
+ "name" : "James Smith"
+ },
+ {
"data" : [
[
"Raku",
@@ -13,17 +44,56 @@
2
]
],
+ "name" : "Luca Ferrar