백준 11829번 파이썬
1. 문제 2. 설명 알고리즘) n개의 원판이 있을때, n - 1개의 원판 즉, 맨 밑의 원판을 제외하고 나머지 원판들을 1번에서 2번으로 옮긴다. -> hanoi(n-1, a, c, b) 맨 밑의 원판을 1번에서 3번으로 옮긴다. -> print(a, c) 그리고 n - 1개의 원판들을 다시 2번에서 3번으로 옮긴다. -> hanoi(n-1, b, a, c) 최소한의 이동 값 규칙) n = 1일 때 1, n = 2일 때 3, n = 3일 때 7, n=4일 때 15 이므로 (2^n - 1)이라는 식이 나온다. 3. 코드 n = int(input()) def hanoi(n, a, b, c): if n == 1: print(a, c) else: hanoi(n-1, a, c, b) print(a, c) han..
[js] for Each & Map
for Each 아무 값도 반환하지 않음. 기존 배열 변경 가능 const arr = [1, 2, 3] aarrrray.forEach((item, index) => { arr[index] = item * 2 }) console.log(arr)// [2, 4, 6] 1. value, index를 인자로 받기 item, index 순 const arr = ['apple', 'kiwi', 'grape', 'orange']; arr.forEach((item, index) => { console.log("index: " + index + ", item: " + item); }); //출력 결과 index: 0, item: apple index: 1, item: kiwi index: 2, item: grape in..