Somone posted what seemed like a homework question here. I replied in a golfish format, and mentioned the fact to the CB. Chemboy suggested posting it as a real golf, wherupon CheeseLord stepped in and said that in a similer reply, which also called for Golf, tachyon had provided an even better answer than mine.
Seemed like an interesting problem, so I present the Nth annual rangify function golf contest!
Problem
Given an unsorted list of unique positive integers convert this list into a "rangeified" form, where all consequtive sequences of numbers are coded into a BEGIN-END format.
For instance, the list 1089,3,4,0,5,6,7,99,832,1087,831,1088
would become 0,3-7,99,831-832,1087-1089
In order to keep it interesting answers in three catagories will be allowed, also code _must_ be strict safe.
Thanks and apologies (for mispelling his name) to CheeseLord for a couple of tips. But from what I've heard it wont help me much....# 1 2 3 4 5 6 # 01234567890123456789012345678901234567890123456789012345678901234567 +890 sub demerphq{ @0=sort{$a<=>$b}@_;$_=":@0";1 while s/:((\d+)(-(\d+))?) (\d+)/ $5-$2-1&&$5-$4-1?"$1,:$5":":$2-$5"/e;y/://d;$_ }
:-)
Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)
In reply to (Golf) Rangify Array by demerphq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |