devdraft challenge - october
[reference]
- i] code-devdraft-2015-09.txt
- i] code-devdraft-2015-10.txt - includes lastSave,
- x] http://jsfiddle.net/nh8mLeda/ - readLines3() - loop
- x] http://jsfiddle.net/rfk6z897/ - calcTime2()
- ]
[notes]
- ] INPUTS
- ] numberAttractions = int A //
- ] averageTimeBetweenPoints = [] ints //
- ] numberOfQueries = 3
- ] qry-n-line1 (numberAttractions) // # of attractions each user will visit
- ] qry-n-line2-POINTS (index of times) // index value of getting TimeValues
- ] ....
- ] INPUT - example - 1 DATA
- ] timeValues = [4, 2, 5, 1, 3, 8];
- ] number attractractions = 2,
- ] 2
- ] 0 1 ( attraction, qry-n)
- ] 3
- ] 0,3,5
- ] 4
- ] 0, 4, 2, 5
- ] PROCESS
- ] NEW task IN i] calculateClockWise(averageTimeBetweenPoints, qry-n-line2-POINTS )
- ] var totalTime =
- ] foreach in points totalTime += averageTime[points[i]];
- ] return totalTime
- ] NEW task IN i] calculateCounterClockWise()
- i] see above
- ] NEW task IN calculateQuickest()
- ] compare clockwise time
- ] return quickest time
- ] NEW task IN calcTime()
- ]
- ] NEW task IN calcTime2()
- ]
- ] NEW task IN readLines3()
- x] get the 'data' for each query - pushed into qData array
- x] data = numberAttractions, indexOfTimeValues
- ] devdraft LESSONS LEARNED
- ] looping through array of object, USE array.forEach VS loop
- ] http://stackoverflow.com/questions/16626735/how-to-loop-through-an-array-containing-objects-and-access-their-properties
- ] --> READ the problem -> map solution B4 line1 of code writing
- ] guests visit attrations in specific order, / not always clear which route fastest(clockwise,counter)
- ] / GIVEN time between adjacent attraction / FIND fastest way between
- ]- saved screenshoot - PRB 0
- -- > READ the problem - the EXAMPLE is the explanation to solve the PROBLEM and THE ANSWER to 1/3 data set (it may have/has a mistake )
- ] -- will need methods clockwise/counter
[previously]
- [2015-10-26][19:00] NEW task IN doc/___
- ] came across website devdraft.com while browsing /r/vancouverjobs
- ] did a practice challenge to check it out
- ] while its puzzly its not overly puzzly or obtuse
- ] spent 3 - 4 hours, still on stage 1, (i think) i am just about there in regards to a solutions
- ] the 'real challenge' deadline was next day 10/27 6am - maybe should have tried that and could have submitted an entry
- ] real challeng deadline moved back 1 day due to tech issues, LETS give it a shot ...
- [2015-10-27][10:15]
- ] OK lets takc a crack at the 'real challenge'
- [00:00] NEW task IN
- ] puzzle = amusement park - calculate time between attractions in minutes,
- ] given # of minutes for average vistor to travel between points
- ] can travel in 2 directions, clockwise, counterclockwise
- [00:00] NEW task IN
- ] REF# = code-devChallenge-2015-10-27 ( keep local copy of code current, see reference )
- [13:00] NEW task IN
- x] ### - break ( p, purch)
- [16:15] NEW task IN
- ] # # - code challenge (contd)
- [01:00] NEW task IN -
- x] # # - whats the PROBLEM
- x] PROBLEM - MISUNDERSTOOD THE PRB(overthinking) - /wrote calcClockwise, calcCounterClockWise BUT already getting 'values' in input
- *] PROBLEM with 'invalid data', NEED REM - convert numbers toString() before output
- ] # # - PROBLEM - REL= again invalid data/data typ
- x] # # - PROBLEM - saving ( problem on server)
- x] EXCUSES = ] not good with puzzles/dont like, ] dont like console coding, ] nodejs
- [2015-10-28][00:00] NEW task
- x] # # - TEST functional, r=FAIL
- x] # # - submit help qry re: save problem
- x] # # - msg1 - recieved,
- x] # # - msg2 - resolved
- x] # # - msg3 - yes, resolved, thanks
- [00:00] NEW task IN function/readLines3
- x] # # - UPDATE readLines(3) - loop - TEST OK correct output in fiddle, TEST FAIL - error in input[idx2] BUT hardcode input[4]
- x] # # - TEST ixd2 value - output '62' , USE parseInt(numberOfQueries) value - output = 8, PROBLEM = numberOfqueries WAS string input
- x] # # - SAVE copy function to .txt
- [12:00] NEW task IN
- ] # # - jsfiddle - calcTimes3
- [00:00] NEW task IN calcTime3()
- ] # # - jsfiddle
- ] got it working BUT changed data structure from using 2 arrays(qDataAttractions,qDataValues) to one array (data) of 'record' objects
- ] TEST = FAIL
- ] PRB again with 'data types', was getting back data 04 vs 4, needed to use parseInt(average)
- ] TEST data[0] = PASS // 4
- ] TEST data[1] = PASS // 12
- ] TEST data[2] = FAIL // 12 <> 26
- ] PROBLEM - I didnt understand the calculation, its NOT a simple look of timeValue in table
- ] they are value pairs, 0,1 - user(0) walked(0,1) from attraction 0 to attraction 1 ( 4 minutes), user(1) walked(0,3,5) from 0, to 3 (4 min, idx), then from (3 to 5) for 12 minutes,
- ] 0, 5, 3, - - user walked from attraction 0-5 , then from 5 - 3
- [00:00] NEW task IN PROBLEM / REALIZATION
- ] # # - there are 3 more equally/likely more difficult challenges AHEAD in Part 1, 2, 3
- [00:00] NEW task IN SOLUTION:
- ] # # -
- [00:00] NEW task IN PROBLEM
- x] # # - getting incorrect data in console, values are being concat VS being totall
- [00:00] NEW task IN SOLUTION:
- x] # # - added parseInt(timeValues)
- [00:00] NEW task IN calcTime4()
- ] # # - jsfiddle - replace call tempCalc(data[0]) this works BUT
- [00:00] NEW task IN
- x] # # - add loop to write out multiple lines of output for each
- ] PROBLEM - not looping through array of objects, get results for first object element,
- ] SOLUTION - replace loop with a forEach method for the array, each item in the dataAll array will be process
- [00:00] NEW task IN
- x] # # - dataAll.forEach - add method to process array, goes thru all array objects, process each to calculate totalTime, writes output to console
- [2015-mm-dd][00:00] NEW task IN
- ] # # - scratchpad
- ] # # - calculateMinutes =
- ] # # - answers= 4, 12, 26
- ] 0,1 ; answer = 4, index 0,
- ] 0, 3, 5 - 0 to 3 = 4 minutes at index 0, 3 to 5 = 8 min at index 5
- ] 0, 4, 2, 5 = 0,4 = 4 min + 4,2, 5 min at index 2, + 2,5 8 min at index 5 = 17 minutes; total = 4+3+5+8(20)
- [2015-10-29][00] NEW task IN
- x] # # - re read instructions - ahaaaaaaaaaa moment ( i think)
- x] pseudo code
- [2015-10-29] NEW task IN
- ] # # -
- [2015-11-03] NEW task
- x] # # - ADD function numberOfTripPairs - trip pairs are the start,end points for each attraction, that a user wants to visit
- x] # # - TEST function
- *] DONT put expression in if statement, EX if ( x/2>0){ // NO go , DO var test = x/2 , then if (test > 0 ){
- ] REVISED formulas to get correct numberOfTripPairs
- x] REM function calcTime // orig version
- x] REM function calcTime2() // rev version
- x] REM function calcTime3() // rev version
[currently]
- [2015-11-04] NEW task IN
- x] UPDATE clockwiseTotal() - 2 loops, uses getNumber of pairs, first loop for numberOfPairs, 2nd loop tallies
- ] ADD function calcTimeClockwise(trips, pairs)
- ] TEST = runs, but results are wrong, first item correct, next should be 12,getting 15, next shoud be 26, getting 21
- [] NEW task IN
- x] # # - add counterClockwiseTotal() to
- ] TEST = PASS but values returned are incorrect
- ] TRY = adjust inner loop
- [] NEW task IN PRB-SOL
- ] # # - reverse array PRB function doesnt complete before values are accessed, node issue event driven
- ] output can be no outputs OR usuall first ouput is regular array, 2nd/3rd is reversed array
- ] have SO art on SOL : http://stackoverflow.com/questions/5010288/how-to-make-a-function-wait-until-a-callback-has-been-called-using-node-js
- ]
- []
[next]
- ]
# support request -
I was working on the Oct 2015 challenge last night it stopped allowing me to save anything, the error message is 500 bad request. It doesn't matter what I try to save. I also have a September challenge in progress in my account which seems to still save fine. Any ideas? Thanks
> SOLVED
0-4 - 11
4-2 - 6
2-5 - 9
] PSEUDO
x] input=numberOfQueries
- ] all points = values
- ] totalTrips = values.length %/ MOD ( 1 REM 0, 1 REM 1, 2 REM 0)
- getFirstTrip = first 2 points ( 0, 4)
- calcTimeBetweenPoints(clockwise)
- saveTimeTrip
function numberTripPairs(){
// calculate the # of trips/attractopms this user will take/visit
// ++ clockwise VS counterClockwise // ?? IF counter JUST access array at end VS at start
IF (totalTrips = values.length %/2 > 0){
// odd # a
return tripPairs = (values.length/2) + 1
}
else {
return tripPairs = (values.length/2)
}
}
function clockwiseTotal(start,destination){
// EX 0,1, // 3,5
// TEST 0,1 OK,
var totalTime = 0;
var tripTime = 0;
var stops = (destination - start) ;
var pairs = numberTrips(); // ex 1 // ex2
// BREAK DOWN FOR 1 // works for single trip // not enought iterations for, could go '<=' but that would break single item, // COULD ADD IF (cond 1) else {loop}
if ( stops === 1){
return times[start];
}
for( i = start; start <= destination ; start++){
tripTime = times[start];
totalTime = tripTotal + tripTime;
}
return totalTime;
--- *** ---
( values ) // (0,1), (0,3,5)
trips = numberOfTripPairs(); // 1, 2, 3
ttlTime = 0;
// [0,3,5] numTripParis = 2,
// first 2 items in arr
// arr items 0 + 1
for (i=0; i< trips; i++ ){
// start, destination, //0 1 // 0 3, 3 5
start = values[i] ;
destination = values[i+1];
for (j=start; j<destination; j++){
ttlTime += timeValues[j]; // 4,
}
}
function counterClockWiseTotal(start,destination){
// ex 0, 1 counterClockwise - 0 -5, 5 - 4, 4 - 3, 3 -2, 2-1
// timeValues = [4, 2, 5, 1, 3, 8];
attractions = numberOfAttractions; // 6
var totalTime = 0;
var tripTime = 0;
var stops = (destination - start) ; // 1, 0
var pairs = numberTrips(); // ex 1 // ex2
if ( stops === 1){
return times[start];
}
for( i = start; start <= destination ; start++){
tripTime = times[start];
totalTime = tripTotal + tripTime;
}
return totalTime;
}
-- /REVERSE case 1 = 0, 1
for ( i=timeValues.length-1; i < destination, i-- ){
totalTime += timeValues[i]; // pass1 ( 6/0/5 8 ), (6/0/5 3), ...
}
-- /REVERSE case 2 = 0, 3, 5 trips = 2, 0-3, 3-5
function calculateQuickestRoute(start, destination){
// ex 0, 1
var clockWise = clockWiseTotal(start, destination);
var counterClockWise = counterClockWiseTotal(start, destination);
if ( clockWise<= counterClockWise){
return clockWise;
}
else{
return counterClockwise;
}
}
*] 2015-10-26 5:29 [pm] last save devdraft
/*
function calcTime (){
var totalTime =0;
var total=0;
var values = indexOfAttractions.length - 1;
for(i=0; i < values; i++){
var idx = indexOfAttractions[i];
var x = parseInt(totalTime);
var y = averageTimeBetweenPoints[idx];
y = parseInt(y);
total = x + y;
totalTime += averageTimeBetweenPoints[idx]; // i = 2, 0 = 4, all += 042
}
return total.toString();
}
function calcTime2 (){
//var totalTime =0;
var total=0;
var values = qDataValues.length - 1;
for(i=0; i < values; i++){
var idx = qDataValues[i];
var x = parseInt(total);
var y = averageTimeBetweenPoints[idx];
y = parseInt(y);
total = x + y;
//totalTime += averageTimeBetweenPoints[idx]; // i = 2, 0 = 4, all += 042
}
return idx.toString();
}
*/
CUT COMMENTS BELOW FUNCTION readLines()
// output = calcTime2();
// output = qDataAttractions[0].toString();
// output = data[0].values.toString();
//var idxT=0;
/* LOOP thru all data outputs PRB - only gets value of 1, SEE BELOW multiple statements work BUT ...
for ( i=0; i < dataAll.length; i++ ){
// output = data.length.toString() ; // PASS '333'
// output = calcTime3(data[i]) + "\n"; // doesnt lOOP,
// output = i.toString()+"\n"; // PASS 0, 1, 2 - each on new line
output = calcTime3(dataAll[i]);
//OUTPUT
// process.stdout.write(output);
process.stdout.write( output + "\n"); // no output, w/out \n we get a single output
}
*/
/*
output = calcTime3(data[0]);
process.stdout.write(output+"\n");
output = calcTime3(data[1]);
process.stdout.write(output+"\n");
output = calcTime3(data[2]);
process.stdout.write(output);
*/