Re: Golf for unique digits
by BrowserUk (Patriarch) on Jan 09, 2013 at 11:40 UTC
|
C:\test>perl -nlE"s[(.)(?=.*?\1)][]g;say length;"
1987
4
2013
4
2113
3
122398723456321467891356178653534
9
1111111111111111
1
121212121212121212121212
2
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [Watch: Dir/Any] [d/l] |
|
perl -nlE"say 0+s/(.)(?!.*\1)//g"
| [reply] [Watch: Dir/Any] [d/l] |
|
perl -nlE"say s/(.)(?!.*\1)//g"
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
|
|
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
|
You can drop the final semicolon, too. How comes there are not two of them? :-)
| [reply] [Watch: Dir/Any] |
Re: Golf for unique digits
by choroba (Cardinal) on Jan 09, 2013 at 11:31 UTC
|
perl -E'$y=2013;$y=~/$_/&&$c++for 0..9;say$c'
Update: and -> &&. Thanks space_monk.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
|
perl -E'$y=2013;$c+=$y=~$_ for 0..9;say$c'
perl -E'$y=2013;say~~map$y=~$_,0..9'
| [reply] [Watch: Dir/Any] [d/l] |
|
Yup, just answered my own question and got a birdie
perl -E '$y=2013;$y=~/$_/&&$c++for 0..9;say$c'
A Monk aims to give answers to those who have none, and to learn from those who know more.
| [reply] [Watch: Dir/Any] [d/l] |
Re: Golf for unique digits
by davido (Cardinal) on Jan 10, 2013 at 09:34 UTC
|
Hmm, this doesn't beat tye's, but matches it, with a different technique. I wish I could find a way to shave a stroke using this method, but I think I've reached the dead end.
perl -lnE'@h{/./g}--;say~~keys%h'
And this adaptation of tye's shaves a stroke:
perl -lnE'say~~s/(.)(?!.*\1)//g'
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
perl -plE"@h{/./g}++;$_=keys%h"
And this saves 2 more over your version of tye's:
perl -lpE'$_=s/(.)(?!.*\1)//g'
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
perl -plE"\@h{/./g};$_=keys%h"
| [reply] [Watch: Dir/Any] [d/l] |
Re: Golf for unique digits
by LanX (Saint) on Jan 09, 2013 at 11:41 UTC
|
> perl -E'$_=2013;@h{split//}=();say 0+keys%h'
4
UPDATE: please ignore, breaks the rulez
| [reply] [Watch: Dir/Any] [d/l] |
|
as a compensation a new approach: =)
> perl -ple'$_=join"",sort split//;y///cs;$_=length'
1987
4
1988
3
2012
3
2013
4
EDIT: shortened the say away...
| [reply] [Watch: Dir/Any] [d/l] |
|
Isn't this the %uniq method?
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: Golf for unique digits
by space_monk (Chaplain) on Jan 09, 2013 at 11:47 UTC
|
choroba's method with ampersands and removing variable
perl -E'2213=~/$_/&&$c++for 0..9;say$c'
A Monk aims to give answers to those who have none, and to learn from those who know more.
| [reply] [Watch: Dir/Any] [d/l] |
|
Even shorter: perl -E'say~~grep+2013=~$_,0..9'
| [reply] [Watch: Dir/Any] [d/l] |
Re: Golf for unique digits
by trizen (Hermit) on Jan 09, 2013 at 13:03 UTC
|
perl -E'$_="2013";/(.)(?=.*\1)(?{++$%})(?!)/||say+y+++c-$%' | [reply] [Watch: Dir/Any] [d/l] |