골리앗전

2026년 9월 16일 09:30분

사무엘상 17장에서 다윗은 물맷돌 하나로 거인 골리앗을 쓰러뜨립니다. 작은 도구가 정확하면 큰 위협도 제거됩니다. 나는 비대칭 전투 로직을 구현했습니다.

package com.jesusbornd.samuel1;

public class Samuel1_17_Chapter_Lv2 {
    record Warrior(String name, int power, int accuracy) {}
    static String battle(Warrior a, Warrior b) {
        int scoreA = a.power() * a.accuracy();
        int scoreB = b.power() * b.accuracy();
        return (scoreA >= scoreB ? a : b).name() + " 승리";
    }
    public static void main(String[] args) {
        var david   = new Warrior("다윗",   5, 100);
        var goliath = new Warrior("골리앗", 90, 20);
        System.out.printf("다윗 점수: %d vs 골리앗 점수: %d%n",
            david.power()*david.accuracy(), goliath.power()*goliath.accuracy());
        System.out.println("결과: " + battle(david, goliath));
    }
}

def battle(a: tuple, b: tuple) -> str:
    score_a, score_b = a[1] * a[2], b[1] * b[2]
    print(f"{a[0]} 점수: {score_a} vs {b[0]} 점수: {score_b}")
    return (a if score_a >= score_b else b)[0] + " 승리"

print("결과:", battle(("다윗", 5, 100), ("골리앗", 90, 20)))

Comments

Avatar
 2026년 9월 16일 11:35분

정확한 한 발이 천 개의 칼보다 강합니다.



Search

← 목록으로