Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:
Inspired by the fact that 2013 is the first year since 1987 which has four unique digits, what's your best code to determine the number of unique digits in a number?
Here's what I ended up with, skipping the %unique method:
$y = 2013; ($y = join('',sort(split(//,$y)))) =~ tr/0-9//s; print "unique digits: " . length($y) . $/;
I'm sure there's something smarter.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Golf for unique digits
by BrowserUk (Patriarch) on Jan 09, 2013 at 11:40 UTC | |
by tye (Sage) on Jan 09, 2013 at 18:42 UTC | |
by BrowserUk (Patriarch) on Jan 09, 2013 at 18:56 UTC | |
by BrowserUk (Patriarch) on Jan 09, 2013 at 18:52 UTC | |
by LanX (Saint) on Jan 09, 2013 at 19:05 UTC | |
by BrowserUk (Patriarch) on Jan 09, 2013 at 19:10 UTC | |
by AnomalousMonk (Archbishop) on Jan 09, 2013 at 13:03 UTC | |
by BrowserUk (Patriarch) on Jan 09, 2013 at 13:10 UTC | |
by AnomalousMonk (Archbishop) on Jan 09, 2013 at 14:11 UTC | |
by choroba (Cardinal) on Jan 09, 2013 at 13:36 UTC | |
Re: Golf for unique digits
by choroba (Cardinal) on Jan 09, 2013 at 11:31 UTC | |
by space_monk (Chaplain) on Jan 09, 2013 at 11:39 UTC | |
by eyepopslikeamosquito (Archbishop) on Jan 09, 2013 at 20:14 UTC | |
by space_monk (Chaplain) on Jan 09, 2013 at 11:41 UTC | |
Re: Golf for unique digits
by davido (Cardinal) on Jan 10, 2013 at 09:34 UTC | |
by BrowserUk (Patriarch) on Jan 10, 2013 at 09:58 UTC | |
by eyepopslikeamosquito (Archbishop) on Jan 10, 2013 at 10:15 UTC | |
Re: Golf for unique digits
by LanX (Saint) on Jan 09, 2013 at 11:41 UTC | |
by LanX (Saint) on Jan 09, 2013 at 12:25 UTC | |
by choroba (Cardinal) on Jan 09, 2013 at 11:45 UTC | |
by LanX (Saint) on Jan 09, 2013 at 11:52 UTC | |
Re: Golf for unique digits
by space_monk (Chaplain) on Jan 09, 2013 at 11:47 UTC | |
by trizen (Hermit) on Jan 09, 2013 at 18:28 UTC | |
Re: Golf for unique digits
by trizen (Hermit) on Jan 09, 2013 at 13:03 UTC |
Back to
Seekers of Perl Wisdom