Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- Python
- 현대
- GAN
- 탐욕법
- 토이프로젝트
- 딥러닝
- heapq
- 자바
- programmers
- cim
- 스마트팩토리
- 파이썬
- 백준
- 프로그래머스
- 티스토리챌린지
- boj
- 힙큐
- Baekjoon
- 오블완
- 자바스크립트
- Java
- alogorithm
- re_lunchu
- Algorithm
- 알고리즘
- softeer
- JavaScript
- 소프티어
- cs공부
- 현대자동차
Archives
- Today
- Total
eaz_coding
[Programmers] 하노이의 탑(Python, Javascript) 본문
문제
https://school.programmers.co.kr/learn/courses/30/lessons/12946
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
Python
def solution(n):
answer = []
def hanoi(k, fr, to, ot):
nonlocal answer
if k == 1:
answer.append([fr, to])
return
hanoi(k-1, fr, ot, to)
answer.append([fr, to])
hanoi(k-1, ot, to, fr)
hanoi(n, 1, 3, 2)
return answer
Javascript
let answer;
function hanoi(k, fr, to, ot){
if (k == 1){
answer.push([fr, to]);
return;
}
hanoi(k-1, fr, ot, to);
answer.push([fr, to]);
hanoi(k-1, ot, to, fr);
}
function solution(n) {
answer = [];
hanoi(n, 1, 3, 2);
return answer;
}'eaz_algorithm' 카테고리의 다른 글
| [Programmers] 우박수열 정적분(Python, Javascript) (0) | 2024.06.26 |
|---|---|
| [Programmers] 문자열 압축(Python, Javascript) (0) | 2024.06.25 |
| [Programmers] 리코쳇 로봇(Python, Javascript) (1) | 2024.06.18 |
| [Programmers] 테이블 해시 함수(Python, Javascript) (0) | 2024.06.17 |
| [Programmers] 미로 탈출(Python, Javascript, Java) (0) | 2024.06.10 |