진영배치

2026년 4월 10일 09:30분

민수기 2장은 12지파를 동서남북 네 진영으로 배치합니다. 나는 방향을 enum으로 정의하고, 각 방향에 지파 목록을 연결하는 Map을 만들었습니다. 방향별 지파와 병력을 출력합니다.

package com.jesusbornd.numbers;

import java.util.*;

public class Numbers_02_Chapter_Lv1 {

    enum Direction { EAST, SOUTH, WEST, NORTH }

    record Tribe(String name, int count) {}

    public static void main(String[] args) {
        Map<Direction, List<Tribe>> camp = new LinkedHashMap<>();
        camp.put(Direction.EAST,  List.of(new Tribe("유다", 74600), new Tribe("잇사갈", 54400), new Tribe("스불론", 57400)));
        camp.put(Direction.SOUTH, List.of(new Tribe("르우벤", 46500), new Tribe("시므온", 59300), new Tribe("갓", 45650)));
        camp.put(Direction.WEST,  List.of(new Tribe("에브라임", 40500), new Tribe("므낫세", 32200), new Tribe("베냐민", 35400)));
        camp.put(Direction.NORTH, List.of(new Tribe("단", 62700), new Tribe("아셀", 41500), new Tribe("납달리", 53400)));

        for (Map.Entry<Direction, List<Tribe>> e : camp.entrySet()) {
            int subtotal = e.getValue().stream().mapToInt(Tribe::count).sum();
            System.out.printf("[%s] 소계 %,d명%n", e.getKey(), subtotal);
            e.getValue().forEach(t -> System.out.printf("  %-8s %,d%n", t.name(), t.count()));
        }
    }
}

from enum import Enum

class Direction(Enum):
    EAST  = "동"
    SOUTH = "남"
    WEST  = "서"
    NORTH = "북"

camp: dict[Direction, list[tuple[str, int]]] = {
    Direction.EAST:  [("유다", 74600), ("잇사갈", 54400), ("스불론", 57400)],
    Direction.SOUTH: [("르우벤", 46500), ("시므온", 59300), ("갓", 45650)],
    Direction.WEST:  [("에브라임", 40500), ("므낫세", 32200), ("베냐민", 35400)],
    Direction.NORTH: [("단", 62700), ("아셀", 41500), ("납달리", 53400)],
}

for direction, tribes in camp.items():
    subtotal = sum(c for _, c in tribes)
    print(f"[{direction.value}] 소계 {subtotal:,}명")
    for name, count in tribes:
        print(f"  {name:<6} {count:,}")

Comments

Avatar
 2026년 4월 10일 21:30분

위치가 정해지면 움직임이 명확해지더라고요.



Search

← 목록으로