Skip to content

Commit

Permalink
색깔에 대한 통계 함수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sungsik819 committed Oct 5, 2024
1 parent 1c55b54 commit 7d57117
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lotto.edn

Large diffs are not rendered by default.

42 changes: 29 additions & 13 deletions src/lotto/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
;; 데이터 가공 하기
;; 가공된 데이터를 처리 하기

;; 색 정의
;; 1 ~ 10 : yellow
;; 11 ~ 20 : blue
;; 21 ~ 30 : red
;; 31 ~ 40 : gray
;; 41 ~ 45 : green

(defn get-data [round]
(let [data (json/read-str
(slurp
Expand Down Expand Up @@ -49,12 +56,23 @@
([]
(lotto-data file-data))
([file-data]
(map trans-data file-data)))
(map trans-data file-data))
([start end] ;; 범위에 있는 회차 가져오기
(->> (get-rounds start end)
(lotto-data))))

;; 범위의 숫자에 해당하는 값 리턴
;; 교체하는 로직만 있으면 될 것 같아서 데이터 구조는 없음
(defn get-color [n]
(cond
(contains? (set (range 1 11)) n) :yellow
(contains? (set (range 11 21)) n) :blue
(contains? (set (range 21 31)) n) :red
(contains? (set (range 31 41)) n) :gray
:else :green))

;; 범위에 있는 로또 데이터 가져오기
(defn get-ranges [start end]
(->> (get-rounds start end)
(lotto-data)))
;; 한줄을 색깔명으로 교체
(map get-color [2 10 12 15 22 44 1])


;; 위 데이터를 바탕으로 적게 나온 숫자 가져오기
Expand Down Expand Up @@ -103,14 +121,12 @@
([lotto-data]
(map #(digit-statistics % lotto-data) [first-d second-d third-d forth-d fifth-d sixth-d bonus-d])))


;; 테스트 용
(comment
(get-data 1140)

(spit "lotto2.edn" [(get-data 1138)])

(add-last-round))
;; 숫자를 색으로 교체
(defn lotto-colors
([]
(map #(map get-color %) (lotto-data)))
([start end]
(map #(map get-color %) (lotto-data start end))))

;; 위 함수를 만들기 위한 테스트
(comment
Expand Down
10 changes: 8 additions & 2 deletions src/lotto/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@
(lotto/statistics)

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

;; 전체 색 데이터가 나타난 횟수 확인
(lotto/group-by-number (mapcat identity (lotto/lotto-colors)))

;; 1~100회차에 대해 색이 나타난 횟수 확인
(lotto/group-by-number (mapcat identity (lotto/lotto-colors 1 100)))

0 comments on commit 7d57117

Please sign in to comment.