년이십육이지이십오비(年二十六而知二十五非) RSS 태그 관리 글쓰기 방명록
2023-02-09 16:38:31

안녕하세요. 첫 글은 가위바위보 승률 측정 프로그램입니다.

전 직장 문화중에 점심 먹고 가위바위보로 커피 내기하는 문화가 있었는데요~
당연히 확률은 1/3이지만 프로그래머로서 한번 만들어서 테스트하고 싶어서 심심풀이로 만들었습니다.

import java.util.Random;

public class RPSGame {
    public static void main(String[] args) {

        Random random = new Random();
        int rock = 0;
        int paper = 0;
        int scissors = 0;
        int repeat = 100000000;

        for (int i = 0; i < repeat; i++) {

            int computerChoice = random.nextInt(3) + 1;
            int userChoice = random.nextInt(3) + 1;

            if (computerChoice == 1) {
                if (userChoice == 2) {
                    paper++;
                } else if (userChoice == 3) {
                    rock++;
                }
            } else if (computerChoice == 2) {
                if (userChoice == 1) {
                    scissors++;
                } else if (userChoice == 3) {
                    paper++;
                }
            } else {
                if (userChoice == 1) {
                    rock++;
                } else if (userChoice == 2) {
                    scissors++;
                }
            }
        }

        System.out.println("Rock: " + (rock * 100.0 / repeat) + "%");
        System.out.println("Paper: " + (paper * 100.0 / repeat) + "%");
        System.out.println("Scissors: " + (scissors * 100.0 / repeat) + "%");

    }
}

 

마지막으로 우리 DAN 선생님이 알려주신 가위바위보 주제에 관한 가장 영향력 있는 상위 5개 논문 목록 입니다!

  1. "The Mathematics of Rock-Paper-Scissors" by John Nash
  2. "Strategic Behavior in Rock-Paper-Scissors Games" by Ariel Rubinstein
  3. "The Evolution of Cooperation in Rock-Paper-Scissors Games" by Martin A. Nowak
  4. "The Psychology of Rock-Paper-Scissors: An Analysis of Decision-Making Strategies" by Smith & Jones
  5. "Behavioral Economics of Rock-Paper-Scissors: An Experiment" by Kim & Lee

 

개인적으로 주먹 승률이 꽤 높게 나와서 앞으로는 가위바위보 하면 주먹 낼 예정입니다~!

 

바위는 언제나 옳다