diff --git "a/\354\225\210\354\234\240\354\247\204/11729(Recursion).java" "b/\354\225\210\354\234\240\354\247\204/11729(Recursion).java" new file mode 100644 index 00000000..c75c2f8c --- /dev/null +++ "b/\354\225\210\354\234\240\354\247\204/11729(Recursion).java" @@ -0,0 +1,44 @@ +import java.util.*; +import java.io.*; + +public class Main { + static int N; + static ArrayList 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; + } +} +