Download benchmarks/quixbugs/java/HANOI.java from SevdanurGenc/LLM-Automated-Test-Generation-Agent: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/quixbugs/java/HANOI.java
- Command line
-
hf download hf://SevdanurGenc/LLM-Automated-Test-Generation-Agent/benchmarks/quixbugs/java/HANOI.java
-
curl -L -o HANOI.java https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/quixbugs/java/HANOI.java
2.42 kB
| import java.util.*; | |
| /** | |
| * Towers of Hanoi | |
| * hanoi | |
| * | |
| * | |
| * An algorithm for solving the Towers of Hanoi puzzle. Three pegs exist, with a stack of differently-sized | |
| * disks beginning on one peg, ordered from smallest on top to largest on bottom. The goal is to move the | |
| * entire stack to a different peg via a series of steps. Each step must move a single disk from one peg to | |
| * another. At no point may a disk be placed on top of another smaller disk. | |
| * | |
| * Input: | |
| * height: The height of the initial stack of disks. | |
| * start: The numbered peg where the initial stack resides. | |
| * end: The numbered peg which the stack must be moved onto. | |
| * | |
| * Preconditions: | |
| * height >= 0 | |
| * start in (1, 2, 3) | |
| * end in (1, 2, 3) | |
| * | |
| * Output: | |
| * An ordered list of pairs (a, b) representing the shortest series of steps (each step moving | |
| * the top disk from peg a to peg b) that solves the puzzle. | |
| * | |
| * @author derricklin | |
| */ | |
| public class HANOI { | |
| // default start=1, end=3 | |
| public static List<Pair<Integer,Integer>> hanoi(int height, int start, int end) { | |
| ArrayList<Pair<Integer,Integer>> steps = new ArrayList<Pair<Integer,Integer>>(); | |
| if (height > 0) { | |
| PriorityQueue<Integer> crap_set = new PriorityQueue<Integer>(); | |
| crap_set.add(1); | |
| crap_set.add(2); | |
| crap_set.add(3); | |
| crap_set.remove(start); | |
| crap_set.remove(end); | |
| int helper = crap_set.poll(); | |
| steps.addAll(hanoi(height-1, start, helper)); | |
| steps.add(new Pair<Integer,Integer>(start, end)); | |
| steps.addAll(hanoi(height-1, helper, end)); | |
| } | |
| return steps; | |
| } | |
| public static class Pair<F, S> { | |
| private F first; //first member of pair | |
| private S second; //second member of pair | |
| public Pair(F first, S second) { | |
| this.first = first; | |
| this.second = second; | |
| } | |
| public void setFirst(F first) { | |
| this.first = first; | |
| } | |
| public void setSecond(S second) { | |
| this.second = second; | |
| } | |
| public F getFirst() { | |
| return first; | |
| } | |
| public S getSecond() { | |
| return second; | |
| } | |
| public String toString() { | |
| return "(" + String.valueOf(first) + ", " + String.valueOf(second) + ")"; | |
| } | |
| } | |
| } | |