#94 The Hashtag Generator


The marketing team are spending way too much time typing in hashtags.

Let's help them with out own Hashtag Generator!


Here's the deal:


- If the final result is longer than 140 chars it must return false.

- If the input is a empty string it must return false.

- It must start with a hashtag (#).

- All words must have their first letter capitalized.


Example Input to Output:


" Hello there thanks for trying my Kata" => "#HelloThereThanksForTryingMyKata"


" Hello World " => "#HelloWorld"




'매일매일개발 > Codewars' 카테고리의 다른 글

codewars #93 Number Format (6kyu)  (0) 2018.08.08
codewars #92 Bit calculator (5kyu)  (0) 2018.08.07
codewars #91 Find X (6kyu)  (0) 2018.08.06
codewars #90 Cure Cancer (6kyu)  (0) 2018.08.01
codewars #89 Mexican Wave (6kyu)  (0) 2018.07.31

#93 Number Format


Format any integer provided into a string with "," (commas) in the correct places.


Example:


numberFormat(100000); // return '100,000'

numberFormat(5678545); // return '5,678,545'

numberFormat(-420902); // return '-420,902'


'매일매일개발 > Codewars' 카테고리의 다른 글

codewars #94 The Hashtag Generator (5kyu)  (0) 2018.08.09
codewars #92 Bit calculator (5kyu)  (0) 2018.08.07
codewars #91 Find X (6kyu)  (0) 2018.08.06
codewars #90 Cure Cancer (6kyu)  (0) 2018.08.01
codewars #89 Mexican Wave (6kyu)  (0) 2018.07.31

 #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!




#88 Which are in?


Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.


#Example 1: a1 = ["arp", "live", "strong"]


a2 = ["lively", "alive", "harp", "sharp", "armstrong"]


returns ["arp", "live", "strong"]


#Example 2: a1 = ["tarp", "mice", "bull"]


a2 = ["lively", "alive", "harp", "sharp", "armstrong"]


returns []


Notes:

Arrays are written in "general" notation. See "Your Test Cases" for examples in your language.


In Shell bash a1 and a2 are strings. The return is a string where words are separated by commas.


Beware: r must be without duplicates.

Don't mutate the inputs.


 #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 ");
  }

}

#79 Human readable duration format


Your task in order to complete this Kata is to write a function which formats a duration, given as a number of seconds, in a human-friendly way.


The function must accept a non-negative integer. If it is zero, it just returns "now". Otherwise, the duration is expressed as a combination of years, days, hours, minutes and seconds.


It is much easier to understand with an example:


TimeFormatter.formatDuration(62)   //returns "1 minute and 2 seconds"

TimeFormatter.formatDuration(3662) //returns "1 hour, 1 minute and 2 seconds"

For the purpose of this Kata, a year is 365 days and a day is 24 hours.


Note that spaces are important.


Detailed rules

The resulting expression is made of components like 4 seconds, 1 year, etc. In general, a positive integer and one of the valid units of time, separated by a space. The unit of time is used in plural if the integer is greater than 1.


The components are separated by a comma and a space (", "). Except the last component, which is separated by " and ", just like it would be written in English.


A more significant units of time will occur before than a least significant one. Therefore, 1 second and 1 year is not correct, but 1 year and 1 second is.


Different components have different unit of times. So there is not repeated units like in 5 seconds and 1 second.


A component will not appear at all if its value happens to be zero. Hence, 1 minute and 0 seconds is not valid, but it should be just 1 minute.


A unit of time must be used "as much as possible". It means that the function should not return 61 seconds, but 1 minute and 1 second instead. Formally, the duration specified by of a component must not be greater than any valid more significant unit of time.




 #78 Convert PascalCase string into snake_case


Complete the function/method so that it takes CamelCase string and returns the string in snake_case notation. Lowercase characters can be numbers. If method gets number, it should return string.


Examples:


//  returns test_controller

toUnderscore('TestController');


// returns movies_and_books

toUnderscore('MoviesAndBooks');


// returns app7_test

toUnderscore('App7Test');


// returns "1"

toUnderscore(1);


+ Recent posts