-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
65 lines (55 loc) · 1.91 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>로또번호 추첨기</title>
<style>
#NUMBERS { margin-top: 40vh; font-size: 5em; color: #fff; text-align: center; }
b{ display: inline-block; width: 128px; height: 128px; line-height: 128px; border-radius: 64px; margin: 16px; background: #999; }
</style>
</head>
<body>
<div id="NUMBERS"><div>
<script>
function genNumbers(){
var lottoNumbers = [];
while (lottoNumbers.length<6) {
var no = Math.round(Math.random()*45)+1;
if( lottoNumbers.indexOf(no) === -1 ) lottoNumbers.push(no);
}
return lottoNumbers;
}
function checkLogic1(numbers){
for(var i=0; i<numbers.length; i++){
var no = numbers[i];
if( numbers.indexOf(no+1)>=0 && numbers.indexOf(no+2)>=0 ) return true;
}
return false;
}
function checkLogic2(numbers){
// TODO feature/checkLogic2
var decArea = [0, 0, 0, 0, 0];
for(var i=0; i<numbers.length; i++){
var area = Math.floor( numbers[i]/10 );
decArea[area]++;
}
return ( decArea[0]>2 || decArea[1]>2 || decArea[2]>2 || decArea[3]>2 || decArea[4]>2 );
}
window.onload = function(){
var lottoNumbers = genNumbers();
// 23,24,25 과 간이 연속으로 3개의 숫자가 나오지 않게 하자!
while( checkLogic1(lottoNumbers) ) lottoNumbers=genNumbers();
// 11,15,17 과 같이 같은 10의 자리수에 3개가 나오지 않게 하자!
while( checkLogic2(lottoNumbers) ) lottoNumbers=genNumbers();
document.getElementById("NUMBERS").innerHTML = lottoNumbers.join(" ");
var html_lotto = "";
for(var i=0; i<lottoNumbers.length; i++){
html_lotto += '<b>'+ lottoNumbers[i] +'</b> ';
}
document.getElementById("NUMBERS").innerHTML = html_lotto;
}
</script>
</body>
</html>