'2021/06'에 해당되는 글 2건

  1. 2021.06.21 생일 문제
  2. 2021.06.08 별 그리기
Coding/Python 삽질기2021. 6. 21. 23:46

기차표 예매를 위하여 줄을 섰을 때, 이들 중 생일이 같은 사람이 존재 할 확률은 얼마일까?

계산을 해보면, 23명 이상 일 때 부터 50%가 넘어가고, 57명이 넘어가면 99%가 넘어간다.

 

 

파이썬으로 짜보면 아래와 같다.

import matplotlib.pyplot as plt

prev = 1
result = [0]
for m in range(57):
    prev = prev * (365-m)/365
    result.append(1-prev)

x = [ n for n in range(len(result))]

plt.scatter(x, result)
plt.axvline(x=23, color='RED', linestyle='-', linewidth=0.2)
plt.axhline(y=0.5, color='RED', linestyle='-', linewidth=0.2)
plt.show()

Posted by chobocho
Coding/CPP 삽질기2021. 6. 8. 22:21

오픈 챗에서 누구나 다 해보는 "별 그리기" 문제를 물어 보길래, 한 번 짜봤다.

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv) {
    char star[] = "*****";

    for (int i = 0; i < strlen(star); i++) {
         printf("%s\n", &star[strlen(star)-i-1]);
    }

    return 0;
}

 

chobocho@Chobocho-Mint:~/github/cpp_study/src/sandbox$ ./a.out
*
**
***
****
*****

'Coding > CPP 삽질기' 카테고리의 다른 글

[ChatGPT에게 묻다] Fast sqrt 함수  (0) 2023.02.26
Stack과 Heap  (0) 2021.02.25
[C] Binary search  (0) 2020.12.06
Posted by chobocho