From ea290a061ef013f3f7276638f46dabdfe2c6c82d Mon Sep 17 00:00:00 2001 From: Yujin <78896558+Yujinmon@users.noreply.github.com> Date: Sat, 22 Jun 2024 15:48:38 +0900 Subject: [PATCH] Create 11729(Recursion).java --- .../11729(Recursion).java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "\354\225\210\354\234\240\354\247\204/11729(Recursion).java" 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; + } +} +