Mas o array não vem como referencia?<br><br clear="all">Just another Perl Hacker,<br>Fernando (SmokeMachine)<br><a href="http://perl-e.org">http://perl-e.org</a><br>Sent from Rio De Janeiro, RJ, Brazil<br>
<br><br><div class="gmail_quote">Em 3 de fevereiro de 2010 19:00, Blabos de Blebe <span dir="ltr"><<a href="mailto:blabos@gmail.com">blabos@gmail.com</a>></span> escreveu:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Sacanagem...<br>
<br>
sub drop{($a,@b)=@_;$a=0if$a<0;@b>1?@b[$a..$#b]:substr$b[0],$a}<br>
<div><div></div><div class="h5"><br>
<br>
<br>
2010/2/3 Fernando Oliveira <<a href="mailto:fernandocorrea@gmail.com">fernandocorrea@gmail.com</a>>:<br>
> 64:<br>
><br>
> sub drop{($a,$b)=@_;$a=0if$a<0;ref$b?@$b[$a..$#$b]:substr$b,$a}<br>
><br>
> Just another Perl Hacker,<br>
> Fernando (SmokeMachine)<br>
> <a href="http://perl-e.org" target="_blank">http://perl-e.org</a><br>
> Sent from Rio De Janeiro, RJ, Brazil<br>
><br>
><br>
> Em 3 de fevereiro de 2010 18:33, Nilson Santos Figueiredo Jr.<br>
> <<a href="mailto:acid06@gmail.com">acid06@gmail.com</a>> escreveu:<br>
>><br>
>> Eu tenho certeza que vai dar pra alguém melhorar, ainda tá grande.<br>
>> Mas se eu ficar mais tempo aqui tentando... vou ter meus dias inteiros<br>
>> pra ficar brincando de Golf ao invés de ter um trabalho. ;-)<br>
>><br>
>> -Nilson<br>
>><br>
>> 2010/2/3 breno <<a href="mailto:breno@rio.pm.org">breno@rio.pm.org</a>>:<br>
>> > Nilson, o final deveria dizer "mas é igual à versão do Nilson". Como<br>
>> > eu fiz um monte de edições e contagens, acabou q foi enviado sem e eu<br>
>> > nao percebi. O crédito e a menor tacada ainda são seus :-)<br>
>> ><br>
>> > []s<br>
>> ><br>
>> > -b<br>
>> ><br>
>> > 2010/2/3 Nilson Santos Figueiredo Jr. <<a href="mailto:acid06@gmail.com">acid06@gmail.com</a>>:<br>
>> >> Breno,<br>
>> >><br>
>> >> Essa que você mandou é exatamente igual a minha anterior, mas ao invés<br>
>> >> de $a,$b eu uso $n,$w.<br>
>> >> Tem 65 chars fora e 55 dentro. Eu estava contando tudo.<br>
>> >><br>
>> >> Mas essa tem um problema que retorna undef em alguns casos. Aí o<br>
>> >> Mantovani que tem que falar se é certo ou não.<br>
>> >><br>
>> >> -Nilson<br>
>> >><br>
>> >> 2010/2/3 breno <<a href="mailto:breno@rio.pm.org">breno@rio.pm.org</a>>:<br>
>> >>> fernando, nao pode funcionar pra valores negativos, vai entender :-)<br>
>> >>><br>
>> >>> acredito que assim funcione:<br>
>> >>><br>
>> >>> sub drop{($a,$b)=@_;$a=0if$a<0;ref$b?@$b[$a..$#{$b}]:substr$b,$a}<br>
>> >>><br>
>> >>> 55 chars (dentro da sub).<br>
>> >>><br>
>> >>><br>
>> >>><br>
>> >>> 2010/2/3 Fernando Oliveira <<a href="mailto:fernandocorrea@gmail.com">fernandocorrea@gmail.com</a>>:<br>
>> >>>> 54:<br>
>> >>>><br>
>> >>>> sub drop{($a,$b)=@_;ref$b?@$b[$a..$#{$b}]:substr$b,$a}<br>
>> >>>><br>
>> >>>> Just another Perl Hacker,<br>
>> >>>> Fernando (SmokeMachine)<br>
>> >>>> <a href="http://perl-e.org" target="_blank">http://perl-e.org</a><br>
>> >>>><br>
>> >>>><br>
>> >>>><br>
>> >>>> Em 3 de fevereiro de 2010 17:54, Nilson Santos Figueiredo Jr.<br>
>> >>>> <<a href="mailto:acid06@gmail.com">acid06@gmail.com</a>> escreveu:<br>
>> >>>>><br>
>> >>>>> Pronto, 80 caracteres (sem strict).<br>
>> >>>>> Estou satisfeito, agora é com vocês:<br>
>> >>>>><br>
>> >>>>> sub<br>
>> >>>>><br>
>> >>>>> drop{($n,$w)=@_;$n=0if$n<0;ref$w?@$w[$n..$#{$w}]:$n>length$w?'':substr$w,$n}<br>
>> >>>>><br>
>> >>>>> -Nilson<br>
>> >>>>><br>
>> >>>>> 2010/2/3 Nilson Santos Figueiredo Jr. <<a href="mailto:acid06@gmail.com">acid06@gmail.com</a>>:<br>
>> >>>>> > Melhorando a minha solução anterior, 85 caracteres (83 tirando o<br>
>> >>>>> > my):<br>
>> >>>>> ><br>
>> >>>>> > sub drop{my($n,$w)=@_;$n=0<br>
>> >>>>> > if$n<0;ref$w?@$w[$n..$#{$w}]:$n>length$w?'':substr($w,$n)}<br>
>> >>>>> ><br>
>> >>>>> > -Nilson<br>
>> >>>>> ><br>
>> >>>>> > 2010/2/3 Nilson Santos Figueiredo Jr. <<a href="mailto:acid06@gmail.com">acid06@gmail.com</a>>:<br>
>> >>>>> >> Uma solução, warnings and strict compliant:<br>
>> >>>>> >><br>
>> >>>>> >> sub drop {<br>
>> >>>>> >> my ($n, $w) = @_;<br>
>> >>>>> >> $n = 0 if $n < 0;<br>
>> >>>>> >> return ( $n > length $w ? '' : substr($w,$n) ) if !ref $w;<br>
>> >>>>> >> @$w[$n..$#{$w}];<br>
>> >>>>> >> }<br>
>> >>>>> >><br>
>> >>>>> >> Se colocar tudo em uma linha:<br>
>> >>>>> >><br>
>> >>>>> >> sub drop{my($n,$w)=@_;$n=0<br>
>> >>>>> >><br>
>> >>>>> >> if$n<0;return($n>length$w?'':substr($w,$n))if!ref$w;@$w[$n..$#{$w}];}<br>
>> >>>>> >><br>
>> >>>>> >> 96 caracteres. Deve dar pra melhorar bastante ainda. Se tirar o<br>
>> >>>>> >> "my"<br>
>> >>>>> >> pra deixar de ser strict compliant, cai pra 94.<br>
>> >>>>> >><br>
>> >>>>> >> -Nilson<br>
>> >>>>> >><br>
>> >>>>> >> 2010/2/3 Daniel de Oliveira Mantovani<br>
>> >>>>> >> <<a href="mailto:daniel.oliveira.mantovani@gmail.com">daniel.oliveira.mantovani@gmail.com</a>>:<br>
>> >>>>> >>> Olá pessoal, o desafio envolve a função drop do Haskell:<br>
>> >>>>> >>><br>
>> >>>>> >>> <haskell><br>
>> >>>>> >>> ghci> myDrop 2 "foobar"<br>
>> >>>>> >>> "obar"<br>
>> >>>>> >>> ghci> myDrop 4 "foobar"<br>
>> >>>>> >>> "ar"<br>
>> >>>>> >>> ghci> myDrop 4 [1,2]<br>
>> >>>>> >>> []<br>
>> >>>>> >>> ghci> myDrop 0 [1,2]<br>
>> >>>>> >>> [1,2]<br>
>> >>>>> >>> ghci> myDrop 7 []<br>
>> >>>>> >>> []<br>
>> >>>>> >>> ghci> myDrop (-2) "foo"<br>
>> >>>>> >>> "foo"<br>
>> >>>>> >>> </haskell><br>
>> >>>>> >>><br>
>> >>>>> >>> Eu fiz em Perl, para ficar claro:<br>
>> >>>>> >>><br>
>> >>>>> >>> <perl><br>
>> >>>>> >>> sub drop {<br>
>> >>>>> >>> my ( $n, $xs ) = @_;<br>
>> >>>>> >>> if ( ref $_[1] ne 'ARRAY' ) {<br>
>> >>>>> >>> $n <= 0 ? return $_[1] : return substr( $_[1], $n );<br>
>> >>>>> >>> }<br>
>> >>>>> >>> if ( $n <= 0 || !@_ ) {<br>
>> >>>>> >>> return @{$xs};<br>
>> >>>>> >>> }<br>
>> >>>>> >>> else {<br>
>> >>>>> >>> shift @{$xs};<br>
>> >>>>> >>> drop( ( $n - 1 ), $xs );<br>
>> >>>>> >>> }<br>
>> >>>>> >>> }<br>
>> >>>>> >>> </perl><br>
>> >>>>> >>><br>
>> >>>>> >>> Exemplos:<br>
>> >>>>> >>> mantovani@mantovani-desktop:~/Perl/Funcional$ perl -MHaskell -E<br>
>> >>>>> >>> 'say<br>
>> >>>>> >>> $_ for drop(3,[1,2,3,4,5,6])'<br>
>> >>>>> >>> 4<br>
>> >>>>> >>> 5<br>
>> >>>>> >>> 6<br>
>> >>>>> >>><br>
>> >>>>> >>> mantovani@mantovani-desktop:~/Perl/Funcional$ perl -MHaskell -E<br>
>> >>>>> >>> 'say<br>
>> >>>>> >>> $_ for drop(1,"ofernandoagoragolf")'<br>
>> >>>>> >>> fernandoagoragolf<br>
>> >>>>> >>><br>
>> >>>>> >>> mantovani@mantovani-desktop:~/Perl/Funcional$ perl -MHaskell -E<br>
>> >>>>> >>> 'say<br>
>> >>>>> >>> $_ for drop(2,["mantovani","garu","fernando","blabos"])'<br>
>> >>>>> >>> fernando<br>
>> >>>>> >>> blabos<br>
>> >>>>> >>><br>
>> >>>>> >>> mantovani@mantovani-desktop:~/Perl/Funcional$ perl -MHaskell -E<br>
>> >>>>> >>> 'say<br>
>> >>>>> >>> $_ for drop(-1,["mantovani","garu","fernando","blabos"])'<br>
>> >>>>> >>> mantovani<br>
>> >>>>> >>> garu<br>
>> >>>>> >>> fernando<br>
>> >>>>> >>> blabos<br>
>> >>>>> >>><br>
>> >>>>> >>> mantovani@mantovani-desktop:~/Perl/Funcional$ perl -MHaskell -E<br>
>> >>>>> >>> 'say<br>
>> >>>>> >>> $_ for drop(-1,"mantovani")'<br>
>> >>>>> >>> mantovani<br>
>> >>>>> >>><br>
>> >>>>> >>> mantovani@mantovani-desktop:~/Perl/Funcional$ perl -MHaskell -E<br>
>> >>>>> >>> 'say<br>
>> >>>>> >>> $_ for drop(10,"mantovani")'<br>
>> >>>>> >>><br>
>> >>>>> >>> --<br>
>> >>>>> >>> "If you’ve never written anything thoughtful, then you’ve never<br>
>> >>>>> >>> had<br>
>> >>>>> >>> any difficult, important, or interesting thoughts. That’s the<br>
>> >>>>> >>> secret:<br>
>> >>>>> >>> people who don’t write, are people who don’t think."<br>
>> >>>>> >>> _______________________________________________<br>
>> >>>>> >>> Rio-pm mailing list<br>
>> >>>>> >>> <a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
>> >>>>> >>> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
>> >>>>> >>><br>
>> >>>>> >><br>
>> >>>>> ><br>
>> >>>>> _______________________________________________<br>
>> >>>>> Rio-pm mailing list<br>
>> >>>>> <a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
>> >>>>> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
>> >>>><br>
>> >>>><br>
>> >>>> _______________________________________________<br>
>> >>>> Rio-pm mailing list<br>
>> >>>> <a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
>> >>>> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
>> >>>><br>
>> >>> _______________________________________________<br>
>> >>> Rio-pm mailing list<br>
>> >>> <a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
>> >>> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
>> >>><br>
>> >> _______________________________________________<br>
>> >> Rio-pm mailing list<br>
>> >> <a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
>> >> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
>> >><br>
>> > _______________________________________________<br>
>> > Rio-pm mailing list<br>
>> > <a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
>> > <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
>> ><br>
>> _______________________________________________<br>
>> Rio-pm mailing list<br>
>> <a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
>> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
><br>
><br>
> _______________________________________________<br>
> Rio-pm mailing list<br>
> <a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
><br>
_______________________________________________<br>
Rio-pm mailing list<br>
<a href="mailto:Rio-pm@pm.org">Rio-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/listinfo/rio-pm</a><br>
</div></div></blockquote></div><br>