#24 A + B = 123



Task

Given number A you must return number B so that


(int) (A + B) == 123


Note

B can't be negative


:-)



#22 Fat Fingers


Freddy has a really fat left pinky finger, and every time Freddy tries to type an A, he accidentally hits the CapsLock key!


Given a string that Freddy wants to type, emulate the keyboard misses where each A supposedly pressed is replaced with CapsLock, and return the string that Freddy actually types. It doesn't matter if the A in the string is capitalized or not. When CapsLock is enabled, capitalization is reversed, but punctuation is not affected.


Examples:


"The quick brown fox jumps over the lazy dog."

-> "The quick brown fox jumps over the lZY DOG."


"The end of the institution, maintenance, and administration of government, is to secure the existence of the body politic, to protect it, and to furnish the individuals who compose it with the power of enjoying in safety and tranquillity their natural rights, and the blessings of life: and whenever these great objects are not obtained, the people have a right to alter the government, and to take measures necessary for their safety, prosperity and happiness."

-> "The end of the institution, mINTENnce, ND dministrTION OF GOVERNMENT, IS TO SECURE THE EXISTENCE OF THE BODY POLITIC, TO PROTECT IT, nd to furnish the individuLS WHO COMPOSE IT WITH THE POWER OF ENJOYING IN Sfety ND TRnquillity their nTURl rights, ND THE BLESSINGS OF LIFE: nd whenever these greT OBJECTS re not obtINED, THE PEOPLE Hve  RIGHT TO lter the government, ND TO Tke meSURES NECESSry for their sFETY, PROSPERITY nd hPPINESS."


"aAaaaaAaaaAAaAa"

-> ""

If the given string is null, return null.


If the given string is "", the answer should be evident.


Happy coding!



 #21  Number of trailing zeros of N! 


Write a program that will calculate the number of trailing zeros in a factorial of a given number.


N! = 1 * 2 * 3 * ... * N


Be careful 1000! has 2568 digits...


For more info, see: http://mathworld.wolfram.com/Factorial.html


Examples

zeros(6) = 1

# 6! = 1 * 2 * 3 * 4 * 5 * 6 = 720 --> 1 trailing zero


zeros(12) = 2

# 12! = 479001600 --> 2 trailing zeros

Hint: You're not meant to calculate the factorial. Find another way to find the number of zeros.


팩토리얼을 구하고 0의 갯수를 세면... 타임 초과가 난다 이틀 연속 타임 초과



 #20 The Millionth Fibonacci Kata 


The year is 1214. One night, Pope Innocent III awakens to find the the archangel Gabriel floating before him. Gabriel thunders to the pope:


Gather all of the learned men in Pisa, especially Leonardo Fibonacci. In order for the crusades in the holy lands to be successful, these men must calculate the millionth number in Fibonacci's recurrence. Fail to do this, and your armies will never reclaim the holy land. It is His will.


The angel then vanishes in an explosion of white light.


Pope Innocent III sits in his bed in awe. How much is a million? he thinks to himself. He never was very good at math.


He tries writing the number down, but because everyone in Europe is still using Roman numerals at this moment in history, he cannot represent this number. If he only knew about the invention of zero, it might make this sort of thing easier.


He decides to go back to bed. He consoles himself, The Lord would never challenge me thus; this must have been some deceit by the devil. A pretty horrendous nightmare, to be sure.


Pope Innocent III's armies would go on to conquer Constantinople (now Istanbul), but they would never reclaim the holy land as he desired.


In this kata you will have to calculate fib(n) where:


fib(0) := 0

fib(1) := 1

fin(n + 2) := fib(n + 1) + fib(n)

Write an algorithm that can handle n where 1000000 ≤ n ≤ 1500000.


Your algorithm must output the exact integer answer, to full precision. Also, it must correctly handle negative numbers as input.


HINT I: Can you rearrange the equation fib(n + 2) = fib(n + 1) + fib(n) to find fib(n) if you already know fin(n + 1) and fib(n + 2)? Use this to reason what value fib has to have for negative values.


HINT II: See http://mitpress.mit.edu/sicp/chapter1/node15.html




 #18 Convert string to camel case



Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized.


Examples:


// returns "theStealthWarrior"

toCamelCase("the-stealth-warrior") 


// returns "TheStealthWarrior"

toCamelCase("The_Stealth_Warrior")





#15 Bagels 


Here's a seemingly simple challenge. We're giving you a class called bagel, exactly as it appears below. All it really does is return an int, specifically 3.


public class Bagel {
    public final int getValue() {
        return 3;
    }
}


The catch? For the solution, we're testing that the result is equal to 4. But as a little hint, the solution to the this Kata is exactly the same as the example test cases.

통과조건...
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;

public class BagelTest {

    @Test
    public void testBagel() {
        Bagel bagel = BagelSolver.getBagel();

        assertEquals(
            bagel.getValue() == 4,
            java.lang.Boolean.TRUE
        );
    }

}

...별짓을 다했다 리플랙션 , 프록시, bci

설마이걸까 했는데 -.- 으음 빡친다.

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class BagelSolver {

  public static Bagel getBagel() {
	  try {
		    Field f = Boolean.class.getField("TRUE");
		    Field modifiers = Field.class.getDeclaredField("modifiers");
		    modifiers.setAccessible(true);
		    modifiers.setInt(f, f.getModifiers() & ~Modifier.FINAL);
		    f.set(null, false);
		} catch (Exception e) {
			// TODO: handle exception
		}
    return new Bagel();
  }

}




#13 Anagram Detection


An anagram is the result of rearranging the letters of a word to produce a new word (see wikipedia).


Note: anagrams are case insensitive


Complete the function to return true if the two arguments given are anagrams of theeach other; return false otherwise.


Examples :


"foefet" is an anagram of "toffee"

"Buckethead" is an anagram of "DeathCubeK"



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

Codewars #15 Bagels (4kyu)  (0) 2018.04.06
Codewars #14 Calculator (3kyu)  (0) 2018.04.03
Codewars #12 Range Extraction (4kyu)  (0) 2018.03.30
Codewars #11 Double Cola (5kyu)  (0) 2018.03.30
Codewars #10 Scramblies (5kyu)  (0) 2018.03.28

#Range Extraction


A format for expressing an ordered list of integers is to use a comma separated list of either


individual integers

or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. The range includes all integers in the interval including both endpoints. It is not considered a range unless it spans at least 3 numbers. For example ("12, 13, 15-17")

Complete the solution so that it takes a list of integers in increasing order and returns a correctly formatted string in the range format.


Example:


Solution.rangeExtraction(new int[] {-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20})

# returns "-6,-3-1,3-5,7-11,14,15,17-20"



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

Codewars #14 Calculator (3kyu)  (0) 2018.04.03
Codewars #13 Anagram Detection (7kyu)  (0) 2018.04.02
Codewars #11 Double Cola (5kyu)  (0) 2018.03.30
Codewars #10 Scramblies (5kyu)  (0) 2018.03.28
Codewars #9 Large Factorials (4kyu)  (0) 2018.03.27

# Double Cola



Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on.


For example, Penny drinks the third can of cola and the queue will look like this:


Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny

Write a program that will return the name of the person who will drink the n-th cola.


Note that in the very beginning the queue looks like that:


Sheldon, Leonard, Penny, Rajesh, Howard

##Input


The input data consist of an array which contains at least 1 name, and single integer n.


(1 ≤ n ≤ 1000000000).


##Output / Examples Return the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.


 string[] names = new string[] { "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" };

 int n = 1;

 Line.WhoIsNext(names, n) --> "Sheldon"


 int n = 6;

 Line.WhoIsNext(names, n) --> "Sheldon"


 int n = 52;

 Line.WhoIsNext(names, n) --> "Penny"


 int n = 7230702951;

 Line.WhoIsNext(names, n) --> "Leonard"



# Scramblies


Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.


Notes:


Only lower case letters will be used (a-z). No punctuation or digits will be included.

Performance needs to be considered


Examples

scramble('rkqodlw', 'world') ==> True

scramble('cedewaraaossoqqyt', 'codewars') ==> True

scramble('katas', 'steak') ==> False




+ Recent posts