in reply to Perl Solution to Spotify Programming Puzzle
#! perl -slw use strict; my $n = <>; my %counts; ++$counts{ $_ } for split ' ', do{ local $/, <> }; my @sorted = sort{ $counts{$b} <=> $counts{$a} }keys %counts; my( $i, $min, $total ) = (0) x 3; ++$min while ( $total += $counts{ $sorted[ $i++ ] } ) < $n; print $min+1; print for @sorted[ 0 .. $min ];
Tests:
C:\test>SpotifyComp.pl 4 1009 2000 1009 2001 1002 2002 1003 2002 ^Z 2 2002 1009 C:\test>SpotifyComp.pl 2 1009 2011 1017 2011 ^Z 1 2011
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl Solution to Spotify Programming Puzzle
by repellent (Priest) on Aug 25, 2011 at 05:34 UTC | |
|
Re^2: Perl Solution to Spotify Programming Puzzle
by ::rml:: (Sexton) on Aug 25, 2011 at 23:50 UTC | |
by BrowserUk (Patriarch) on Aug 26, 2011 at 00:08 UTC |