본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 96

반응형

Q>

You have a device that uses a Seven-segment display to display 2 digit numbers.

(7 세그먼트 디스플레이를 사용하여 두 자리 숫자를 표시하는 장치가 있습니다.)

However, some of the segments aren't working and can't be displayed.

(그러나 일부 세그먼트가 작동하지 않아 표시 할 수 없습니다.)

You will be given information on the lit and broken segments.

(조명 및 깨진 세그먼트에 대한 정보가 제공됩니다.)

You won't know whether the broken segment is lit or not.

(깨진 세그먼트가 켜져 있는지 여부는 알 수 없습니다.)

You have to count and return the total number that the device may be displaying.

(디바이스가 표시 할 수있는 총 수를 세고 리턴해야합니다.)

The input is a set of lit segments (the first argument) and broken segments (the second argument).

(입력은 조명 세그먼트 (첫 번째 인수)와 깨진 세그먼트 (두 번째 인수)의 집합입니다.)

  • Uppercase letters represent the segments of the first out two digit number.
  • Lowercase letters represent the segments of the second out two digit number.
  • topmost: 'A(a)', top right: 'B(b)', bottom right: 'C(c)', bottommost: 'D(d)', bottom left: 'E(e)', top left: 'F(f)', middle: 'G(g)'

대문자는 처음 두 자리 숫자의 세그먼트를 나타냅니다.

소문자는 두 번째 숫자 두 번째 세그먼트를 나타냅니다.

위쪽 : 'A (a)', 오른쪽 위 : 'B (b)', 오른쪽 아래 : 'C (c)', 아래쪽 : 'D (d)', 왼쪽 아래 : 'E (e)', 왼쪽 위 : 'F (f)', 가운데 : 'G (g)'

 

 

Example:

seven_segment({'B', 'C', 'b', 'c'}, {'A'}) == 2    #11, 71
seven_segment({'B', 'C', 'a', 'c', 'd', 'f', 'g'}, {'A', 'D', 'G', 'e'}) == 6    #15, 16, 35, 36, 75, 76
seven_segment({'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f'}, {'G', 'g'}) == 4    #0, 8, 80, 88

 

Input: Two arguments.

         (두 가지 주장.)

         The first one contains the lit segments as a set of letters representing segments.

         (첫 번째 세그먼트는 세그먼트를 나타내는 문자 세트로 조명 세그먼트를 포함합니다.)

         The second one contains the broken segments as a set of letters representing segments.

         (두 번째 세그먼트는 세그먼트를 나타내는 문자 세트로 끊어진 세그먼트를 포함합니다.)

 

Output: The total number that the device may be displaying.

           (장치가 표시 할 수있는 총 숫자입니다.)

 

Precondition:

  • all(re.match('[A-Ga-g]', s) for s in lit | broken)
  • len(lit & broken) == 0

A>

# 1 ~ 0 set
segments = list(map(set, [
    'bc',       #1
    'abged',    #2
    'abgcd',    #3
    'fbgc',     #4
    'afgcd',    #5
    'afgcde',   #6
    'abc',      #7
    'abcdefg',  #8
    'abcdfg',   #9
    'abcdef'    #0
]))

# *args : *arguments / 여러개의 인자를 받을때 사용
def seven_segment(*args):
    def digit(n):
        lit, broken = ({s.lower() for s in segs if n(s)} for segs in args)
        return sum(lit <= s <= (broken | lit) for s in segments)
    # islower : 소문자 문자열을 감지
    # isupper : 대문자 문자열을 감지
    return digit(str.islower) * digit(str.isupper)

if __name__ == '__main__':
    assert seven_segment({'B', 'C', 'b', 'c'}, {'A'}) == 2, '11, 71'
    assert seven_segment({'B', 'C', 'a', 'f', 'g', 'c', 'd'}, {'A', 'G', 'D', 'e'}) == 6, '15, 16, 35, 36, 75, 76'
    assert seven_segment({'B', 'C', 'a', 'f', 'g', 'c', 'd'}, {'A', 'G', 'D', 'F', 'b', 'e'}) == 20, '15...98'
    print('"Run" is good. How is "Check"?')

 

O>

"Run" is good. How is "Check"?

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글