Re: Golf: ROT-n
by tilly (Archbishop) on Nov 09, 2004 at 18:54 UTC
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
Re: Golf: ROT-n
by dragonchild (Archbishop) on Nov 09, 2004 at 16:31 UTC
|
rotn.pl 4 xyz
----
|}~
It should return 'bcd'. The immediate un-golf'ed fix would be:
print chr(((ord()+$n-ord('a'))%26)+ord('a'))for@_
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: Golf: ROT-n
by dragonchild (Archbishop) on Nov 09, 2004 at 16:46 UTC
|
# 1 2 3 4 5
# 3456789 123456789 123456789 123456789 123456789 1234567890
$n=shift;print chr(($n-97+ord)%26+97)for split//,pop
|
52 strokes
Update:
# 1 2 3 4 5
# 3456789 123456789 123456789 123456789 123456789 1234567890
print chr 97+($ARGV[0]-97+ord)%26for pop=~/./g
|
46 strokes
Update:
# 1 2 3 4 5
# 3456789 123456789 123456789 123456789 123456789 1234567890
print chr 97+($ARGV[0]+7+ord)%26for pop=~/./g
|
45 strokes, thanks to cLive_;-)
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
Ah, but -97%26 == 7%26 - so there's another character ;-)
cLive ;-)
| [reply] [Watch: Dir/Any] |
|
What do you mean?
Update: Duh! :-)
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] [Watch: Dir/Any] |
Re: Golf: ROT-n (33)
by eyepopslikeamosquito (Archbishop) on Nov 09, 2004 at 23:19 UTC
|
# 345678 1 2345678 2 2345678 3 2345678 4 2345678
y/a-z/b-za/for($\=pop)x+pop;print
|
| [reply] [Watch: Dir/Any] [d/l] |
|
# 345678 1 2345678 2 2345678 3 2345678 4 2345678
y//-za/cfor($_=pop)x+pop;print
(that's \001 as start of the range)
|
| [reply] [Watch: Dir/Any] [d/l] |
Re: Golf: ROT-n
by fruiture (Curate) on Nov 09, 2004 at 17:41 UTC
|
I couldn't find a shorter solution for the character-based approach. So this is different, maybe it can be made even shorter than 54.
# 1 2 3 4 5
# 3456789 123456789 123456789 123456789 123456789 123456789
eval'tr/a-z/'.chr(97+shift).'-za-z/for@ARGV;print pop'
|
update: changed spoiler hiding to standard way.
| [reply] [Watch: Dir/Any] [d/l] |
|
Nicely done. I always forget the ins-and-outs of tr///.
A few improvements:
# 1 2 3 4 5
# 3456789 123456789 123456789 123456789 123456789 123456789
$_=pop;eval'y/a-z/'.chr(97+pop).'-za-z/';print
|
And you're at 46 strokes
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] [d/l] |
Re: Golf: ROT-n
by fruiture (Curate) on Nov 09, 2004 at 16:48 UTC
|
I could make it to 37.
# 1 2 3
# 3456789 123456789 123456789 123456789
print map{chr$ARGV[0]+ord}split//,pop
# sadly i could not come up with a split-less soution that
# is short enough
|
Update: ROT is for ROTate, so this is not a solution to the problem. Working on it...
Update2: changed HTML to properly hide code
| [reply] [Watch: Dir/Any] [d/l] |
|
ok, solving the problem, 58, or 59 if the ambiguity warning disturbs you.
# 1 2 3 4 5
# 3456789 123456789 123456789 123456789 123456789 123456789
print map{chr+(($_=$ARGV[0]+ord)>122?-26:0)+$_}split//,pop ;
print map{chr((($_=$ARGV[0]+ord)>122?-26:0)+$_)}split//,pop ;
|
update: changed hiding code here, too
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
Re: Golf: ROT-n
by BrowserUk (Patriarch) on Nov 09, 2004 at 19:03 UTC
|
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
|
[19:39:27.71] P:\test>perl -v
This is perl, v5.8.4 built for MSWin32-x86-multi-thread
(with 3 registered patches, see perl -V for more detail)
Copyright 1987-2004, Larry Wall
Binary build 810 provided by ActiveState Corp. http://www.ActiveState.
+com
ActiveState is a division of Sophos.
Built Jun 1 2004 11:52:21
Perl may be copied only under the terms of either the Artistic License
+ or the
GNU General Public License, which may be found in the Perl 5 source ki
+t.
Complete documentation for Perl, including FAQ lists, should be found
+on
this system using `man perl' or `perldoc perl'. If you have access to
+ the
Internet, point your browser at http://www.perl.com/, the Perl Home Pa
+ge.
[19:40:24.59] P:\test>perl -e"die map{($i)=@ARGV;$_++while$i--;chop}sp
+lit'',pop" 4 pqrstuvwxyz
tuvwxyzabcd at -e line 1.
I saw your for tr version just after I posted which is in a similar vien but much shorter. Nice work++.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
| [reply] [Watch: Dir/Any] [d/l] |
|
Re: Golf: ROT-n
by borisz (Canon) on Nov 09, 2004 at 20:38 UTC
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
perl -we" $_=pop;y/a-z/b-za/for$x(1..pop);print"
syntax error at -e line 1, near "$x("
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
| [reply] [Watch: Dir/Any] [d/l] |
|
I know, I asked what is wrong with that line?
| [reply] [Watch: Dir/Any] |
|
Re: Golf: ROT-n
by belg4mit (Prior) on Nov 18, 2004 at 09:57 UTC
|
Just adding some keywords for Super Search and a link to prior art on caesar/cesar shifts Caesar Shift.
--
I'm not belgian but I play one on TV.
| [reply] [Watch: Dir/Any] |