|
|
|
|
|
by dsp1234
3464 days ago
|
|
Do you have an example which correctly solves the problem but takes too long? Behold var AGESORT = rows.bubblesort("AGE ASCENDING")
var AGESORT1 = rows.bubblesort("AGE DESCENDING")
var MALE = "None"
var MALE1 = "None"
for row in AGESORT
if row.isMale
MALE = row
break
for row in AGESORT1
if row.isMale
MALE1 = row
break
print "Min age: " + MALE
print "Max age: " + MALE1
Stuff like this is usually the result of thoughts like "Ok, I'll break this problem into two, then combine the pieces. First I'll find the minimum age, which is easy once I sort the rows. Done. Ok, now I can see I can slightly alter that code so that it finds the max age! Now, I just put the pieces of code together, and do a little code organization to put like with like. I" |
|