#!/usr/bin/env perluse List::Util qw(min);while (<>) { my ( @solos, %count_of ) = (); map { chomp; ++$count_of{$_} } split(/,/); while ( my ( $num, $counts ) = each(%count_of) ) { push @solos, $num if $counts == 1; } @solos ? printf "%d\n", min @solos : print "-1\n";}
1,1,1,1,2,2,2,3,3,4 1,2,3,4,5,5,4,3,2,1 3,1,4,1,5,9,2,6,5,3,5
4 -1 2
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!