#36 The Supermarket Queue 


There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!


The function has two input variables:


customers: an array (list in python) of positive integers representing the queue. Each integer represents a customer, and its value is the amount of time they require to check out.

n: a positive integer, the number of checkout tills.

The function should return an integer, the total time required.


EDIT: A lot of people have been confused in the comments. To try to prevent any more confusion:


There is only ONE queue, and

The order of the queue NEVER changes, and

Assume that the front person in the queue (i.e. the first element in the array/list) proceeds to a till as soon as it becomes free.

The diagram on the wiki page I linked to at the bottom of the description may be useful.

So, for example:


queueTime([5,3,4], 1)

// should return 12

// because when n=1, the total time is just the sum of the times


queueTime([10,2,3,3], 2)

// should return 10

// because here n=2 and the 2nd, 3rd, and 4th people in the 

// queue finish before the 1st person has finished.


queueTime([2,3,10], 2)

// should return 12



#34 Write Number in Expanded Form


Write Number in Expanded Form

You will be given a number and you will need to return it as a string in Expanded Form. For example:


Kata.expandedForm(12); # Should return "10 + 2"

Kata.expandedForm(42); # Should return "40 + 2"

Kata.expandedForm(70304); # Should return "70000 + 300 + 4"

NOTE: All numbers will be whole numbers greater than 0.



#30 Psychic


A common exercise, when you're learning a new language, is to make a guessing game. It's a great way to learn control structures, IO, the works.


This is taking the guessing game to a whole new level. This time, you're the one playing the guessing game. And the guessing game is Math.random().


The task is really simple. You make a guess, Math.random() does it's thing, and if you're right 5 times out of 5, you win!


Hint: You guess first.



#28 Valid Braces


Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return true if the string is valid, and false if it's invalid.


This Kata is similar to the Valid Parentheses Kata, but introduces new characters: brackets [], and curly braces {}. Thanks to @arnedag for the idea!


All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: ()[]{}.


What is considered Valid?

A string of braces is considered valid if all braces are matched with the correct brace.


Examples


"(){}[]"   =>  True

"([{}])"   =>  True

"(}"       =>  False

"[(])"     =>  False

"[({})](]" =>  False



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

codewars #30 Psychic (3kyu)  (1) 2018.04.27
codewars #29 Multiples of 3 or 5 (6kyu)  (0) 2018.04.26
codewars #27 Follow that Spy (6kyu)  (0) 2018.04.24
오늘은 하루 쉼  (0) 2018.04.23
codewars #26 lucky number (7kyu)  (1) 2018.04.20

#27 Follow that Spy


We are tracking down our rogue agent Matthew Knight A.K.A. Roy Miller and he travels from places to places to avoid being tracked. Each of his travels are based on a list of itineraries in an unusual or incorrect order. The task is to determine the routes he will take in his every journey. You are given an array of routes of his itineraries. List down only the places where he will go in correct order based on his itineraries.


Example:

routes = [[USA, BRA], [JPN, PHL], [BRA, UAE], [UAE, JPN]]


result: "USA, BRA, UAE, JPN, PHL"


note: It is safe to assume that there will be no repeating place with different rout



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

codewars #29 Multiples of 3 or 5 (6kyu)  (0) 2018.04.26
codewars #28 Valid Braces (4kyu)  (1) 2018.04.25
오늘은 하루 쉼  (0) 2018.04.23
codewars #26 lucky number (7kyu)  (1) 2018.04.20
codewars #25 Find The Parity Outlier (6kyu)  (0) 2018.04.19

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





+ Recent posts