Skip to content

Commit

Permalink
회차 범위 데이터 가져오는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sungsik819 committed Oct 4, 2024
1 parent e1b6f5d commit 1c55b54
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
44 changes: 32 additions & 12 deletions src/lotto/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,32 @@
;; (def remote-data (map #(get-data %) (range 1 (inc last-round))))

;; 파일에 있는 정보 읽기
(def file-data (read-string (slurp "lotto.edn")))
(def ^:private file-data (read-string (slurp "lotto.edn")))

;; 회차 데이터 가져오기
(def ^:private get-round #(nth file-data (dec %)))

;; 범위에 있는 데이터 가져오기
(defn ^:private get-rounds [start end]
(map get-round (range start (inc end))))

;; [1 2 3 4 5 6 보너스]의 형태로 변환
(defn trans-data [& coll]
(let [{:keys [drwtNo1 drwtNo2 drwtNo3 drwtNo4 drwtNo5 drwtNo6 bnusNo]} coll]
[drwtNo1 drwtNo2 drwtNo3 drwtNo4 drwtNo5 drwtNo6 bnusNo]))

;; 변환된 데이터
(def lotto-data (map #(trans-data %) file-data))
;; 로또 데이터로 변환
(defn lotto-data
([]
(lotto-data file-data))
([file-data]
(map trans-data file-data)))

;; 범위에 있는 로또 데이터 가져오기
(defn get-ranges [start end]
(->> (get-rounds start end)
(lotto-data)))


;; 위 데이터를 바탕으로 적게 나온 숫자 가져오기
;; [숫자 횟수] 형태로 바꾼다.
Expand Down Expand Up @@ -80,8 +97,11 @@
:unincluded (unincluded-numbers digit-data)}))

;; 자리에 대한 각각 통계 데이터
(defn statistics []
(map #(digit-statistics % lotto-data) [first-d second-d third-d forth-d fifth-d sixth-d bonus-d]))
(defn statistics
([]
(statistics lotto-data))
([lotto-data]
(map #(digit-statistics % lotto-data) [first-d second-d third-d forth-d fifth-d sixth-d bonus-d])))


;; 테스트 용
Expand All @@ -95,45 +115,45 @@
;; 위 함수를 만들기 위한 테스트
(comment
;; 첫째 자리수 가져오기
(def first-digit (map first lotto-data))
(def first-digit (map first (lotto-data)))
;; [숫자 횟수] 형태로 변환
(def first-number-counts (group-by-number first-digit))

;; 첫째 자리에서 안나온 숫자 확인
(unincluded-numbers first-digit)

;; 둘째 자리수 가져오기
(def second-digit (map second lotto-data))
(def second-digit (map second (lotto-data)))

;; 둘째 자리에서 안나온 숫자 확인
(unincluded-numbers second-digit)

;; 셋째 자리수 가져오기
(def third-digit (map third-d lotto-data))
(def third-digit (map third-d (lotto-data)))

;; 셋째 자리에서 안나온 숫자 확인
(unincluded-numbers third-digit)

;; 넷째 자리수 가져오기
(def forth-digit (map forth-d lotto-data))
(def forth-digit (map forth-d (lotto-data)))

;; 넷째 자리에서 안나온 숫자 확인
(unincluded-numbers forth-digit)

;; 다섯째 자리수 가져오기
(def fifth-digit (map fifth-d lotto-data))
(def fifth-digit (map fifth-d (lotto-data)))

;; 다섯째 자리에서 안나온 숫자 확인
(unincluded-numbers fifth-digit)

;; 여섯째 자리수 가져오기
(def sixth-digit (map sixth-d lotto-data))
(def sixth-digit (map sixth-d (lotto-data)))

;; 여섯째 자리에서 안나온 숫자 확인
(unincluded-numbers sixth-digit)

;; 보너스 숫자만 가져오기
(def bonus-digit (map bonus-d lotto-data))
(def bonus-digit (map bonus-d (lotto-data)))

;; 보너스 자리에서 안나온 숫자 확인 - 없음
(unincluded-numbers bonus-digit))
14 changes: 9 additions & 5 deletions src/lotto/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(lotto/add-last-round)

;; 전체 자리수에 있는 숫자의 횟수 계산
(def all-number-counts (lotto/group-by-number (mapcat identity lotto/lotto-data)))
(def all-number-counts (lotto/group-by-number (mapcat identity (lotto/lotto-data))))

;; 숫자가 적게 나온 번호 순으로
(def min-numbers (lotto/sort-asc all-number-counts))
Expand All @@ -16,14 +16,18 @@

;; 숫자가 적게 나온 로또 번호 가져오기(보너스 번호 포함)
;; [1 2 3 4 5 6 보너스]
(map first (sort (take 7 min-numbers)))
(lotto/get-numbers 7 min-numbers)

;; 숫자가 많이 나온 로또 번호 가져오기(보너스 번호 포함)
;; [1 2 3 4 5 6 보너스]
(map first (sort (take 7 max-numbers)))
(lotto/get-numbers 7 max-numbers)


;; 마지막 10개 회차만 보기
(drop 1130 lotto/lotto-data)
(drop 1130 (lotto/lotto-data))

(lotto/statistics)
(lotto/statistics)

;; 1 ~ 100까지 회차에서의 통계 보기
(->> (lotto/get-ranges 1 100)
(lotto/statistics))

0 comments on commit 1c55b54

Please sign in to comment.