icymint3, are you sure that code is in VB? That looks more like C.....
Code:function parseSet(set) { var result = [], lastIndex = 0, list = set.split(','); for (var i = 0, len = list.length; i < len; i++) { var range = list[i].split('-'); if (range.length == 1) result[lastIndex++] = range[0] - 0; else for (var num = range[0] - 0, max = range[1] - 0; num <= max; num++) result[lastIndex++] = num; } return result; } parseSet("1,2,3,17,81,8-17,11,12,21-23,99,100-103");
Cultured in Aggression and Koding like a Warrior!!
“Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
"The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein
icymint3, are you sure that code is in VB? That looks more like C.....
.
SHANTI II - Ubuntu 13.04 64bit Desktop
HP Pav G60-236US 3GB RAM Laptop, Ubuntu 13.04 64bit and Win7 Home
"So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"
Changes to posting in Classifieds
sorry, that was javascript... i just did it in my browser, couldnt bother fire up my IDE to do VB, im not a fan of VB either
Cultured in Aggression and Koding like a Warrior!!
“Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
"The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein
Your code is less but you didn't check for duplications.
When I was constructing the function, I could have done that part in another function but I wanted this function to be self reliant.
Unuh idle eh?
.
8800GT - AMD X2 - 4GB Ram - 600GB Disk - M Audio Revolution 7.1 - Sky is the Limit
Felt lazy, so I just ripped the relevant code from my AutoIt3 script and removed a few comments and unrelated statements. All you'd need to do is zap the GetChap function and use it's first argument to build your array. 12 linesCode:$chapters = StringSplit( $chapters, "," ) For $inc = 1 To $chapters[ 0 ] $curChap = $chapters[ $inc ] If StringInStr( $curChap, "-" ) Then $curChap = StringSplit( $curChap, "-" ) For $inc2 = $curChap[ 1 ] To $curChap[ 2 ] FileWriteLine( $dlLog, "Grabbing chapter " & $inc2 ) GetChap( $inc2, $firstPage ) Next Else FileWriteLine( $dlLog, "Grabbing chapter " & $curChap ) GetChap( $curChap, $firstPage ) EndIf Next, easy to convert to VB since they're both BASIC descendants.
icymint3, you're cheating. Not because it's a free-form language, the code should be easily readable. You should've broken those into logical lines
(giving you 13+ lines
)...
Are you saying that programming is idling? (I for one am ready to attack...)
Rooted HTC Amaze 4G, Android 4.1.2 PA/AOKP/CM10 on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 4.0.3 Android Revolution HD; Laptop: HP HDX, 2.13GHzx2, 4GB, 128GB SSD, 1TB xHDD, Win7
Facebook page: Skeleville Software Solutions
Code:void main(){ char set[] = "1,3,5-7,9,11,23-27,30", currChar, *lowerRange = set, *upperRange = set; int low, hi, i = 0; do{ currChar = set[i]; // get the char before we destroy the original string if(currChar == '-'){ // check if we need a pointer to second number upperRange = &set[i] + 1; // point upper to next char set[i] = 0; // end the lower range string } if(currChar == ',' || set[i + 1] == 0){ // check for comma or end of string if(currChar == ',') set[i] = 0; // end the 'number string' for(low = atoi(lowerRange), hi = atoi(upperRange); low <= hi; low++) printf("%d, ", low); lowerRange = upperRange = &set[i] + 1; // point lower/upper to next char } } while(set[++i] != 0); }
Cultured in Aggression and Koding like a Warrior!!
“Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
"The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein
C# ... this would be shorter with Linq
Code:public static void RunSnippet() { string set = "1,3,5-7,9,11,23-27,30"; string[] range; int low, hi; foreach(string entry in set.Split(',')) for(range = entry.Split('-'), low = int.Parse(range[0]), hi = int.Parse(range[range.Length -1]); low <= hi ; low++) W("{0}, ", low); }
Cultured in Aggression and Koding like a Warrior!!
“Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
"The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein