Skip to content

Commit

Permalink
Weird Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
noahmarro committed Feb 12, 2024
1 parent 912e470 commit bd2795d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions introductoryProblems/WeirdAlgorithm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Scanner;

public class WeirdAlgorithm {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
long n = input.nextInt();
input.close();
wa(n);
}

private static void wa(long n) {
System.out.print(n + " ");
if (n > 1) {
if (n % 2 == 0) {
wa(n / 2);
} else {
wa(n * 3 + 1);
}
}
}
}

0 comments on commit bd2795d

Please sign in to comment.