<jupyter_start><jupyter_text>탐욕<jupyter_code>def greed():
    coin=int(input('거슬러줄 금액을 입력하세요:'))
    change=sorted(list(map(int,input('거슬러줄 동전을 입력하세요:').split(' '))),reverse=True)
    
    while coin!=0:
        for i in change:
            q=coin//i
            print(''.join(f'{i}원 {q}개'))
            coin-=q*i    
greed()<jupyter_output>거슬러줄 금액을 입력하세요:14
거슬러줄 동전을 입력하세요:10 7 1
10원 1개
7원 0개
1원 4개<jupyter_text>이진탐색<jupyter_code>def bi_search(a,n,cnt=0):
    """
    a=리스트
    n=찾고싶은 숫자
    """
    import numpy as np
    
    cnt+=1
    if len(a)==1:
        if a[0]==n:
            return f'{n}은 이진탐색 {cnt}번 만에 찾았습니다.'
        else:
            return f'{n}은 a 리스트에서 검색되지 않습니다.'
        
    a0=np.array(a)
    if np.median(a0)==n:        
        return f'{n}은 이진탐색 {cnt}번 만에 찾았습니다.'
    
    a_m=np.median(a0)
    if a_m > n:
        a=[i for i in a if i < a_m]
    else:
        a=[i for i in a if i > a_m]
           
    return bi_search(a, n, cnt)
        
a=[1,7,11,12,14,23,33,47,51,64,67,77,129,672,871]
bi_search(sorted(a),12)<jupyter_output><empty_output><jupyter_text>합성곱<jupyter_code>def convolution(A,f,stride=1):
    x=[]
    
    Ar, Ac=np.shape(A)
    fr, fc=np.shape(f)
    
    cntr=int((Ar-fr)/stride+1)
    cntc=int((Ac-fc)/stride+1)
    
    for i in range(cntr):
        for j in range(cntc):
            x.append(np.sum(A[i:fr+i,j:fc+j]*f))
    return np.array(x).reshape(cntr,cntc)

A=np.array([[1,2,3,0,6],[0,1,2,3,7],[3,0,1,2,8],[2,3,0,1,9],[5,6,8,7,3]])
A2=np.array([[1,2,3,0],[0,1,2,3],[3,0,1,2],[2,3,0,1]])
f=np.array([[2,0,1],[0,1,2],[1,0,2]])

print(convolution(A,f))
print(convolution(A2,f))<jupyter_output>[[15 16 46]
 [ 6 15 47]
 [31 24 43]]
[[15 16]
 [ 6 15]]<jupyter_text>삽입<jupyter_code>import random
import time
def insert_sort(a):
    """
    a=any kind of list
    """
    for i in range(1,len(a)):
        for j in range(i):
            if a[i]<a[j]:            
                a.insert(a.index(a[j]),a.pop(i))                
    return a

a=[5,4,3,2,1,8,9,10]
insert_sort(a)<jupyter_output><empty_output><jupyter_text>버블<jupyter_code>def bubble_sort(a):
    """
    a = list
    """
    n=len(a)
    for i in range(1,n-1):
        for j in range(n-i):
            if a[j]>a[j+1]:
                a[j],a[j+1]=a[j+1],a[j]
    return a
a=[5,102,99,56,75,1,8,9,18,20,46,47,98,86]                
bubble_sort(a)<jupyter_output><empty_output><jupyter_text>자카드 유사도<jupyter_code>def jacade(a, b):
    str1 = a.lower()
    str2 = b.lower()
    ls1 = []
    ls2 = []
    for i in range(len(str1)-1):
        if str1[i].isalpha() and str1[i+1].isalpha():
            ls1.append(str1[i:i+2])
    for i in range(len(str2)-1):
        if str2[i].isalpha() and str2[i+1].isalpha():
            ls2.append(str2[i:i+2])

    union = []
    inter = []
    rs = set(ls1+ls2)

    for i in rs:
        for _ in range(min(ls1.count(i), ls2.count(i))):
            inter.append(i)
        for _ in range(max(ls1.count(i), ls2.count(i))):
            union.append(i)

    if len(ls1) == 0 and len(ls2) == 0:
        return 65536
    else:
        return int(len(inter)/len(union)*65536)


print(jacade('FRANCE', 'french'))
print(jacade('handshake', 'shake hands'))
print(jacade('aa1+aa2', 'AAAA12'))
print(jacade('E=M*C^2', 'e=m*c^2'))<jupyter_output>16384
65536
43690
65536<jupyter_text>재귀<jupyter_code>def multi_table_2(n):
    if n==0:
        return
    else:
        print(f'2 x {10-n} = {2*(10-n)}')
        return multi_table_2(n-1)
multi_table_2(9)<jupyter_output>2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18<jupyter_text>LRU<jupyter_code>def cacheProcess(cities,size):
    """
    cities : list of cities
    size : cache size
    """
    cache=[]
    time=0
    for i in cities:
        if i.upper() in cache:
            time += 1            
            cache.append(cache.pop(cache.index(i.upper())))
#             print(cache,'1')
        else:
            if len(cache) == size and size != 0:
                cache.pop(0)
                time += 5
                cache.append(i.upper())
#                 print(cache,'2')
            elif size==0:
                time += 5
#                 print(cache,'0')
            else:
                time += 5
                cache.append(i.upper())
#                 print(cache,'3')
    else:
        return time
print(cacheProcess(['Jeju', 'Pangyo', 'Seoul', 'NewYork', 'LA', 'Jeju', 'Pangyo', 'Seoul', 'NewYork', 'LA'],3))
print(cacheProcess(['Jeju', 'Pangyo', 'Seoul', 'Jeju', 'Pangyo','Seoul', 'Jeju', 'Pangyo','Seoul'],3))
print(cacheProcess(['Jeju', 'Pangyo', 'Seoul', 'NewYork', 'LA', 'SanFrancisco', 'Seoul', 'Rome', 'Paris', 'Jeju', 'NewYork', 'Rome'],2))
print(cacheProcess(['Jeju', 'Pangyo', 'Seoul', 'NewYork', 'LA', 'SanFrancisco', 'Seoul', 'Rome', 'Paris', 'Jeju', 'NewYork', 'Rome'],5))
print(cacheProcess(['Jeju', 'Pangyo', 'NewYork', 'newyork'],2))
print(cacheProcess(['Jeju', 'Pangyo', 'Seoul', 'NewYork', 'LA'],0))
print(cacheProcess(['Jeju','Jeju','Jeju'],3))<jupyter_output>50
21
60
52
16
25
7<jupyter_text>버블재귀<jupyter_code>def bubble_sort(a, n=1, cnt=0, rs=[]):

    cnt = len(a)
    if len(a)==1:
        rs.insert(0, a[-1])
        return rs
    if a[n+1]:
        if a[n+1] < a[n]:
            a[n+1], a[n] = a[n], a[n+1]
        
    if a[len(a)-1] == max(a):
        rs.insert(0, a[-1])
        del a[-1]
    n += 1
    cnt += 1
    if len(a) == n:            
        n = 0

    return bubble_sort(a, n, cnt, rs)
    
a = [5, 4, 3, 9 ,2,321,564,789,9878,321865409,9876521321, 1, 8, 7, 10]
bubble_sort(a)
def test(a):
    b=[]
    b.insert(0,a.pop(0))
    return b, a
a=[1,2,3,4]
test(b)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19957761351636746, 'fraction_numerical': 0.0667018655403027, 'mean_word_length': 2.4715943799633475, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '251278', 'license': 'MIT', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2655, 'n_words': 455, 'path': 'test prep..ipynb', 'repo_name': 'Adrian123K/python_class', 'size': '5682'}