운영서버에 간헐적으로 CPU 사용량이 100%가 되어 내려오지 않는 현상이 발생하였고 몇주동안이나 원인을 찾지 못하다가 

우연히 서버에 CSV 파일을 업로드하다 무한루프가 있음을 발견하였다.


CSV 한 행에서 열의 갯수가 3개 이하일 경우 3개로 맞춰주는 부분을 아래와 같이 while문을 통해 작성하였는데,


String [] row = getRows(); // csv 파일의 한 행을 String [] 형태로 반환한다;
while(row.length != 3) // 
   Arrays.append(row,"");


열의 갯수가 3보다 큰 경우를 고려하지 않아서 열의 갯수가 3보다 큰경우의 무한루프에 빠지게 되었다.

조건문을 수정하여 row.length != 3 -> row.length <3  문제는 해결 하였지만 


기본적인 부분에서 테스트 미흡 , 무한루프를 고려하지 못한점이 많이 아쉽다.



요약


원인 : while문을 사용할때 잘못 된 조건문 사용

해결 : 조건문 수정 / while 문사용시 무한 루프 고려 및 테스트 철저히

 #90 Cure Cancer


Now you are a doctor.


You are working with a patient's body which has many cells.


The patient's body is a matrix where every row represents a cell.


Each cell contains just uppercase and lowercase letters,


and every cell in the body should be the same.


Oh no! It seems that one of the cells have mutated!


It is your job to locate the mutation so that the chemo specialists can fix it!


return the location [i,j] within the matrix...


before it's too late! :(


example:


cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecadecells <- here it is! [9, 20]

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

cellscellscellscodecodecells

no bodies will have less than 3 cells.

if the diagnose was a false alarm, return an empty array.




#89 Mexican Wave


Introduction

 The wave (known as the Mexican wave in the English-speaking world outside North America) is an example of metachronal rhythm achieved in a packed stadium when successive groups of spectators briefly stand, yell, and raise their arms. Immediately upon stretching to full height, the spectator returns to the usual seated position. The result is a wave of standing spectators that travels through the crowd, even though individual spectators never move away from their seats. In many large arenas the crowd is seated in a contiguous circuit all the way around the sport field, and so the wave is able to travel continuously around the arena; in discontiguous seating arrangements, the wave can instead reflect back and forth through the crowd. When the gap in seating is narrow, the wave can sometimes pass through it. Usually only one wave crest will be present at any given time in an arena, although simultaneous, counter-rotating waves have been produced. (Source Wikipedia)

 


Task

In this simple Kata your task is to create a function that turns a string into a Mexican Wave. You will be passed a string and you must return that string in an array where an uppercase letter is a person standing up.


Rules

1.  The input string will always be lower case but maybe empty.

2.  If the character in the string is whitespace then pass over it as if it was an empty seat.


Example

wave("hello") => ["Hello", "hEllo", "heLlo", "helLo", "hellO"]


Good luck and enjoy!




#84Can you get the loop ?


You are given a node that is the beginning of a linked list. This list always contains a tail and a loop.


Your objective is to determine the length of the loop.


For example in the following picture the tail's size is 3 and the loop size is 11.


Image and video hosting by TinyPic


// Use the `getNext()` method to get the following node.


node.getNext()

Note: do NOT mutate the nodes!


Thanks to shadchnev, I broke all of the methods from the Hash class.


Don't miss dmitry's article in the discussion after you pass the Kata !!



 #83 Stop gninnipS My sdroW!


Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.



Examples:


spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" 

spinWords( "This is a test") => returns "This is a test" 

spinWords( "This is another test" )=> returns "This is rehtona test"


 #82Evil Autocorrect Prank


Your friend won't stop texting his girlfriend. It's all he does. All day. Seriously. The texts are so mushy too! The whole situation just makes you feel ill. Being the wonderful friend that you are, you hatch an evil plot. While he's sleeping, you take his phone and change the autocorrect options so that every time he types "you" or "u" it gets changed to "your sister."


Write a function called autocorrect that takes a string and replaces all instances of "you" or "u" (not case sensitive) with "your sister" (always lower case).


Return the resulting string.


Here's the slightly tricky part: These are text messages, so there are different forms of "you" and "u".


For the purposes of this kata, here's what you need to support:


"youuuuu" with any number of u characters tacked onto the end

"u" at the beginning, middle, or end of a string, but NOT part of a word

"you" but NOT as part of another word like youtube or bayou


#81 Format words into a sentence


Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string values should be ignored. Empty arrays or null/nil values being passed into the method should result in an empty string being returned.


Kata.formatWords(new String[] {"ninja", "samurai", "ronin"}) => "ninja, samurai and ronin"

Kata.formatWords(new String[] {"ninja", "", "ronin"}) => "ninja and ronin"

Kata.formatWords(new String[] {}) => ""



import java.util.Arrays;
import java.util.stream.Collectors;

public class Kata {

	 public static String replaceLast(String str, String regex, String replacement) {
	        int regexIndexOf = str.lastIndexOf(regex);
	        if(regexIndexOf == -1){
	            return str;
	        }else{
	            return str.substring(0, regexIndexOf) + replacement + str.substring(regexIndexOf + regex.length());
	        }
	}

  public static String formatWords(String[] words) {
    // Do the things...
    if(words == null) return "";
    return replaceLast(Arrays.stream(words).filter(word -> !word.equals("")).collect(Collectors.joining(", ")),", "," and ");
  }

}

Underscores in Numeric Literals


긴 숫자를 선언할때 숫자사이에 언더스코어를 넣어서 가독성을 향상 시킬수 있다. 


숫자 구두점처럼 3자리마다 찍을 필요는 없고 숫자와 숫자 사이에서만 유효하다.

int price = 1000000;
int price =1_000_000;


#67 Predict your age!


My grandfather always predicted how old people would get, and right before he passed away he revealed his secret!


In honor of my grandfather's memory we will write a function using his formula!


Take a list of ages when each of your great-grandparent died.

Multiply each number by itself.

Add them all together.

Take the square root of the result.

Divide by two.

Example

predictAge(65, 60, 75, 55, 60, 63, 64, 45) === 86

Note: the result should be rounded down to the nearest integer.




#51 Simple string indices


n this Kata, you will be given a string with brackets and an index of an opening bracket and your task will be to return the index of the matching closing bracket. Both the input and returned index are 0-based except in Fortran where it is 1-based. An opening brace will always have a closing brace. Return -1 if there is no answer (Haskell return Nothing, Fortran: return 0)


For example


solve("((1)23(45))(aB)", 0) = 10 // the opening brace at index 0 matches the closing brace at index 10

solve("((1)23(45))(aB)", 1) = 3 

solve("((1)23(45))(aB)", 2) = -1 // there is no opening bracket at index 2, so return -1

solve("((1)23(45))(aB)", 6) = 9

solve("((1)23(45))(aB)", 11) = 14

solve("((>)|?(*'))(yZ)", 11) = 14



+ Recent posts