#31 extract file name


ou have to extract a portion of the file name as follows:


Assume it will start with date represented as long number

Followed by an underscore

Youll have then a filename with an extension

it will always have an extra extension at the end

Inputs:

1231231223123131_FILE_NAME.EXTENSION.OTHEREXTENSION


1_This_is_an_otherExample.mpg.OTHEREXTENSIONadasdassdassds34


1231231223123131_myFile.tar.gz2

Outputs

FILE_NAME.EXTENSION


This_is_an_otherExample.mpg


myFile.tar

The recommend way to solve it is using RegEx and specifically groups.



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

codewars #33 Vasya - Clerk (6kyu)  (1) 2018.05.02
codewars #32 Dubstep (6kyu)  (0) 2018.05.01
codewars #30 Psychic (3kyu)  (1) 2018.04.27
codewars #29 Multiples of 3 or 5 (6kyu)  (0) 2018.04.26
codewars #28 Valid Braces (4kyu)  (1) 2018.04.25

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



codewars #29  Multiples of 3 or 5



If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.


Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.


Note: If the number is a multiple of both 3 and 5, only count it once.


Courtesy of ProjectEuler.net



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

codewars #31 extract file name (6kyu)  (0) 2018.04.30
codewars #30 Psychic (3kyu)  (1) 2018.04.27
codewars #28 Valid Braces (4kyu)  (1) 2018.04.25
codewars #27 Follow that Spy (6kyu)  (0) 2018.04.24
오늘은 하루 쉼  (0) 2018.04.23

#26 lucky number



Write a function to find if a number is lucky or not. If the sum of all digits is 0 or multiple of 9 then the number is lucky.


1892376 => 1+8+9+2+3+7+6 = 36. 36 is divisble by 9, hence number is lucky.


Function will return true for lucky numbers and false for others.


집에 너무 늦게 들어온데다가 이번주내내 잠을 못자서 너무 피곤한 관계로 낮은 레벨을 선택해서 품

어뷰징에 대해 고민이 조금 있긴 하지만, 한번 안하면 두번 안하는건 일도 아니기 때문이 쉬운문제라도 풀기로 한다.


#25 Find The Parity Outlier



You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N.


Examples

[2, 4, 0, 100, 4, 11, 2602, 36]

Should return: 11 (the only odd number)


[160, 3, 1719, 19, 11, 13, -21]

Should return: 160 (the only even number)



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

오늘은 하루 쉼  (0) 2018.04.23
codewars #26 lucky number (7kyu)  (1) 2018.04.20
codewars #24 A + B == 123 (6kyu)  (0) 2018.04.18
codewars #23 Prime Streaming (NC-17) (2kyu)  (1) 2018.04.17
codewars #22 Fat Fingers (5kyu)  (0) 2018.04.16

#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


:-)



#23 Prime Streaming


Create an endless stream of prime numbers - a bit like IntStream.of(2,3,5,7,11,13,17), but infinite. The stream must be able to produce 50 million primes in a few seconds.


당당하게 도전하고 ,당당하게 망했다 3시간동안 고민해봤는데 못풀겠다.

현재 레벨보다 높은 단계라 솔루션도 못본다. 포기하고 다른문제 풀어서 올릴까하다가 

들인시간이 아까워서 주말에 다시 풀어보려고 올림



#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




+ Recent posts