#69  Weight for weight


My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest.


I am the one who establishes the list so I told him: "Don't worry any more, I will modify the order of the list". It was decided to attribute a "weight" to numbers. The weight of a number will be from now on the sum of its digits.


For example 99 will have "weight" 18, 100 will have "weight" 1 so in the list 100 will come before 99. Given a string with the weights of FFC members in normal order can you give this string ordered by "weights" of these numbers?


Example:

"56 65 74 100 99 68 86 180 90" ordered by numbers weights becomes: "100 180 90 56 65 74 68 86 99"


When two numbers have the same "weight", let us class them as if they were strings and not numbers: 100 is before 180 because its "weight" (1) is less than the one of 180 (9) and 180 is before 90 since, having the same "weight" (9) it comes before as a string.


All numbers in the list are positive numbers and the list can be empty.




#46 Your order, please



Your task is to sort a given string. Each word in the String will contain a single number. This number is the position the word should have in the result.


Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).


If the input String is empty, return an empty String. The words in the input String will only contain valid consecutive numbers.


For an input: "is2 Thi1s T4est 3a" the function should return "Thi1s is2 3a T4est"


your_order("is2 Thi1s T4est 3a")


[1] "Thi1s is2 3a T4est"



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.


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

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


+ Recent posts