Fix formatting in Juggler Sequence (#2846)
This commit is contained in:
parent
2954ed2ab1
commit
b870de4db4
@ -195,6 +195,7 @@
|
|||||||
* [AutomorphicNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java)
|
* [AutomorphicNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java)
|
||||||
* [Average](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Average.java)
|
* [Average](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Average.java)
|
||||||
* [BinaryPow](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/BinaryPow.java)
|
* [BinaryPow](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/BinaryPow.java)
|
||||||
|
* [BinomialCoefficient](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/BinomialCoefficient.java)
|
||||||
* [Ceil](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Ceil.java)
|
* [Ceil](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Ceil.java)
|
||||||
* [CircularConvolutionFFT](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java)
|
* [CircularConvolutionFFT](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/CircularConvolutionFFT.java)
|
||||||
* [Combinations](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Combinations.java)
|
* [Combinations](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Combinations.java)
|
||||||
@ -220,6 +221,7 @@
|
|||||||
* [GCDRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/GCDRecursion.java)
|
* [GCDRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/GCDRecursion.java)
|
||||||
* [GenericRoot](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/GenericRoot.java)
|
* [GenericRoot](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/GenericRoot.java)
|
||||||
* [HarshadNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/HarshadNumber.java)
|
* [HarshadNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/HarshadNumber.java)
|
||||||
|
* [JugglerSequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/JugglerSequence.java)
|
||||||
* [KeithNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/KeithNumber.java)
|
* [KeithNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/KeithNumber.java)
|
||||||
* [KrishnamurthyNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/KrishnamurthyNumber.java)
|
* [KrishnamurthyNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/KrishnamurthyNumber.java)
|
||||||
* [LeonardoNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LeonardoNumber.java)
|
* [LeonardoNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LeonardoNumber.java)
|
||||||
@ -289,6 +291,7 @@
|
|||||||
* [FirstFit](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/FirstFit.java)
|
* [FirstFit](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/FirstFit.java)
|
||||||
* [FloydTriangle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/FloydTriangle.java)
|
* [FloydTriangle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/FloydTriangle.java)
|
||||||
* [GuassLegendre](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/GuassLegendre.java)
|
* [GuassLegendre](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/GuassLegendre.java)
|
||||||
|
* [HappyNumbersSeq](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/HappyNumbersSeq.java)
|
||||||
* [Huffman](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Huffman.java)
|
* [Huffman](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Huffman.java)
|
||||||
* [Implementing auto completing features using trie](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Implementing_auto_completing_features_using_trie.java)
|
* [Implementing auto completing features using trie](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Implementing_auto_completing_features_using_trie.java)
|
||||||
* [InsertDeleteInArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/InsertDeleteInArray.java)
|
* [InsertDeleteInArray](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/InsertDeleteInArray.java)
|
||||||
@ -334,6 +337,7 @@
|
|||||||
* [IterativeTernarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/IterativeTernarySearch.java)
|
* [IterativeTernarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/IterativeTernarySearch.java)
|
||||||
* [JumpSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/JumpSearch.java)
|
* [JumpSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/JumpSearch.java)
|
||||||
* [LinearSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LinearSearch.java)
|
* [LinearSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LinearSearch.java)
|
||||||
|
* [LinearSearchThread](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LinearSearchThread.java)
|
||||||
* [LowerBound](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LowerBound.java)
|
* [LowerBound](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/LowerBound.java)
|
||||||
* [MonteCarloTreeSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/MonteCarloTreeSearch.java)
|
* [MonteCarloTreeSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/MonteCarloTreeSearch.java)
|
||||||
* [PerfectBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/PerfectBinarySearch.java)
|
* [PerfectBinarySearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/PerfectBinarySearch.java)
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.thealgorithms.maths;
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Java program for printing juggler sequence
|
* Java program for printing juggler sequence
|
||||||
* Wikipedia: https://en.wikipedia.org/wiki/Juggler_sequence
|
* Wikipedia: https://en.wikipedia.org/wiki/Juggler_sequence
|
||||||
@ -9,56 +12,40 @@ package com.thealgorithms.maths;
|
|||||||
* */
|
* */
|
||||||
|
|
||||||
public class JugglerSequence {
|
public class JugglerSequence {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method prints juggler sequence starting with the number in the parameter
|
* This method prints juggler sequence starting with the number in the parameter
|
||||||
*
|
*
|
||||||
* @param inputNumber Number from which juggler sequence is to be started
|
* @param inputNumber Number from which juggler sequence is to be started
|
||||||
* */
|
*/
|
||||||
static void jugglerSequence(int inputNumber) {
|
public static void jugglerSequence(int inputNumber) {
|
||||||
//Copy method argument to a local variable
|
// Copy method argument to a local variable
|
||||||
int n = inputNumber;
|
int n = inputNumber;
|
||||||
|
List<String> seq = new ArrayList<>();
|
||||||
//Printing first number
|
seq.add(n + "");
|
||||||
System.out.print(n+",");
|
// Looping till n reaches 1
|
||||||
|
while (n != 1) {
|
||||||
//Looping till n reaches 1
|
int temp;
|
||||||
while(n != 1) {
|
// if previous term is even then
|
||||||
int temp=0;
|
|
||||||
|
|
||||||
//if previous term is even then
|
|
||||||
// next term in the sequence is square root of previous term
|
// next term in the sequence is square root of previous term
|
||||||
//if previous term is odd then
|
// if previous term is odd then
|
||||||
// next term is floor value of 3 time the square root of previous term
|
// next term is floor value of 3 time the square root of previous term
|
||||||
|
|
||||||
//Check if previous term is even or odd
|
// Check if previous term is even or odd
|
||||||
if(n%2 == 0) {
|
if (n % 2 == 0) {
|
||||||
temp = (int) Math.floor(Math.sqrt(n));
|
temp = (int) Math.floor(Math.sqrt(n));
|
||||||
|
} else {
|
||||||
|
temp = (int) Math.floor(Math.sqrt(n) * Math.sqrt(n) * Math.sqrt(n));
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
temp = (int) Math.floor(Math.sqrt(n)*Math.sqrt(n)*Math.sqrt(n));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Printing next term
|
|
||||||
if(temp != 1) {
|
|
||||||
System.out.print(temp+",");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
System.out.print(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
n = temp;
|
n = temp;
|
||||||
|
seq.add(n + "");
|
||||||
|
}
|
||||||
|
String res = String.join(",", seq);
|
||||||
|
System.out.println(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
// Driver code
|
||||||
|
|
||||||
//Driver code
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
jugglerSequence(3);
|
jugglerSequence(3);
|
||||||
|
// Output: 3,5,11,36,6,2,1
|
||||||
//Output: 3,5,11,36,6,2,1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user