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



#33 Vasya - Clerk


The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill. An "Avengers" ticket costs 25 dollars.


Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.


Can Vasya sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?


Return YES, if Vasya can sell a ticket to each person and give the change with the bills he has at hand at that moment. Otherwise return NO.


###Examples:


// *** Java ***


Line.Tickets(new int[] {25, 25, 50}) // => YES 

Line.Tickets(new int []{25, 100}) 

         // => NO. Vasya will not have enough money to give change to 100 dollars




	  public static String Tickets(int[] peopleInLine) {
		  
	      //Your code is here...
		  int dollars25 = 0;
		  int dollars50 = 0;
		  
		  for (int i : peopleInLine) {
			  if(i==25) {
				  dollars25++;
			  }else if(i==50) {
				  dollars25--;
				  dollars50++;
			  }else {
				  if(dollars50>0) {
					  dollars50--;
					  dollars25--;
				  }else {
					  dollars25 -=3;
				  }
			  }
			  if (dollars25<0 || dollars50<0) return "NO";
		  }
		  return "YES";
	  }

#32 Dubstep


Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.


Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Polycarpus inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.


For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".


Recently, Jonny has heard Polycarpus's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Polycarpus remixed. Help Jonny restore the original song.


Input

The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters


Output

Return the words of the initial song that Polycarpus used to make a dubsteb remix. Separate the words with a space.


Examples

songDecoder("WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB")

  // =>  WE ARE THE CHAMPIONS MY FRIEND


 #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

#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

업데이트로 인한 조기출근 + 추움 + 비 3연타로 몸살 


오늘 못한 코딩은 주말에 매꾸는걸로 i - i

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


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

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


+ Recent posts