task

devdraft challenge - september

[reference]

  1. x] code-devdraft-2015-10.txt - includes lastSave,
  2. http://jsfiddle.net/nh8mLeda/ - readLines3() - loop
  3. i] # 5768 - devDraft-challenge-2015-10 - 

[notes]

  1. ] PROBLEM - remove CRYSTAL COMPOUNDS from workbench of CRYSTALS
    1. ] single player word game, take elemental crystals (repped by letters) and forms compounds, 
    2. ] each crystal is a specific type of element, F I Z B A R 
    3. ] crystals are presented in a line
    4. ] COMPOUNDS form when adjacent crystals are in a specific order, FIZ, BAR, BAZ, ZIF, RAB, ZAB, ( last 3 are first 3 reversed)
    5. ] IF adjacent CRYSTALS form a SEQUNCE ex BAZIF consisting of overlapping COMPOUNDS ( BAZ ZIF ), then sequences is LARGER COMPOUND 
    6. ] when compound forms, crystals are removed from the workbench, any crystals to their right, slide left, so there are no gaps. 
    7. ] after sliding left, check again, for compounds
    8. *] ASSUME no compounds exist on workbench at start of the game 
    9. ] PLAYER - can only re-arragange crystals by swapping adjacent crystals , CAN only swap if crystals if a COMPOUND formed is the result (legal move)
    10. ] if PLAYER MOVE is !legal, no crystals are swapped
    11. ] gameplay alternates between ] removeCompound, ] slideLeft, ] player making swap 
  2. ] INPUTS - 
    1. ] line 1 int C, ( 0 < C < 100) number of crystals on the workbench
    2. ] line 2 str C capital letters, ith letter = i-th crystal 
    3. ] line 3 int S ( 0 <=S < 50) number of swaps the player makes
    4. ] line 4 S space seperated integers , index of the left letter, to be swapped with its right , leftmost crystal is 0 
  3. ] PROCESS - 
    1. ] get inputs 
    2. ] removeCompound 
    3. ] slideLeft (shrinkLeft) 
    4. ] playerSwap
  4. ] OUTPUT - 
    1. ] from left to right, letters of the crystals remaining on the workbench, AFTER the swaps are done ANY any compounds are removed, 
    2. ] written to stdout 

[process]

  1. x] VAR inputs
    1. ] get input from stdin, set global variables
  2. ] function swap()
    1. ] switches the position of 2 different chars in the string of chars
  3. ] function testMatch()
    1. ] check if a given 3 char string, matches 
    2. ] walk through all options for the workbench
  4. ] function shrinkLeft(str)
    1. ] remove a given 3 char sequence from the string
  5. ] function writeOutput()
    1. ] write remaining string to std out
  6. *******
  7. ] testSuperCompounds()
  8. ] removeSuperCompound()
  9. ] isLegalMove()

status

[previously]

  1. [2015-10-27] NEW task IN
    1. x] # # - ] try this practice challenge as practice, check out the level of difficutly that the actual challenge may entail
  2. [2015-10-28]
    1. ] # # - decided why NOT try the real thing (2015-10-challenge) as it it live and i can win the prize ...
    2. ] # # - or NOT ...
    3. ] # # - leaving this practice ex (for now)
  3. [2015-11-04] NEW task IN 
    1. ] # # - x] revisit
    2. ] # # - review, create problem statement as above
  4. > [00:00] NEW task IN careers/pln/
    1. x] # 5803 - devdraft-2015-09 - x] create PG, ] 
    2. x] DELETEd .txt file with  CUT scaps, MISC info, MOVE content (here)
  5. [00:00] NEW task IN 
    1. x] # # = TEST = PASS - returns the first output correctly ] STILL incomplete but hey
  6. [] 

[currently]

  1. ] PRB writeOutput 
    1. ] output = ] output swap(strWorkbench), ] output = shrinkLeft(output, index) ] output= swap (output), ] output = shrinkLeft(output,index)
    2. ] first pass through returns correctl shortened string, removing first matched compound
    3. ] 2nd call to swap() FAIL, no results
    4. ] REVISIONS = 
    5. ] TEST = PASS- 
  2. [2015-11-05] NEW task IN 
    1. ] UPD writeOutput - add loop to call, WORKS but output is wrong, 
    2. ] PRB - 2nd swap is not happening , 2nd 'compound' not being removed
  3. [00:00] 

[next]

  1. ]
[OUTLINE]
x] get inputs (from stdin)
] test input for match()
] remove matched 
] swap(0)
] test input for match()
] remove matched
] swap(2)
] test input for match()
] remove matched 
] swap 
 

] CUT CODE
function process(){
 for(i=0; i< input.length; i++){
    var x = input.substring(i,3)
    if ( x === 'ABC'){
  console.log('match ABC');
    }
    if ( x ==='CDX'){
  console.log('match CDX');
    }
 }
 // alert('hello');
] CODE BLANK
process.stdin.resume();
process.stdin.setEncoding('utf8');
fullInput = ''
process.stdin.on('data', function(chunk) {
  if (chunk !== null)
  {
    fullInput += chunk;
  }
});
process.stdin.on('end', function() {
  solveProblem(fullInput);
});
function solveProblem(input)
{
    // Your code goes here. Replace "output" with what you need to print.
    // You can use multiple write statements.
    var output, match;
    
    for(i=0; i<input.length; i++){
        output = input.substring(i,3);
        if (output === 'FIZ' || 'BAZ'){
            match = true;
            output = 'BBFF';
        }
        // i++;
    }
    
    //output = '';
    
    
    process.stdout.write(output);
}
] CUT
        if (output === 'FIZ' || 'BAR'|| 'BAZ'|| 'ZIF' || 'RAB' || 'ZAB'){
            match = true;
            output = 'BBFF';
        }
        
http://stackoverflow.com/questions/21895233/how-in-node-to-split-string-by-newline-n
] // EX 4
var input = 'BFIZBRAFBF';
var output = 'ABC';
var f,b,r,x,y,z ;
var cuts = [];
function process(){
    for(i=0; i<input.length; i++){
        output = input.substring(i,3);
        // test for each set chars to find, if match save index of 
        if (output === 'FIZ' ) {
            cuts.push(i);
        }
        if (output === 'BAR'){
            cuts.push(i);
        }
        if (output === 'BAZ'){
            cuts.push(i);
        }
        if (output === 'BAR'){
            cuts.push(i);
        }
        if (output === 'ZIF'){
            cuts.push(i);
        }
       if (output === 'RAB'){
            cuts.push(i);
        }
        if (output === 'BAZ'){
            cuts.push(i);
        }
    }
    // walk through each of the matched char sets, remove matched chars from original string 
    if ( cuts.length > 0){
        for (i=0; i< cuts.length; i++){
            // index value of a matched item
            var startCut = cuts[i];  
            var tempStr1, tempStr2;
            // characters to remove // 10  
            // last part of string
            tempStr1 = input.substring( input.length - ( startCut + 3) ); 
            tempStr2 = input.substring(0, startCut);
            output = tempStr1 + tempStr2;
            
            // input.substring( (input.length - startcut), 3) input.substring(startCut,3);
            // 
            console.log(output);
        }
    }
    console.log(output);
}
process();
--- -v-001 
/*
    // WORKING - removes matched characters
     function shrinkLeft(strOriginal,startCut){
         var strBefore, strAfter, strShrunk;
         strBefore = strOriginal.substring( strOriginal.length - ( startCut + 3) ); 
         strAfter = strOriginal.substring(0, startCut);
         strShrunk = strBefore + strAfter;     
         
        return strShrunk;
    }
    */
Details Photos Edit more

Details

ID: 5803

NAME: devdraft-challenge-2015-09

DESCRIPTION: challenge for 2015-09 (practice) - character manipulation,

START DATE TIME: 2015-11-04 14:04:18

EST DURATION: 01:00:00

END DATE TIME: 2015-11-04 15:04:18

STATUS:

PRIORITY: -5

OWNER ID: 75

Content Photos Edit more

photos

photos for this task

actions

Agenda Email task SMS task Priorities