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