edit-task
Home
Up
Delete
Task Name:
Task Description:
challenge for 2015-09 (practice) - part 2 - parade
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 - september - part 2</h1> <h2>[reference]</h2> <ol> <li>x] code-devdraft-2015-10.txt - includes lastSave,</li> <li>i] # <a href="/view/task?id=5768" target="_blank">5768 - devDraft-challenge-2015-10</a> - </li> <li>i] # <a href="/view/task?id=5768" target="_blank">580# - devDraft-challenge-2015-09</a> - </li> <li>x] # 5809 - devDraft-challenge-2015-09-part-2 (this)</li> <li>x] http://jsfiddle.net/9f64m2tu/ - nested loop approach, calculate maximum value of array segment</li> <li>x] http://jsfiddle.net/a33goL3s/ - another approach - arrary slices, sum function, </li> <ol> <li>*] inline loops execute</li> <li>*] </li> </ol> <li>] http://jsfiddle.net/a33goL3s/5/ </li> <li><strong>] MISC / NOTE / LEARN</strong></li> <li>//FAIL - var Blocks = parseInt(data[0].split(" ")); // CANT do the parse on the same line</li> </ol> <div><hr /></div> <h2>[notes]</h2> <ol> <li><strong>] PROBLEM - Parade - place your security forces to minimize threat risks</strong></li> <ol> <li>] list of ints , rep <strong>threat</strong> of vandalism occuring on the city blocks along the parade route, 0=no vandalism, 1 = greater vandalism, </li> <li>] parade moves in a straight line, passes by every block once</li> <li>] given several security <strong>forces</strong>, each of which can control a number of adjacent blocks, nullifying the <strong>threats</strong> on the <strong>blocks</strong> they patrol</li> <li>] forces come in different types(<strong>forceType</strong>), the types affect their <strong>patrolLength</strong></li> <li>] typeBike > patrolLengh then typeFoot</li> <li>] forces repped by a list of pairs of integers, first int is # of adjacent blocks a type of force can control, 2nd int is how many forces of that type</li> <li>] num forces is limited, place them strategically to minimize the sum of threat levels of all blocks that are not patrolled, </li> <li>] because the minimum threat level may be achieved by multiple arrangements of security, output only the min total threat level that can be achieved and not the positions of the forces</li> </ol> <li><strong>] INPUTS -</strong> </li> <ol> <li>] line 1 - 2 space sep integers, B (# of city blocks parade passes through, P # of different patrolLengths available among all avail forces</li> <li>] line 2 - B space sep ints between 0 - 10 ^7, with the i-th int repping the threat level of vandalism occuring on the i-th block</li> <li>] line 3 - 2P space seperated integers, meant to be read 2 at a time, total of P pairs, each pair first int reps # of adj blocks, that a specific type of force can patrol, 2nd int reps # of forces of that type, you have availabel</li> <li>] F = total # of forces across all patrol types, </li> <li>] TEST CASE SETS</li> <li>] A - code correctness - 0<=B<=100; P = 1, F=1</li> <li>] B - advanced cs - 0<=B<=10000; P=1; 0<=F<=100 </li> <li>] C - advanced cs - 0<= B <=1000; 0<=P<=3; 0<=F<=100 ; </li> <li>*] score will increase in proportion to size of test cases</li> </ol> <li><strong>] PROCESS - </strong></li> <ol> <li>] get inputs </li> <ol> <li>x] line1 = ] # blocks, ] patrol lengths</li> <li>x] line 2 = threatLevels - array of int, for each block, ] threatLevel</li> <li>x] line 3 = pairs of ints, ] adjBlocks ] #forces</li> </ol> <li>] calculateSegmentRisk()</li> <li>] calculateAllSegments()</li> <li>] calcualteRiskBalance()</li> </ol> <li><strong>] OUTPUT - </strong></li> <ol> <li>] single int rep min possible threat level to achieve</li> </ol></ol> <h2>[process]</h2> <ol> <li><strong>x] VAR inputs</strong></li> <ol> <li>x] get input from stdin, set global variables, test input to see if its read, </li> </ol> <li><span style="background-color: #c0c0c0;"><strong>] function readPairs()</strong></span></li> <ol> <li><span style="background-color: #c0c0c0;">] get # of pairs, </span></li> <li><span style="background-color: #c0c0c0;">] get values of pairs</span></li> <li><span style="background-color: #c0c0c0;">] load into pairs array</span></li> </ol> <li><span style="background-color: #c0c0c0;"><strong>] function setthreatLevelOnBlock()</strong></span></li> <ol> <li><span style="background-color: #c0c0c0;">] </span></li> </ol> <li><span style="text-decoration: line-through;"><strong>] function maxThreatLevel()</strong></span></li> <ol> <li><span style="text-decoration: line-through;">] using nested loop to read in values of threat levels from each segment</span></li> </ol> <li><strong>] function calculateSegmentRisk()</strong></li> <ol> <li>] take a slice of the array, slice size determined by ajdBlocks var</li> <li>] sum elements to calculate risk</li> </ol> <li><strong>] function calculateAllSegments()</strong></li> <ol> <li>] loop thru, call callSegmentRisk for </li> </ol> <li><strong>] function getIndexRiskiestBlock()</strong></li> <ol> <li>] </li> </ol> <li><strong>] function calculateRiskBalance(arr)</strong></li> <ol> <li>] var maxRisk = </li> <li>] var totalRisk = </li> <li>*] use arr line2, </li> </ol> <li><strong>] function main() </strong></li> <ol> <li>] </li> </ol></ol><hr /> <h1 style="text-align: center;">status</h1> <h2>[previously]</h2> <ol> <li><strong><span style="background-color: #888888;">[2015-11-06]</span> NEW task IN</strong></li> <ol> <li>] # # - ] start level2 after level1 locked out, ?? too many fails ?? </li> </ol> <li><strong>[00:00] NEW task IN </strong></li> <ol> <li>x] # # - this page to document PRB, PROGRESS</li> </ol> <li><strong>[00:00] NEW task</strong></li> <ol> <li>] # # - trying to use nested loop to calculate the , </li> <li>x] SEE REF # 5 (fiddle) </li> <li>] PRB - lenght/iterations on inner loop</li> </ol> <li><strong><span style="background-color: #888888;">[2015-11-07]</span> NEW task CREATE functions - multiple(#)</strong></li> <ol> <li>] # # - NEW approach, multiple functions, ] calcSegmentRisk,//calcs single segment riskvalue ] calculateAllSegments // ] getIndexRiskiestBlocks // returns 2</li> <li>x] SEE REF # 5 (fiddle) </li> </ol> <li><strong>[] NEW task CREATE function() riskBalance() </strong></li> <ol> <li>] sum of the risk = totalRisk - covered</li> </ol> <li><strong>[14:00] NEW task</strong></li> <ol> <li>x] # # - PORT from: fiddle to solution</li> <li>x] ADD parseInt to functions(), </li> <li>x] changed var adjBlocks to Blocks</li> <li>x] PRB calcTotalRisk = ttl(22 OK) - covered(should be 14, getting 0 )</li> <li>x] ADD var adjBlocks, test output val = // changed Blocks back to adjBlocks</li> <li>x] calculate All segment - PRB syntax, missing bracket, prbly knocked off when editing 'adjBlocks' var, NOW returning data</li> <li>x] PRB getIndexRiskiestBlock = FAIL ( REASON 1 b/c = see above), REASON 2 = missing return statement</li> <li>x] SUCCESS - part-2 - partA, partA = single force, </li> </ol></ol> <h2>[currently]</h2> <ol> <li><strong>[15:00] NEW task IN </strong></li> <ol> <li>] # # - part-2-part-B - multiple forces(2, same adjBlocks), </li> </ol></ol> <h2>[next]</h2> <ol> <li><strong>[15:00] NEW task IN </strong></li> <ol> <li>] # # - part-2-part-C - multiple forces(>2, different adjBlocks), </li> </ol></ol> <div>[OUTLINE]</div> <div> <div>x] get inputs (from stdin)</div> <div>] </div> <div> </div> <div><hr /></div> <div>]</div> </div>