Logo

Who is talking?

Archive

Code post testing in different plugins

over 8 years ago | Lakshman Prasad: becomingGuru.com

1: public class SpiralWalking{ 2: public int totalPoints(String[] levelMap){ 3: int[] pos={0,0}; 4: int dim=0; 5: int ymax=levelMap.length; 6: int xmax=levelMap[0].length(); 7: int cells=(ymax)*(xmax); 8: int[] size={xmax,ymax}; 9: boolean isForward=true; 10: boolean[][] isDone=new boolean[xmax][ymax]; 11: int score=0; 12: isDone[0][0]=true; 13: int modCounter=0; 14: for(int count=1;count<cells;count++){ 15: if(pos[dim]==size[dim]-1 || (pos[dim]==0 && count!=1) 16: || ((isForward && dim==0 && isDone[pos[0]+1][pos[1]]) 17: || (isForward && dim==1 && isDone[pos[0]][pos[1]+1])) 18: || ((!isForward && dim==0 && isDone[pos[0]-1][pos[1]]) 19: || (!isForward && dim==1 && isDone[pos[0]][pos[1]-1]))) { 20: if(++modCounter%2==0) isForward=!isForward; 21: dim=++dim%2; 22: if(isForward)pos[dim]++; else pos[dim]--; 23: isDone[pos[0]][pos[1]]=true; 24: }else { 25: score+=Integer.parseInt(String.valueOf(levelMap[pos[1]].charAt(pos[0]))); 26: if(isForward)pos[dim]++; else pos[dim]--; 27: isDone[pos[0]][pos[1]]=true; 28: } 29: } 30: score+=Integer.parseInt(String.valueOf(levelMap[pos[1]].charAt(pos[0]))); 31: return score; 32: } 33:  34: public static void main(String z[]){ 35: String[] inp={"86850","76439", 36: "15863", 37: "24568", 38: "45679", 39: "71452", 40: "05483" 41: }; 42: System.out.println(new SpiralWalking().totalPoints(inp)); 43: } 44: }   public class SpiralWalking{ public int totalPoints(String[] levelMap){ int[] pos={0,0}; int dim=0; int ymax=levelMap.length; int xmax=levelMap[0].length(); int cells=(ymax)*(xmax); int[] size={xmax,ymax}; boolean isForward=true; boolean[][] isDone=new boolean[xmax][ymax]; int score=0; isDone[0][0]=true; int modCounter=0; for(int count=1;count<cells;count++){ if(pos[dim]==size[dim]-1 || (pos[dim]==0 && count!=1) || ((isForward && dim==0 && isDone[pos[0]+1][pos[1]]) || (isForward && dim==1 && isDone[pos[0]][pos[1]+1])) || ((!isForward && dim==0 && isDone[pos[0]-1][pos[1]]) || (!isForward && dim==1 && isDone[pos[0]][pos[1]-1]))) { if(++modCounter%2==0) isForward=!isForward; dim=++dim%2; if(isForward)pos[dim]++; else pos[dim]--; isDone[pos[0]][pos[1]]=true; }else { score+=Integer.parseInt(String.valueOf(levelMap[pos[1]].charAt(pos[0]))); if(isForward)pos[dim]++; else pos[dim]--; isDone[pos[0]][pos[1]]=true; } } score+=Integer.parseInt(String.valueOf(levelMap[pos[1]].charAt(pos[0]))); return score; }   public static void main(String z[]){ String[] inp={"86850","76439", "15863", "24568", "45679", "71452", "05483" }; System.out.println(new SpiralWalking().totalPoints(inp)); } }

Top Coder SRM 701

over 8 years ago | Lakshman Prasad: becomingGuru.com

Problem Statement You are playing a game where you must traverse a rectangular grid of cells using a spiral path. The map is given in a String[] levelMap, where the j-th character of the i-th element is the number of points associated with the cell in row i, column j. Rows are numbered from top to bottom, starting at 0, and columns are numbered from left to right, starting at 0. All coordinates in this problem will be given as (row, column). You start at cell (0,0), the top left corner of the grid. You are facing right. You move by repeating the following strategy until you have visited every single cell on the grid exactly once. If there is an adjacent cell in front of you that you haven't visited yet, move forward to that cell. Otherwise, if there are still unvisited cells on the grid, turn 90 degrees clockwise. To calculate your final score, add up all the points for the cells that you visited, but don't include the cells in which you changed direction. The first and last cells in your path will always be included in your final score. See examples for further clarification. Definition Class: SpiralWalking Method: totalPoints Parameters: String[] Returns: int Method signature: int totalPoints(String[] levelMap) (be sure your method is public) Constraints - levelMap will contain between 2 and 50 elements, inclusive. - All elements of levelMap will contain the same number of characters. - Each element of levelMap will contain between 2 and 50 digits ('0'-'9'), inclusive. Examples 0) {"111", "111", "111"} Returns: 5 This is the spiral path you must follow: (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (2,1) -> (2,0) -> (1,0) -> (1,1). 1) {"101", "110"} Returns: 3 The grid is not always a square. 2) {"00", "10"} Returns: 1 3) {"86850", 1: public class SpiralWalking{ 2: public int totalPoints(String[] levelMap){ 3: int[] pos={0,0}; 4: int dim=0; 5: int ymax=levelMap.length; 6: int xmax=levelMap[0].length(); 7: int cells=(ymax)*(xmax); 8: int[] size={xmax,ymax}; 9: boolean isForward=true; 10: boolean[][] isDone=new boolean[xmax][ymax]; 11: int score=0; 12: isDone[0][0]=true; 13: int modCounter=0; 14: for(int count=1;count<cells;count++){ 15: if(pos[dim]==size[dim]-1 || (pos[dim]==0 && count!=1) 16: || ((isForward && dim==0 && isDone[pos[0]+1][pos[1]]) 17: || (isForward && dim==1 && isDone[pos[0]][pos[1]+1])) 18: || ((!isForward && dim==0 && isDone[pos[0]-1][pos[1]]) 19: || (!isForward && dim==1 && isDone[pos[0]][pos[1]-1]))) { 20: if(++modCounter%2==0) isForward=!isForward; 21: dim=++dim%2; 22: if(isForward)pos[dim]++; else pos[dim]--; 23: isDone[pos[0]][pos[1]]=true; 24: }else { 25: score+=Integer.parseInt(String.valueOf(levelMap[pos[1]].charAt(pos[0]))); 26: if(isForward)pos[dim]++; else pos[dim]--; 27: isDone[pos[0]][pos[1]]=true; 28: } 29: } 30: score+=Integer.parseInt(String.valueOf(levelMap[pos[1]].charAt(pos[0]))); 31: return score; 32: } 33:  34: public static void main(String z[]){ 35: String[] inp={"86850","76439", 36: "15863", 37: "24568", 38: "45679", 39: "71452", 40: "05483" 41: }; 42: System.out.println(new SpiralWalking().totalPoints(inp)); 43: } 44: } "76439", "15863", "24568", "45679", "71452", "05483"} Returns: 142 The following image shows your path. The yellow cell is the last cell you visit. You receive points for all the cells except the red ones.  This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

Pacing it right

over 8 years ago | Bhuwan Lodha: What Not to Build

Speed is increasingly of the essence in new product development. The idea is to get to market fast. But how do you "do it right" and "do it fast"? Well, just because you might do something slowly doesn't mean you'll do it right, and it's also true that speedy execution does not preclude high quality of execution. No two ways about it, though, it does make the task more challenging.The single most effective way to speed up the process is not to make mistakes. Instead of cutting corners, build in quality at every step, so that you "do it right the first time" and don't have to waste time doing it over again.Product managers should invest a lot of time in defining the new product at the outset, so that everyone doesn't squander time on unfocused and unnecessary activities.Let's not run a relay race. Ever since Henry Ford made the assembly line practical, businesses have been obsessed with sequential processing: do this, finish it, then do this, finish it, then go on to this and so on. To whatever degree possible, you should try to abandon sequential processing for parallel processing. Divide the task at hand to several parallel steps. And of-course make sure you maintain constant intercommunication.Through clear definition of corporate goals and strategic plan, you should prioritize the proposed new activities. Which ones are important to work on now? Which can be back-burnered? Which can be scrapped? If need be, make hard choices, and then, get set to work on them.Speed is important in product development, but carelessness is unforgivable. It is not unforgivable just for some highflauntin moral reason, but because customers will not forgive products that are flawed in design or in quality. Most people spend much of their lives trying not to look like fools. Your customers are no different. They won't take a chance on a new product that has a flawed reputation.