edit-task
Home
Up
Delete
Task Name:
Task Description:
challenge for 2015-09 (practice) - character manipulation,
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</h1> <h2>[reference]</h2> <ol> <li>x] code-devdraft-2015-10.txt - includes lastSave,</li> <li>] <a href="http://jsfiddle.net/nh8mLeda/" target="_blank">http://jsfiddle.net/nh8mLeda/</a> - readLines3() - loop</li> <li>i] # <a href="/view/task?id=5768" target="_blank">5768 - devDraft-challenge-2015-10</a> - </li> </ol> <div><hr /></div> <h2>[notes]</h2> <ol> <li><strong>] PROBLEM - remove CRYSTAL COMPOUNDS from workbench of CRYSTALS</strong></li> <ol> <li>]<strong> </strong>single player word game, take elemental crystals (repped by letters) and forms compounds, </li> <li>] each crystal is a specific type of element, F I Z B A R </li> <li>] crystals are presented in a line</li> <li>] COMPOUNDS form when adjacent crystals are in a specific order, FIZ, BAR, BAZ, ZIF, RAB, ZAB, ( last 3 are first 3 reversed)</li> <li>] IF adjacent CRYSTALS form a SEQUNCE ex BAZIF consisting of overlapping COMPOUNDS ( BAZ ZIF ), then sequences is LARGER COMPOUND </li> <li>] when compound forms, crystals are removed from the workbench, any crystals to their right, slide left, so there are no gaps. </li> <li>] after sliding left, check again, for compounds</li> <li>*] ASSUME no compounds exist on workbench at start of the game </li> <li>] PLAYER - can only re-arragange crystals by swapping adjacent crystals , CAN only swap if crystals if a COMPOUND formed is the result (legal move)</li> <li>] if PLAYER MOVE is !legal, no crystals are swapped</li> <li>] gameplay alternates between ] removeCompound, ] slideLeft, ] player making swap </li> </ol> <li><strong>] INPUTS -</strong> </li> <ol> <li>] line 1 int C, ( 0 < C < 100) number of crystals on the workbench</li> <li>] line 2 str C capital letters, ith letter = i-th crystal </li> <li>] line 3 int S ( 0 <=S < 50) number of swaps the player makes</li> <li>] line 4 S space seperated integers , index of the left letter, to be swapped with its right , leftmost crystal is 0 </li> </ol> <li><strong>] PROCESS - </strong></li> <ol> <li>] get inputs </li> <li>] removeCompound </li> <li>] slideLeft (shrinkLeft) </li> <li>] playerSwap</li> </ol> <li><strong>] OUTPUT - </strong></li> <ol> <li>] from left to right, letters of the crystals remaining on the workbench, AFTER the swaps are done ANY any compounds are removed, </li> <li>] written to stdout </li> </ol></ol> <h2>[process]</h2> <ol> <li><strong>x] VAR inputs</strong></li> <ol> <li>] get input from stdin, set global variables</li> </ol> <li><strong>] function swap()</strong></li> <ol> <li>] switches the position of 2 different chars in the string of chars</li> </ol> <li><strong>] function testMatch()</strong></li> <ol> <li>] check if a given 3 char string, matches </li> <li>] walk through all options for the workbench</li> </ol> <li><strong>] function shrinkLeft(str)</strong></li> <ol> <li>] remove a given 3 char sequence from the string</li> </ol> <li><strong>] function writeOutput()</strong></li> <ol> <li>] write remaining string to std out</li> </ol> <li>*******</li> <li>] testSuperCompounds()</li> <li>] removeSuperCompound()</li> <li>] isLegalMove()</li> </ol><hr /> <h1 style="text-align: center;">status</h1> <h2>[previously]</h2> <ol> <li><strong><span style="background-color: #888888;">[2015-10-27]</span> NEW task IN</strong></li> <ol> <li>x] # # - ] try this practice challenge as practice, check out the level of difficutly that the actual challenge may entail</li> </ol> <li><span style="background-color: #888888;"><strong>[2015-10-28]</strong></span></li> <ol> <li>] # # - decided why NOT try the real thing (2015-10-challenge) as it it live and i can win the prize ...</li> <li>] # # - or NOT ...</li> <li>] # # - leaving this practice ex (for now)</li> </ol> <li><strong><span style="background-color: #888888;">[2015-11-04]</span> NEW task IN </strong></li> <ol> <li>] # # - x] revisit</li> <li>] # # - review, create problem statement as above</li> </ol> <li><strong>> [00:00] NEW task IN careers/pln/</strong></li> <ol> <li>x] # <a href="/view/task?id=5803" target="_blank">5803 - devdraft-2015-09</a> - x] create PG, ] </li> <li>x] DELETEd .txt file with CUT scaps, MISC info, MOVE content (here)</li> </ol> <li><strong>[00:00] NEW task IN </strong></li> <ol> <li>x] # # = TEST = PASS - returns the first output correctly ] STILL incomplete but hey</li> </ol> <li>[] </li> </ol> <h2>[currently]</h2> <ol> <li><strong>] PRB writeOutput </strong></li> <ol> <li>] output = ] output swap(strWorkbench), ] output = shrinkLeft(output, index) ] output= swap (output), ] output = shrinkLeft(output,index)</li> <li>] first pass through returns correctl shortened string, removing first matched compound</li> <li>] 2nd call to swap() FAIL, no results</li> <li>] REVISIONS = </li> <li>] TEST = PASS- </li> </ol> <li><strong>[2015-11-05] NEW task IN </strong></li> <ol> <li>] UPD writeOutput - add loop to call, WORKS but output is wrong, </li> <li>] PRB - 2nd swap is not happening , 2nd 'compound' not being removed</li> </ol> <li>[00:00] </li> </ol> <h2>[next]</h2> <ol> <li>]</li> </ol> <div>[OUTLINE]</div> <div> <div>x] get inputs (from stdin)</div> <div>] test input for match()</div> <div>] remove matched </div> <div>] swap(0)</div> <div>] test input for match()</div> <div>] remove matched</div> <div>] swap(2)</div> <div>] test input for match()</div> <div>] remove matched </div> <div>] swap </div> <div> </div> <div><hr /></div> <div>] CUT CODE</div> <div> <div>] </div> <div>function process(){</div> <div> for(i=0; i< input.length; i++){</div> <div> var x = input.substring(i,3)</div> <div> if ( x === 'ABC'){</div> <div> console.log('match ABC');</div> <div> }</div> <div> if ( x ==='CDX'){</div> <div> console.log('match CDX');</div> <div> }</div> <div> }</div> <div> // alert('hello');</div> <div>] CODE BLANK</div> <div>process.stdin.resume();</div> <div>process.stdin.setEncoding('utf8');</div> <div>fullInput = ''</div> <div>process.stdin.on('data', function(chunk) {</div> <div> if (chunk !== null)</div> <div> {</div> <div> fullInput += chunk;</div> <div> }</div> <div>});</div> <div>process.stdin.on('end', function() {</div> <div> solveProblem(fullInput);</div> <div>});</div> <div>function solveProblem(input)</div> <div>{</div> <div> // Your code goes here. Replace "output" with what you need to print.</div> <div> // You can use multiple write statements.</div> <div> var output, match;</div> <div> </div> <div> for(i=0; i<input.length; i++){</div> <div> output = input.substring(i,3);</div> <div> if (output === 'FIZ' || 'BAZ'){</div> <div> match = true;</div> <div> output = 'BBFF';</div> <div> }</div> <div> // i++;</div> <div> }</div> <div> </div> <div> //output = '';</div> <div> </div> <div> </div> <div> process.stdout.write(output);</div> <div>}</div> <div>] CUT</div> <div> if (output === 'FIZ' || 'BAR'|| 'BAZ'|| 'ZIF' || 'RAB' || 'ZAB'){</div> <div> match = true;</div> <div> output = 'BBFF';</div> <div> }</div> <div> </div> <div>] </div> <div>http://stackoverflow.com/questions/21895233/how-in-node-to-split-string-by-newline-n</div> <div>] // EX 4</div> <div>var input = 'BFIZBRAFBF';</div> <div>var output = 'ABC';</div> <div>var f,b,r,x,y,z ;</div> <div>var cuts = [];</div> <div>function process(){</div> <div> for(i=0; i<input.length; i++){</div> <div> output = input.substring(i,3);</div> <div> // test for each set chars to find, if match save index of </div> <div> if (output === 'FIZ' ) {</div> <div> cuts.push(i);</div> <div> }</div> <div> if (output === 'BAR'){</div> <div> cuts.push(i);</div> <div> }</div> <div> if (output === 'BAZ'){</div> <div> cuts.push(i);</div> <div> }</div> <div> if (output === 'BAR'){</div> <div> cuts.push(i);</div> <div> }</div> <div> if (output === 'ZIF'){</div> <div> cuts.push(i);</div> <div> }</div> <div> if (output === 'RAB'){</div> <div> cuts.push(i);</div> <div> }</div> <div> if (output === 'BAZ'){</div> <div> cuts.push(i);</div> <div> }</div> <div> }</div> <div> // walk through each of the matched char sets, remove matched chars from original string </div> <div> if ( cuts.length > 0){</div> <div> for (i=0; i< cuts.length; i++){</div> <div> // index value of a matched item</div> <div> var startCut = cuts[i]; </div> <div> var tempStr1, tempStr2;</div> <div> // characters to remove // 10 </div> <div> // last part of string</div> <div> tempStr1 = input.substring( input.length - ( startCut + 3) ); </div> <div> tempStr2 = input.substring(0, startCut);</div> <div> output = tempStr1 + tempStr2;</div> <div> </div> <div> // input.substring( (input.length - startcut), 3) input.substring(startCut,3);</div> <div> // </div> <div> console.log(output);</div> <div> }</div> <div> }</div> <div> console.log(output);</div> <div>}</div> <div>process();</div> </div> </div> <div>--- -v-001 </div> <div> <div>/*</div> <div> // WORKING - removes matched characters</div> <div> function shrinkLeft(strOriginal,startCut){</div> <div> var strBefore, strAfter, strShrunk;</div> <div> strBefore = strOriginal.substring( strOriginal.length - ( startCut + 3) ); </div> <div> strAfter = strOriginal.substring(0, startCut);</div> <div> strShrunk = strBefore + strAfter; </div> <div> </div> <div> return strShrunk;</div> <div> }</div> <div> */</div> </div>