task

devdraft challenge - october

[reference]

  1. i] code-devdraft-2015-09.txt
  2. i] code-devdraft-2015-10.txt - includes lastSave,
  3. x] http://jsfiddle.net/nh8mLeda/ - readLines3() - loop
  4. x] http://jsfiddle.net/rfk6z897/ - calcTime2()
  5. ]

[notes]

  1. ] INPUTS
    1. ] numberAttractions = int A //
    2. ] averageTimeBetweenPoints = [] ints //
    3. ] numberOfQueries = 3
    4. ] qry-n-line1 (numberAttractions) // # of attractions each user will visit
    5. ] qry-n-line2-POINTS (index of times) // index value of getting TimeValues
    6. ] ....
  2. ] INPUT - example - 1 DATA
    1. ] timeValues = [4, 2, 5, 1, 3, 8];
    2. ] number attractractions = 2,
    3. ] 2
    4. ] 0 1 ( attraction, qry-n)
    5. ] 3
    6. ] 0,3,5
    7. ] 4
    8. ] 0, 4, 2, 5
  3. ] PROCESS
    1. ] NEW task IN i] calculateClockWise(averageTimeBetweenPoints, qry-n-line2-POINTS )
      1. ] var totalTime =
      2. ] foreach in points totalTime += averageTime[points[i]];
      3. ] return totalTime
    2. ] NEW task IN i] calculateCounterClockWise()
      1. i] see above
    3. ] NEW task IN  calculateQuickest()
      1. ] compare clockwise time 
      2. ] return quickest time
    4. ] NEW task IN  calcTime()
      1. ]
    5. ] NEW task IN  calcTime2()
      1. ]
    6. ] NEW task IN readLines3()
      1. x] get the 'data' for each query - pushed into qData array
      2. x] data = numberAttractions, indexOfTimeValues
  4. ] devdraft LESSONS LEARNED
    1. ] looping through array of object, USE array.forEach VS loop
    2. ] http://stackoverflow.com/questions/16626735/how-to-loop-through-an-array-containing-objects-and-access-their-properties
    3. ] --> READ the problem -> map solution B4 line1 of code writing
    4. ] guests visit attrations in specific order, / not always clear which route fastest(clockwise,counter) 
    5. ] / GIVEN time between adjacent attraction / FIND fastest way between 
    6. ]- saved screenshoot - PRB 0 
    7. -- > 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 )
    8. ] -- will need methods clockwise/counter

[previously]

  1. [2015-10-26][19:00] NEW task IN doc/___
    1. ]  came across website devdraft.com while browsing /r/vancouverjobs
    2. ] did a practice challenge to check it out
    3. ] while its puzzly its not overly puzzly or obtuse
    4. ] spent 3 - 4 hours, still on stage 1, (i think) i am just about there in regards to a solutions
    5. ] the 'real challenge' deadline was next day 10/27 6am - maybe should have tried that and could have submitted an entry
    6. ] real challeng deadline moved back 1 day due to tech issues, LETS give it a shot ...
  2. [2015-10-27][10:15]
    1. ] OK lets takc a crack at the 'real challenge'
  3. [00:00] NEW task IN
    1. ] puzzle = amusement park - calculate time between attractions in minutes,
    2. ] given # of minutes for average vistor to travel between points
    3. ] can travel in 2 directions, clockwise, counterclockwise
  4. [00:00] NEW task IN
    1. ] REF# = code-devChallenge-2015-10-27 ( keep local copy of code current, see reference )
  5. [13:00] NEW task IN
    1. x] ### - break  ( p, purch)
  6. [16:15] NEW task IN
    1. ] # # - code challenge (contd)
  7. [01:00] NEW task IN -
    1. x] # # - whats the PROBLEM
    2. x] PROBLEM - MISUNDERSTOOD THE PRB(overthinking) - /wrote calcClockwise, calcCounterClockWise BUT already getting 'values' in input
    3. *] PROBLEM  with 'invalid data', NEED REM - convert numbers toString() before output
    4. ] # # - PROBLEM - REL= again  invalid data/data typ
    5. x] # # - PROBLEM - saving ( problem on server)
    6. x] EXCUSES = ] not good with puzzles/dont like, ] dont like console coding, ] nodejs  
  8. [2015-10-28][00:00] NEW task
    1. x] # # - TEST functional, r=FAIL
    2. x] # # - submit help qry re: save problem
    3. x] # # - msg1 - recieved,
    4. x] # # - msg2 - resolved
    5. x] # # - msg3 - yes, resolved, thanks
  9. [00:00] NEW task IN function/readLines3
    1. x] # # - UPDATE readLines(3) - loop - TEST OK correct output in fiddle, TEST FAIL - error in input[idx2] BUT hardcode input[4]
    2. x] # # - TEST ixd2 value - output '62' , USE parseInt(numberOfQueries) value - output = 8, PROBLEM = numberOfqueries WAS string input
    3. x]  # # - SAVE copy function to .txt
  10. [12:00] NEW task IN
    1. ] # # - jsfiddle - calcTimes3  
  11. [00:00] NEW task IN  calcTime3()
    1. ] # # - jsfiddle 
    2. ] got it working BUT changed data structure from using 2 arrays(qDataAttractions,qDataValues) to one array (data) of 'record' objects
    3. ] TEST = FAIL
    4. ] PRB again with 'data types', was getting back data 04 vs 4, needed to use parseInt(average)
    5. ] TEST data[0] = PASS // 4
    6. ] TEST data[1] = PASS  // 12
    7. ] TEST data[2] = FAIL // 12 <> 26
    8. ] PROBLEM - I didnt understand the calculation, its NOT a simple look of timeValue in table
    9. ] 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,    
    10. ] 0, 5, 3, - - user walked from attraction 0-5 , then from 5 - 3
  12. [00:00] NEW task IN PROBLEM / REALIZATION
    1. ] # # - there are 3 more equally/likely more difficult challenges AHEAD in Part 1, 2, 3
  13. [00:00] NEW task IN SOLUTION:
    1. ] # # -
  14. [00:00] NEW task IN PROBLEM
    1. x] # # - getting incorrect data in console, values are being concat VS being totall
  15. [00:00] NEW task IN SOLUTION: 
    1. x] # # - added parseInt(timeValues)
  16. [00:00] NEW task IN  calcTime4()
    1. ] # # - jsfiddle - replace call tempCalc(data[0]) this works BUT
  17. [00:00] NEW task IN
    1. x] # # - add loop to write out multiple lines of output for each
    2. ] PROBLEM - not looping through array of objects, get results for first object element,
    3. ] SOLUTION - replace loop with a forEach method for the array, each item in the dataAll array will be process
  18. [00:00] NEW task IN
    1. x] # # - dataAll.forEach - add method to process array, goes thru all array objects, process each to calculate totalTime, writes output to console
  19. [2015-mm-dd][00:00] NEW task IN
    1. ] # # - scratchpad
    2. ] # # - calculateMinutes =
    3. ] # # - answers= 4, 12, 26
    4. ] 0,1 ; answer = 4, index 0,
    5. ] 0, 3, 5  -  0 to 3 = 4 minutes at index 0, 3 to 5 = 8 min at index 5
    6. ] 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)
  20. [2015-10-29][00] NEW task IN
    1. x] # # - re read instructions - ahaaaaaaaaaa moment ( i think)
    2. x] pseudo code
  21. [2015-10-29] NEW task IN
    1. ] # # -
  22. [2015-11-03] NEW task
    1. x] # # - ADD function numberOfTripPairs - trip pairs are the start,end points for each attraction, that a user wants to visit
    2. x] # # - TEST function 
      1. *] DONT put expression in if statement, EX if ( x/2>0){ // NO go , DO var test = x/2 , then if (test > 0 ){ 
      2. ] REVISED formulas to get correct numberOfTripPairs
    3. x] REM function calcTime // orig version
    4. x] REM function calcTime2() // rev version  
    5. x] REM function calcTime3() // rev version  

[currently]

  1. [2015-11-04] NEW task IN 
    1. x] UPDATE clockwiseTotal() - 2 loops, uses getNumber of pairs, first loop for numberOfPairs, 2nd loop tallies 
    2. ] ADD function calcTimeClockwise(trips, pairs) 
    3. ] TEST = runs, but results are wrong, first item correct, next should be 12,getting 15, next shoud be 26, getting 21 
  2. [] NEW task IN 
    1. x] # # - add counterClockwiseTotal() to
    2. ] TEST = PASS but values returned are incorrect 
    3. ] TRY = adjust inner loop 
  3. [] NEW task IN PRB-SOL
    1. ] # # - reverse array PRB function doesnt complete before values are accessed, node issue event driven
    2. ] output can be no outputs OR usuall first ouput is regular array, 2nd/3rd is reversed array
    3. ] 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
    4. ]
  4. []

[next]

  1. ]

 

 


# 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);

    */

    

    

Details Photos Edit more

Details

ID: 5768

NAME: devdraft-challenge-2015-10

DESCRIPTION: ] Challenge 2015-10 - AMUSEMENT PARK - get shortest time between attractions

START DATE TIME: 2015-10-27 09:51:58

EST DURATION: 01:00:00

END DATE TIME: 2015-10-27 10:51:58

STATUS: To-Do

PRIORITY: -5

OWNER ID: 1

Content Photos Edit more

photos

photos for this task

actions

Agenda Email task SMS task Priorities