#48 A Rule of Divisibility by 13


When you divide the successive powers of 10 by 13 you get the following remainders of the integer divisions:


1, 10, 9, 12, 3, 4.


Then the whole pattern repeats.


Hence the following method: Multiply the right most digit of the number with the left most number in the sequence shown above, the second right most digit to the second left most digit of the number in the sequence. The cycle goes on and you sum all these products. Repeat this process until the sequence of sums is stationary.


...........................................................................


Example: What is the remainder when 1234567 is divided by 13?


7×1 + 6×10 + 5×9 + 4×12 + 3×3 + 2×4 + 1×1 = 178


We repeat the process with 178:


8x1 + 7x10 + 1x9 = 87


and again with 87:


7x1 + 8x10 = 87


...........................................................................


From now on the sequence is stationary and the remainder of 1234567 by 13 is the same as the remainder of 87 by 13: 9


Call thirt the function which processes this sequence of operations on an integer n (>=0). thirt will return the stationary number.


thirt(1234567) calculates 178, then 87, then 87 and returns 87.


thirt(321) calculates 48, 48 and returns 48




#47 String repeat 


Write a function called repeatStr which repeats the given string string exactly n times.


repeatStr(6, "I") // "IIIIII"

repeatStr(5, "Hello") // "HelloHelloHelloHelloHello"



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



 #45 Sort - one, three, two

Hey You !

Sort these integers for me ...


By name ...


Do it now !


Input

Range is 0-999


There may be duplicates


The array may be empty


#44 Bouncing Balls


A child plays with a ball on the nth floor of a big building. The height of this floor is known.


(float parameter "h" in meters. Condition 1) : h > 0)


He lets out the ball. The ball bounces for example to two-thirds of its height.


(float parameter "bounce". Condition 2) : 0 < bounce < 1)


His mother looks out of a window that is 1.5 meters from the ground.


(float parameters "window". Condition 3) : window < h).


How many times will the mother see the ball either falling or bouncing in front of the window?


If all three conditions above are fulfilled, return a positive integer, otherwise return -1.


Note


You will admit that the ball can only be seen if the height of the rebouncing ball is stricty greater than the window parameter.


Example:


h = 3, bounce = 0.66, window = 1.5, result is 3


h = 3, bounce = 1, window = 1.5, result is -1 (Condition 2) not fulfilled).



 #43Counting Duplicates


Count the number of Duplicates

Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.


Example

"abcde" -> 0 # no characters repeats more than once

"aabbcde" -> 2 # 'a' and 'b'

"aabBcde" -> 2 # 'a' occurs twice and 'b' twice (bandB)

"indivisibility" -> 1 # 'i' occurs six times

"Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice

"aA11" -> 2 # 'a' and '1'

"ABBA" -> 2 # 'A' and 'B' each occur twice



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

#3 PANGRAM  (0) 2018.03.08
#2 가챠 - 가중치가 있는 랜덤  (0) 2018.03.07
#1 문자열 역순으로 출력하기  (0) 2018.03.07

테스트 결제 건을 자정에 자동 취소 시키는 서비스를 만들었는데  아래와 같은 이유로 취소 문자가 반복적으로 발송 됨.


1. 대상 범위 설정 오류 - 현재 상태값에 상관 업이 모든 상태를 재설정함.

->  현재 상태가 취소가 아닌것의 상태만 취소로 바꿔줬어야 함.


2. 다른사람이 작성한 메소드를 이용함에 있어서 동작을 제대로 파악하지 않음.

-> 테스트 결제의 경우 메일 /문자가 발송되지 않았을 것으로 판단했으나 실제로는 발송됨.

 테스트 결제건은 메일/ 문자가 발송 되지 않도록 처리 하거나  1번을 좀더 신경썼어야 함.


3. 실제 환경에서 테스트를 1번이라도 해봤으면 2와 같은일은 없음.

-> 환경 탓 하지말고 실환경에 유사하게 테스트 할 수 있도록 노력해야 함.



요약


문제 : 전반적으로 시스템 이해도 떨어짐. 다른사람 코드를 분석하는 능력 떨어짐. 테스트 게을리함.

해결 : 단디하자....

#42 Delete occurrences of an element if it occurs more than n times



Enough is enough!

Alice and Bob were on a holiday. Both of them took many pictures of the places they've been, and now they want to show Charlie their entire collection. However, Charlie doesn't like this sessions, since the motive usually repeats. He isn't fond of seeing the Eiffel tower 40 times. He tells them that he will only sit during the session if they show the same motive at most N times. Luckily, Alice and Bob are able to encode the motive as a number. Can you help them to remove numbers such that their list contains each number only up to N times, without changing the order?


Task

Given a list lst and a number N, create a new list that contains each number of lst at most N times without reordering. For example if N = 2, and the input is [1,2,3,1,2,1,2,3], you take [1,2,3,1,2], drop the next [1,2] since this would lead to 1 and 2 being in the result 3 times, and then take 3, which leads to [1,2,3,1,2,3].


Example

EnoughIsEnough.deleteNth(new int[] {20,37,20,21}, 1) // return [20,37,21]

EnoughIsEnough.deleteNth(new int[] {1,1,3,3,7,2,2,2,2}, 3) // return [1, 1, 3, 3, 7, 2, 2, 2]



#41 Dashatize it

 

 

Given a number, return a string with dash'-'marks before and after each odd integer, but do not begin or end the string with a dash mark.

 

Ex:
dashatize(274) -> '2-7-4'
dashatize(6815) -> '68-1-5'

 

#40 What's a Perfect Power anyway?


A perfect power is a classification of positive integers:


In mathematics, a perfect power is a positive integer that can be expressed as an integer power of another positive integer. More formally, n is a perfect power if there exist natural numbers m > 1, and k > 1 such that mk = n.


Your task is to check wheter a given integer is a perfect power. If it is a perfect power, return a pair m and k with mk = n as a proof. Otherwise return Nothing, Nil, null, NULL, None or your language's equivalent.


Note: For a perfect power, there might be several pairs. For example 81 = 3^4 = 9^2, so (3,4) and (9,2) are valid solutions. However, the tests take care of this, so if a number is a perfect power, return any pair that proves it.


Examples

isPerfectPower(4) => new int[]{2,2}

isPerfectPower(5) => null

isPerfectPower(8) => new int[]{2,3}

isPerfectPower(9) => new int[]{3,2}


+ Recent posts