Description
3x villagers don't use multiples of 3 and numbers 3 because they think 3 is a curse number. The number of 3x villagers is here according to the following.
Decimal Sys | 3x viilagers | Deciaml System | 3x viilagers |
1 | 1 | 6 | 8 |
2 | 2 | 7 | 10 |
3 | 4 | 8 | 11 |
4 | 5 | 9 | 14 |
5 | 7 | 10 | 16 |
Given an integer n as a parameter, complete the solution function to return n by replacing it with the number used in the 3x village.
Restrictions
- 1 ≤ n ≤ 100
Example Input/Output
n | Results |
15 | 25 |
40 | 76 |
#1 Input
- Converting 15 to a number in a 3x village is 25.
#2 Input
- If you convert 40 to a number in a 3x village, it's 76.
def solution(n):
ans = 0
for i in range(n):
ans += 1
while ans % 3 == 0 or '3' in str(ans):
ans += 1
return ans
Discussion
You can repeat for statement by n, and find a rule that requires +1 once more for numbers that contain 3 or are multiples of 3.
A two-dimensional list can be created by putting a list in the list, and each list inside is separated by a comma.
>>> a = [[10, 20], [30, 40], [50, 60]]
>>> a
[[10, 20], [30, 40], [50, 60]]
When accessing or assigning values to elements in a two-dimensional list, use the list followed by [ ] twice and specify a row index and a column index within [].
>>> a = [[10, 20], [30, 40], [50, 60]]
>>> a[0] [0] # 세로 인덱스 0, 가로 인덱스 0인 요소 출력
10
>>> a[1][1] # 세로 인덱스 1, 가로 인덱스 1인 요소 출력
40
>>> a[2][1] # 세로 인덱스 2, 가로 인덱스 0인 요소 출력
60
>>> a[0][1] = 1000 # 세로 인덱스 0, 가로 인덱스 1인 요소에 값 할당
>>> a[0][1]
1000