눈의백색
2014-12-21 03:11
조회: 171
추천: 0
코드import random import math def all_bingo( i ): total_ticket = 0 for j in range( 5 ): total_ticket += one_line_bingo( i ) # print( total_ticket ) return total_ticket def one_line_bingo( i ): # i : ( 서로 다른 숫자를 ) 랜덤으로 몇개까지 뽑을지 user_array = [] ticket = 0 while len( user_array ) < i: x = random.randrange( 1, 6 ) # 1 ~ 5 if ( x in user_array ) == False: user_array.append( x ) ticket += 1 ticket += ( 5 - i ) * 3 return ticket def statistics( time, i ): # only for statistics total = 0 max_t = 0 min_t = 100000000 fail = 0 temp_array = [] for j in range( time ): temp = all_bingo( i ) total += temp if temp > max_t: max_t = temp if temp < min_t: min_t = temp if temp > 70: fail += 1 temp_array.append( temp ) # only for standardDeviation # return total, max_t, min_t, standardDeviation( temp_array ) # print( 'ave : ' + str( total / time ) ) print( 'ave : ' + str( total / time ) + ' ( ' + str( min_t ) + ', ' + str( max_t ) + ', ' + str( fail ) + ' )' ) standardDeviation( temp_array ) # print( 'Ticket : ' + str( use_ticket_1 ) + ' + ' + str( use_ticket_3 ) + ' = ' + str( use_ticket_1 + use_ticket_3 ) ) # print( user_array ) # Standard Deviation def standardDeviation( values, option = 1 ): if len( values ) < 2: return None sd = 0.0 sum = 0.0 meanValue = mean( values ) for i in range( 0, len( values ) ): diff = values[ i ] - meanValue sum += diff * diff sd = math.sqrt( sum / ( len( values ) - option ) ) print( sd ) def mean( values ): if len( values ) == 0: return None return sum( values, 0.0 ) / len( values ) # end of Standard Deviation statistics( 1000000, 0 ) statistics( 1000000, 1 ) statistics( 1000000, 2 ) statistics( 1000000, 3 ) statistics( 1000000, 4 ) statistics( 1000000, 5 ) |
인벤 공식 앱
댓글 알람 기능 장착! 최신 게임뉴스를 한 눈에 보자