
RapidKode : 처음으로 올바르게 얻으십시오
RapidKode는 경쟁력있는 프로그래밍 및 코딩을 쉽고 직관적으로 작업하도록 설계된 빠르고 유연하며 표현적인 데이터 구조를 제공하는 파이썬 패키지입니다. Python에서 경쟁 프로그래밍을위한 기본적인 고급 빌딩 블록이되는 것을 목표로합니다. RapidKode를 사용하면 덜 복잡한 알고리즘을 수행 할 수 있습니다. 모든 알고리즘은 최고의 시간으로 최적화되어 시간 복잡성을 줄여 리더 보드에서 눈에 띄게됩니다. 더 이상 거대한 코드를 쓰고 나중에 디버깅하는 데 더 이상 시간이 없으며, RapidKode는 단일 한 줄의 코드로 손가락 끝에서 모든 일이 발생합니다. RapidKode의 목표는 초보자가 경쟁 프로그램을 시작하고 시간과 공간의 중요성을 이해하도록 돕는 것입니다. RapidKode를 만드는 모토는 Util 기능에 10 분의 소중한 시간을 소비하는 대신 '처음으로 올바르게 얻는 것'입니다.
설치:
또는
문제, 버그 보고서 및 기부금은 개발 저장소를 방문하십시오 -> 여기를 클릭하십시오.
사용 가능한 기능 :
숫자 함수 :
| 통사론 | 작업 |
|---|
| 숫자 .gen_sparsenum_upto (x) | 주어진 범위까지 희소 숫자를 생성합니다 |
| 숫자.get_sparsenum_after (n) | 주어진 숫자에 대한 성공적인 스파 스 숫자를 반환합니다 |
| 숫자. Checkprime (x) | 숫자가 프라임 인 경우 True를 반환합니다 |
| 숫자.getPrimes.generate (x) | 먼저 X 소수를 반환합니다 |
| 숫자.getprimes.upto (x) | 주어진 범위까지 소수를 반환합니다 |
| 숫자.getPrimes.inRange (X, Y) | 주어진 범위에서 소수를 반환합니다 |
| 숫자 .fib.getElement (x) | X'TH Fibonacci 번호를 반환합니다 |
| 숫자 .fib.generate (x) | 먼저 x fibonacci 번호를 반환합니다 |
예:
import rapidkode as rk
var = rk . numbers . gen_sparsenum_upto ( 100 )
print ( var )
var = rk . numbers . get_sparsenum_after ( 3289 )
print ( var )
var = rk . numbers . checkprime ( 8364 )
print ( var )
var = rk . numbers . getprimes . generate ( 100 )
print ( var )
var = rk . numbers . getprimes . inrange ( 100 , 500 )
print ( var )
var = rk . numbers . fib . getelement ( 58 )
print ( var )
var = rk . numbers . fib . generate ( 25 )
print ( var )
산출:
[0, 1, 2, 4, 5, 8, 9, 10, 16, 17, 18, 20, 21, 32, 33, 34, 36, 37, 40, 41, 42, 64, 65, 66, 68, 69, 72, 73, 74, 80, 81, 82, 84, 85, 128]
4096
False
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541]
[101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499]
365435296162
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368]
숫자 시스템 - 변환 기능 :
| 통사론 | 작업 |
|---|
| 변환 (x, 'sys'). to ( 'new_sys') | X를 SYS에서 New Sys로 변환합니다 |
| 예: | |
| 변환 (9845, 'dec'). to ( 'bin') | 9845를 10 진에서 바이너리로 변환합니다 |
| 변환 (3745, 'Oct'). to ( 'hex') | 3745를 10 대에서 16645로 변환합니다 |
-
sys 로 [ 'bin', 'dec', 'oct', 'hex'] 및 new_sys [ 'bin', 'dec', 'oct', 'hex']로 대체하여 숫자 변환을 할 수 있습니다.
import rapidkode as rk
converted_num_1 = rk . convert ( 2013 , 'dec' ). to ( 'bin' )
print ( converted_num_1 )
converted_num_2 = rk . convert ( 11111011101 , 'bin' ). to ( 'hex' )
print ( converted_num_2 )
converted_num_3 = rk . convert ( '7dd' , 'hex' ). to ( 'dec' )
print ( converted_num_3 )
converted_num_4 = rk . convert ( 5634 , 'oct' ). to ( 'dec' )
print ( converted_num_4 )
converted_num_5 = rk . convert ( 2972 , 'hex' ). to ( 'oct' )
print ( converted_num_5 )
converted_num_6 = rk . convert ( 24562 , 'oct' ). to ( 'bin' )
print ( converted_num_6 )
산출:
11111011101
7dd
2013
2972
24562
10100101110010
알고리즘 검색 :
| 기술 | 통사론 | 작업 | 시간 복잡성 |
|---|
| 선형 검색 | linear.search (Arr, x) | ARR에서 X의 위치를 반환합니다 | 에) |
| 이진 검색 | 이진 | ARR에서 X의 위치를 반환합니다 | O (로그 N) |
| 점프 검색 | jump.search (arr, x) | ARR에서 X의 위치를 반환합니다 | O (√ n) |
| 보간 검색 | 보간. 검색 (ARR, X) | ARR에서 X의 위치를 반환합니다 | o (log2 (log2 n)) |
| 지수 검색 | Exponential.search (ARR, X) | ARR에서 X의 위치를 반환합니다 | O (log2 I) |
| 3 배 검색 | Ternary.search (ARR, X) | ARR에서 X의 위치를 반환합니다 | O (log3 n) |
추가로 사용할 수 있습니다.
| 기능 | 작업 |
|---|
| .보여주다() | 터미널의 코드를 인쇄합니다 |
| .info () | 간단한 정보를 제공합니다 |
| .Algo () | Step Wise 알고리즘을 인쇄합니다 |
예:
import rapidkode as rk
> >> rk . binary . show ()
> >> rk . binary . info ()
> >> rk . binary . algo ()
산출:
def binarysearch ( arr , x ):
l = 0
r = len ( arr ) - 1
while l <= r :
mid = l + ( r - l ) // 2
if arr [ mid ] == x :
return mid
elif arr [ mid ] < x :
l = mid + 1
else :
r = mid - 1
return "element not found"
Binary search is the search technique that works efficiently on sorted lists
. Hence, to search an element into some list using the binary search technique, we must ensure that the list is sorted
. Binary search follows the divide and conquer approach in which the list is divided into two halves, and the item is compared with the middle element of the list
. If the match is found then, the location of the middle element is returned
. Otherwise, we search into either of the halves depending upon the result produced through the match
Algorithm
Step 1 - Read the search element from the user.
Step 2 - Find the middle element in the sorted list.
Step 3 - Compare the search element with the middle element in the sorted list.
Step 4 - If both are matched, then display "Given element is found!!!" and terminate the function.
Step 5 - If both are not matched, then check whether the search element is smaller or larger than the middle element.
Step 6 - If the search element is smaller than middle element, repeat steps 2, 3, 4 and 5 for the left sublist of the middle element.
Step 7 - If the search element is larger than middle element, repeat steps 2, 3, 4 and 5 for the right sublist of the middle element.
Step 8 - Repeat the same process until we find the search element in the list or until sublist contains only one element.
Step 9 - If that element also doesn't match with the search element, then display "Element is not found in the list!!!" and terminate the function.
세 가지 함수 .show() , .info() , .algo() 는 6 개의 검색 기술 모두에 사용할 수 있습니다.
분류 알고리즘 :
| 기술 | 통사론 | 작업 | 시간 복잡성 |
|---|
| 선택 정렬 | selection.sort (arr) | 주어진 배열을 정렬하고 반환합니다 | O (n^2) |
| 버블 정렬 | bubble.sort (ARR) | 주어진 배열을 정렬하고 반환합니다 | O (n^2) |
| 삽입 정렬 | 삽입 .SORT (ARR) | 주어진 배열을 정렬하고 반환합니다 | O (n^2) |
| 정렬을 병합하십시오 | merge.sort (arr) | 주어진 배열을 정렬하고 반환합니다 | o (n log (n)) |
| 힙 정렬 | Heap.Sort (ARR) | 주어진 배열을 정렬하고 반환합니다 | o (n log (n)) |
| 빠른 정렬 | Quick.sort (시작, 끝, ARR) | 주어진 배열을 정렬하고 반환합니다 | O (n^2) |
| 정렬을 계산하십시오 | count.sort (arr) | 주어진 배열을 정렬하고 반환합니다 | O (N+K) |
| radix 정렬 | radix.sort (arr) | 주어진 배열을 정렬하고 반환합니다 | O (NK) |
| 버킷 정렬 | Bucket.Sort (ARR) | 주어진 배열을 정렬하고 반환합니다 | O (N + K) |
| 쉘 정렬 | Shell.SORT (ARR) | 주어진 배열을 정렬하고 반환합니다 | o (nlog n) |
| 빗 정렬 | Comb.sort (ARR) | 주어진 배열을 정렬하고 반환합니다 | o (n log n) |
| 비둘기 정렬 | PigeonHole.SORT (ARR) | 주어진 배열을 정렬하고 반환합니다 | O (N + N) |
| 사이클 정렬 | cycle.sort (arr) | 주어진 배열을 정렬하고 반환합니다 | O (N2) |
추가로 사용할 수 있습니다.
| 기능 | 작업 |
|---|
| .보여주다() | 터미널의 코드를 인쇄합니다 |
| .info () | 간단한 정보를 제공합니다 |
| .Algo () | Step Wise 알고리즘을 인쇄합니다 |
예:
import rapidkode as rk
> >> rk . count . show ()
> >> rk . count . info ()
> >> rk . count . algo ()
산출:
def countsort ( arr ):
output = [ 0 for i in range ( len ( arr ))]
count = [ 0 for i in range ( 256 )]
array = [ 0 for _ in arr ]
for i in arr :
count [ i ] += 1
for i in range ( 256 ):
count [ i ] += count [ i - 1 ]
for i in range ( len ( arr )):
output [ count [ arr [ i ]] - 1 ] = arr [ i ]
count [ arr [ i ]] -= 1
for i in range ( len ( arr )):
array [ i ] = output [ i ]
return array Counting sort is a sorting algorithm that sorts the elements of an array by counting the number of occurrences of each unique element in the array
. The count is stored in an auxiliary array and the sorting is done by mapping the count as an index of the auxiliary array
. Counting sort is a sorting technique based on keys between a specific range
. It works by counting the number of objects having distinct key values (kind of hashing)
. Then doing some arithmetic to calculate the position of each object in the output sequence
Algorithm
step 1 - Find out the maximum element (let it be max) from the given array.
step 2 - Initialize an array of length max+1 with all elements 0.
This array is used for storing the count of the elements in the array.
step 3 - Store the count of each element at their respective index in count array
For example: if the count of element 3 is 2 then, 2 is stored in the 3rd position of count array.
If element "5" is not present in the array, then 0 is stored in 5th position.
step 4 - Store cumulative sum of the elements of the count array.
It helps in placing the elements into the correct index of the sorted array.
step 5 - Find the index of each element of the original array in the count array.
This gives the cumulative count. Place the element at the index calculated as shown in figure below.
step 6 - After placing each element at its correct position, decrease its count by one.
세 가지 함수 .show() , .info() , .algo() 13 개의 분류 기술 모두에 사용할 수 있습니다.
그래프 기능 :
| 통사론 | 작업 |
|---|
| .Buildedge (u, v) | 그래프 모서리를 만듭니다 |
| .Buildmultiedge ([]) | 주어진 코디 목록이있는 그래프를 만듭니다 |
| .BFS (X) | 폭을 먼저 검색하십시오 |
| .dfs (x) | 깊이 첫 번째 검색을 수행합니다 |
| .findap () | 그래프의 관절 지점을 반환합니다 |
예:
import rapidkode as rk
# make graph object with graph() class
my_graph = rk . graph ()
# adding one edge at a time
my_graph . buildedge ( 0 , 1 )
my_graph . buildedge ( 0 , 2 )
my_graph . buildedge ( 1 , 2 )
my_graph . buildedge ( 2 , 0 )
my_graph . buildedge ( 2 , 3 )
my_graph . buildedge ( 3 , 3 )
import rapidkode as rk
# make graph object with graph() class
my_graph = rk . graph ()
# adding multiple edges at once
my_graph . buildmultiedge ([ 0 , 1 , 0 , 2 , 1 , 2 , 2 , 0 , 2 , 3 , 3 , 3 ])
import rapidkode as rk
# make graph object with graph() class
my_graph = rk . graph ()
my_graph . buildmultiedge ([ 0 , 1 , 0 , 2 , 1 , 2 , 2 , 0 , 2 , 3 , 3 , 3 ])
# performing BFS from edge 2
print ( my_graph . BFS ( 2 ))
# performing DFS from edge 2
print ( my_graph . DFS ( 2 ))
# finding the Articulation Point
print ( my_graph . findAP ())
산출:
['-->', 2, '-->', 0, '-->', 3, '-->', 1]
['-->', 2, '-->', 0, '-->', 1, '-->', 3]
2
패턴 기능 :
다음 함수는 해시 함수를 사용하여 텍스트에서 패턴을 검색/매칭에 사용하는 알고리즘 인 Rabin-Karp 알고리즘을 사용합니다. 순진한 문자열 일치 알고리즘과 달리, 초기 단계에서 모든 문자를 통과하는 것은 아니지만 일치하지 않는 문자를 필터링 한 다음 비교를 수행합니다.
| 통사론 | 작업 |
|---|
| Pattern.isShere (a) .inn (b) | 문자열 a가 문자열 b에 존재하는 경우 true를 반환합니다. |
| pattern.whereis (a) .inn (b) | 문자열 b에서 문자열 a의 인덱스 위치를 반환합니다. |
예:
import rapidkode as rk
a = 'sasi'
b = 'satyasasivatsal'
print ( rk . isthere ( a ). inn ( b ))
print ( rk . whereis ( a ). inn ( b ))
산출:
LinkedList 기능 :
| 작업 | 통사론 |
|---|
| .ins_beg (노드) | 처음에 새 노드를 삽입합니다 |
| .ins_end (노드) | 끝에 새 노드를 삽입합니다 |
| .ins_after (POS, 노드) | 노드가 지정된 후 새 노드를 삽입합니다 |
| .ins_before (POS, 노드) | 지정된 노드 전에 새 노드를 삽입합니다 |
| .del_node (노드) | 지정된 노드를 삭제합니다 |
| .return_as_list () | LinkedList를 Python 목록으로 반환합니다 |
예:
import rapidkode as rk
my_list = rk . linkedlist ()
my_list . head = rk . node ( 'a' )
s1 = rk . node ( 'b' )
s2 = rk . node ( 'c' )
s3 = rk . node ( 'd' )
s4 = rk . node ( 'e' )
s5 = rk . node ( 'f' )
s6 = rk . node ( 'g' )
my_list . head . next = s1
s1 . next = s2
s2 . next = s3
s3 . next = s4
s4 . next = s5
s5 . next = s6
print ( my_list )
출력 :
a -> b -> c -> d -> e -> f -> g -> None
예 -2 :
# insertion at beginning
my_list . ins_beg ( rk . node ( 'A' ))
# insertion at end
my_list . ins_end ( rk . node ( 'G' ))
# insertion at positiom
my_list . ins_after ( 'e' , rk . node ( 'E' ))
# insertion at position
my_list . ins_before ( 'c' , rk . node ( 'C' ))
# deletion of ndoe
my_list . del_node ( 'b' )
# returning as list
my_listt = my_list . return_as_list ()
print ( my_list )
print ( my_listt )
출력 :
A -> a -> C -> c -> d -> e -> E -> f -> g -> G -> None
['A', 'a', 'C', 'c', 'd', 'e', 'E', 'f', 'g', 'G', 'None']
비트 조작 핵 :
| 통사론 | 작업 |
|---|
| 비트 .toggle_bits (x) | 세트 비트와 비 세트 비트를 토글합니다 |
| 비트 .convert_to_bin (x) | 주어진 숫자를 이진으로 변환합니다 |
| bits.counsetbits (x) | 12 월 번호로 세트 비트를 반환합니다 |
| 비트 .rotate_byleft (x, d) | 비트를 왼쪽으로 D 시간으로 회전시킵니다 |
| Bits.rotate_byright (X, D) | 비트를 왼쪽으로 D 시간으로 회전시킵니다 |
| 비트 .countflips (x, y) | 플립 번호를 반환하여 x를 y로 만듭니다 |
예:
import rapidkode as rk
var = rk . bits . toggle_bits ( 873652 )
print ( var )
var = rk . bits . convert_to_bin ( 873652 )
print ( var )
var = rk . bits . countsetbits ( 873652 )
print ( var )
var = rk . bits . rotate_byleft ( 873652 , 4 )
print ( var )
var = rk . bits . rotate_byright ( 873652 , 4 )
print ( var )
var = rk . bits . countflips ( 8934756 , 873652 )
print ( var )
산출:
960632
11010101010010110100
8474306
13978432
54603
7
기타 기타 기능 :
| 통사론 | 작업 |
|---|
| .Showsieves () | 터미널에서 소수를 찾기위한 Sieves 코드를 인쇄합니다 |
| getPrimefactors.fornum (x) | 주어진 숫자에 대한 주요 요인 목록을 반환합니다 |
| findgcdof (x, y) | 주어진 숫자의 GCD를 반환합니다 |
| FindInvers.forr (ARR) | 배열이 정렬되는지 반환합니다 |
| catlan_numbers.getElement (x) | x'th catlan 번호를 반환합니다 |
| catlan_numbers.gen (x) | 첫 번째 x catlan_numbers 목록을 반환합니다 |
예:
import rapidkode as rk
var = rk . getprimefactors . fornum ( 6754 )
print ( var )
var = rk . findgcdof ( 97345435 , 8764897 )
print ( var )
var = rk . findinversions . forr ([ 1 , 20 , 6 , 4 , 5 ])
print ( var )
var = rk . catlan_numbers . getelement ( 15 )
print ( var )
var = rk . catlan_numbers . gen ( 28 )
print ( var )
산출:
[2, 11, 307.0]
1
5
9694845.0
[1.0, 1.0, 2.0, 5.0, 14.0, 42.0, 132.0, 429.0, 1430.0, 4862.0, 16796.0, 58786.0, 208012.0, 742900.0, 2674440.0, 9694845.0, 35357670.0, 129644790.0, 477638700.0, 1767263190.0, 6564120420.0, 24466267020.0, 91482563640.0, 343059613650.0, 1289904147324.0, 4861946401452.0, 18367353072152.0, 69533550916004.0]
Rapid Kode에 기여합니다
- 모든 기여, 버그 보고서, 버그 수정, 문서 개선, 개선 및 아이디어를 환영합니다.
- 문제를 발견하면 문제를 제기하십시오
- 기여를 원한다면 풀 요청을하기 전에 REPO를 포크로 만들면 관리가 쉽습니다.
- 로고 및 헤더 크레딧 -> M.Sri harsha해 bel
행복한 빠른 코딩 !!