Skip to content

Commit

Permalink
Create 11729(Recursion).java
Browse files Browse the repository at this point in the history
  • Loading branch information
Yujinmon authored Jun 22, 2024
1 parent bcdf5b6 commit ea290a0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 안유진/11729(Recursion).java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.util.*;
import java.io.*;

public class Main {
static int N;
static ArrayList<Pair> arrayList;
public static void move(int current, int source, int dest, int aux) {
if(current == 1) {
arrayList.add(new Pair(source, dest));
}else{
move(current - 1, source, aux, dest);
arrayList.add(new Pair(source, dest));
move(current - 1, aux, dest, source);
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

N = Integer.parseInt(br.readLine());
arrayList = new ArrayList<>();

move(N, 1, 3, 2);

System.out.println(arrayList.size());

StringBuilder sb = new StringBuilder();
for(Pair p : arrayList) {
sb.append(p.from).append(" ");
sb.append(p.to).append('\n');
}

System.out.println(sb);
}
}

class Pair{
int from;
int to;
Pair(int f, int t) {
from = f;
to = t;
}
}

0 comments on commit ea290a0

Please sign in to comment.