본문 바로가기
나는 이렇게 학습한다/Algorithm & SQL

0101. Pillars

by daco2020 2023. 1. 1.

There are pillars near the road. The distance between the pillars is the same and the width of the pillars is the same. Your function accepts three arguments:

  1. number of pillars (≥ 1);
  2. distance between pillars (10 - 30 meters);
  3. width of the pillar (10 - 50 centimeters).

Calculate the distance between the first and the last pillar in centimeters (without the width of the first and last pillar).



Solution:

def pillars(num_pill: int, dist: int, width: int) -> int:
    return 0 if num_pill == 1 else (num_pill - 1) * (dist * 100 + width) - width