2022/05/22 4

[Easy] FrogJmp

[문제] 현재 위치(X), 점프 거리(D), 목표지점(Y) 현재 위치로부터 목표지점에 도달/지나칠 때까지 몇번의 점프를 해야하는지 찾는 문제 FrogJmp coding task - Learn to Code - Codility Count minimal number of jumps from position X to Y. app.codility.com [코드] # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(X, Y, D): # write your code in Python 3.6 count=Y-X if count==0: return 0 i = int(count/D) j = ..

기타/Codility 2022.05.22

[Easy] CyclicRotation

[문제] 주어진 수(K)만큼 1차원 배열을 회전하는 문제 [코드] # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A, K): # write your code in Python 3.6 lenth = len(A) if lenth==0 or K==0: return A K%=lenth answer=[0 for i in range(lenth)] for i in range(0, lenth) : answer[(i+K)%lenth] = A[i] return answer * 0에 대한 별도 처리 필요 https://app.codility.com/programmers/lessons/2-..

기타/Codility 2022.05.22

[Easy] ArrListLen

[문제] 배열 내 값을 배열 idx로 사용하여 접근하며 '-1'이 있는 배열 idx에 몇번만에 도달하는지 찾는 문제 [코드] # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A): # write your code in Python 3.6 answer=1 i=0 while True: if A[i] == -1: break; else: i = A[i] answer+=1 return answer # PassTheMessage is recommended https://app.codility.com/demo/results/trainingJVBNCC-F9V/ Test results ..

기타/Codility 2022.05.22

[Easy] BinaryGap

[문제] 2진수에 대해 1로 둘러싸인 연속된 0의 숫자를 세어 가장 큰 연속된 0의 개수를 출력하는 문제 [코드] # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(N): # write your code in Python 3.6 binary = bin(N) start=0 cont=0 answer=0 for b in binary: if b=='1' and start==0: start=1 elif b=='0' and start==1: cont+=1 elif b=='1' and start==1: answer = max(answer, cont) cont=0 return answe..

기타/Codility 2022.05.22
반응형