codeparrot/xlcost-text-to-code huggingface dataset:
Check if a number is Flavius Number | Java implementation of the above approach ; Return the number is Flavious Number or not ; index i starts from 2 because at 1 st iteration every 2 nd element was remove and keep going for k - th iteration ; removing the elements which are already removed at kth iteration ; Driver Code
class GFG { static boolean Survives ( int n ) { for ( int i = 2 ; ; i ++ ) { if ( i > n ) return true ; if ( n % i == 0 ) return false ; n -= n / i ; } } public static void main ( String [ ] args ) { int n = 17 ; if ( Survives ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Nth XOR Fibonacci number | Java implementation of the above approach ; Function to return the nth XOR Fibonacci number ; Driver code
class GFG { static int nthXorFib ( int n , int a , int b ) { if ( n == 0 ) return a ; if ( n == 1 ) return b ; if ( n == 2 ) return ( a ^ b ) ; return nthXorFib ( n % 3 , a , b ) ; } public static void main ( String [ ] args ) { int a = 1 , b = 2 , n = 10 ; System . out . println ( nthXorFib ( n , a , b ) ) ; } }
Sand Timer Flip Counting Problem | Java implementation of the approach ; Recursive function to return the gcd of a and b ; Everything divides 0 ; Function to print the number of flips for both the sand timers ; Driver code
class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void flip ( int a , int b ) { int lcm = ( a * b ) / gcd ( a , b ) ; a = lcm / a ; b = lcm / b ; System . out . print ( ( a - 1 ) + " ▁ " + ( b - 1 ) ) ; } public static void main ( String [ ] args ) { int a = 10 ; int b = 5 ; flip ( a , b ) ; } }
Sum of N terms in the expansion of Arcsin ( x ) | Java implementation of the approach ; Function to find the arcsin ( x ) ; The power to which ' x ' is raised ; Numerator value ; Denominator value ; Driver code
import java . io . * ; class GFG { static void find_Solution ( double x , int n ) { double sum = x , e = 2 , o = 1 , p = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { p += 2 ; sum += ( double ) ( o / e ) * ( double ) ( Math . pow ( x , p ) / p ) ; o = o * ( o + 2 ) ; e = e * ( e + 2 ) ; } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { double x = - 0.5 ; if ( Math . abs ( x ) >= 1 ) { System . out . println ( " Invalid ▁ Input " ) ; } int n = 8 ; find_Solution ( x , n ) ; } }
Minimize the cost of buying the Objects | Java implementation of the approach ; Function that will calculate the price ; Calculate the number of items we can get for free ; Calculate the number of items we will have to pay the price for ; Calculate the price ; Driver code ; Calling function
class GFG { static int totalPay ( int totalItems , int priceOfOneItem , int N , int M ) { int freeItems = 0 , actual = 0 ; freeItems = totalItems / ( N + M ) ; actual = totalItems - freeItems ; int amount = actual * priceOfOneItem ; return amount ; } public static void main ( String [ ] args ) { int T = 12 , P = 8 ; int N = 2 , M = 1 ; System . out . print ( " Amount ▁ = ▁ " + totalPay ( T , P , N , M ) ) ; } }
Count of all possible pairs of disjoint subsets of integers from 1 to N | Java implementation of the approach ; Modulo exponentiation function ; Function to calculate ( x ^ y ) % p in O ( log ( y ) ) ; Driver Code ; Evaluating ( ( 3 ^ n - 2 ^ ( n + 1 ) + 1 ) / 2 ) % p ; From Fermats 's little theorem  a^-1 ? a^(m-2) (mod m)
class GFG { static int p = 1000000007 ; static long power ( long x , long y ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res % p ; } public static void main ( String [ ] args ) { long n = 3 ; long x = ( power ( 3 , n ) % p + 1 ) % p ; x = ( x - power ( 2 , n + 1 ) + p ) % p ; x = ( x * power ( 2 , p - 2 ) ) % p ; System . out . println ( x ) ; } }
Right most non | Java implementation of the approach ; Function to return the rightmost non - zero digit in the multiplication of the array elements ; To store the count of times 5 can divide the array elements ; Divide the array elements by 5 as much as possible ; increase count of 5 ; Divide the array elements by 2 as much as possible ; Decrease count of 5 , because a '2' and a '5' makes a number with last digit '0' ; If c5 is more than the multiplier should be taken as 5 ; Driver code
import java . util . * ; class GFG { static int rightmostNonZero ( int a [ ] , int n ) { int c5 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( a [ i ] > 0 && a [ i ] % 5 == 0 ) { a [ i ] /= 5 ; c5 ++ ; } } for ( int i = 0 ; i < n ; i ++ ) { while ( c5 != 0 && a [ i ] > 0 && ( a [ i ] & 1 ) == 0 ) { a [ i ] >>= 1 ; c5 -- ; } } int ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { ans = ( ans * a [ i ] % 10 ) % 10 ; } if ( c5 != 0 ) ans = ( ans * 5 ) % 10 ; if ( ans != 0 ) return ans ; return - 1 ; } public static void main ( String args [ ] ) { int a [ ] = { 7 , 42 , 11 , 64 } ; int n = a . length ; System . out . println ( rightmostNonZero ( a , n ) ) ; } }
Find the remainder when First digit of a number is divided by its Last digit | Java program to find the remainder when the First digit of a number is divided by its Last digit ; Function to find the remainder ; Get the last digit ; Get the first digit ; Compute the remainder ; Driver code
class GFG { static void findRemainder ( int n ) { int l = n % 10 ; while ( n >= 10 ) n /= 10 ; int f = n ; int remainder = f % l ; System . out . println ( remainder ) ; } public static void main ( String [ ] args ) { int n = 5223 ; findRemainder ( n ) ; } }
Percentage increase in the volume of cuboid if length , breadth and height are increased by fixed percentages | Java implementation of the approach ; Function to return the percentage increase in the volume of the cuboid ; Driver code
class GFG { static double increaseInVol ( double l , double b , double h ) { double percentInc = ( 1 + ( l / 100 ) ) * ( 1 + ( b / 100 ) ) * ( 1 + ( h / 100 ) ) ; percentInc -= 1 ; percentInc *= 100 ; return percentInc ; } public static void main ( String [ ] args ) { double l = 50 , b = 20 , h = 10 ; System . out . println ( increaseInVol ( l , b , h ) + " % " ) ; } }
Count the number of occurrences of a particular digit in a number | Java program to count the number of occurrences of a particular digit in a number ; Function to count the occurrences of the digit D in N ; Loop to find the digits of N ; check if the digit is D ; return the count of the occurrences of D in N ; Driver code
import java . util . * ; class GFG { static int countOccurrances ( int n , int d ) { int count = 0 ; while ( n > 0 ) { count = ( n % 10 == d ) ? count + 1 : count ; n = n / 10 ; } return count ; } public static void main ( String args [ ] ) { int d = 2 ; int n = 214215421 ; System . out . println ( countOccurrances ( n , d ) ) ; } }
Find number of factors of N when location of its two factors whose product is N is given | Java program to implement the above problem ; Function to find the number of factors ; print the number of factors ; Driver code ; initialize the factors position
class GFG { static void findFactors ( int a , int b ) { int c ; c = a + b - 1 ; System . out . print ( c ) ; } public static void main ( String [ ] args ) { int a , b ; a = 13 ; b = 36 ; findFactors ( a , b ) ; } }
21 Matchsticks Problem | Java implementation of the approach ; Function to return the optimal strategy ; Removing matchsticks in blocks of five ; Driver code
class GFG { static void TwentyoneMatchstick ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i += 1 ) { System . out . print ( 5 - arr [ i ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 2 , 2 } ; int N = arr . length ; TwentyoneMatchstick ( arr , N ) ; } }
Find the smallest positive number which can not be represented by given digits | Java program to find the smallest positive number which can not be represented by given digits ; Function to find the smallest positive number which can not be represented by given digits ; Storing the count of 0 digit or store the value at 0 th index ; Calculates the min value in the array starting from 1 st index and also store it index . ; If its value at 0 th index is less than min value than either 10 , 100 , 1000 ... can 't be expressed ; If it value is greater than min value than iterate the loop upto first min value index and simply print it index value . ; Driver code ; Value of N is always 10 as we take digit from 0 to 9 ; Calling function
import java . util . * ; class GFG { static void expressDigit ( int arr [ ] , int n ) { int min = 9 , index = 0 , temp = 0 ; temp = arr [ 0 ] ; for ( int i = 1 ; i < 10 ; i ++ ) { if ( arr [ i ] < min ) { min = arr [ i ] ; index = i ; } } if ( temp < min ) { System . out . print ( 1 ) ; for ( int i = 1 ; i <= temp + 1 ; i ++ ) System . out . print ( 0 ) ; } else { for ( int i = 0 ; i < min ; i ++ ) System . out . print ( index ) ; System . out . print ( index ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 1 , 2 , 1 , 1 , 3 , 1 , 1 , 1 } ; int N = 10 ; expressDigit ( arr , N ) ; } }
Find the average of k digits from the beginning and l digits from the end of the given number | Java implementation of the approach ; Function to return the count of digits in num ; Function to return the sum of first n digits of num ; Remove the unnecessary digits ; Function to return the sum of the last n digits of num ; If the average can 't be calculated without  using the same digit more than once ; Sum of the last l digits of n ; Sum of the first k digits of n ( totalDigits - k ) must be removed from the end of the number to get the remaining k digits from the beginning ; Return the average ; Driver code
class GFG { public static int countDigits ( int num ) { int cnt = 0 ; while ( num > 0 ) { cnt ++ ; num /= 10 ; } return cnt ; } public static int sumFromStart ( int num , int n , int rem ) { num /= ( ( int ) Math . pow ( 10 , rem ) ) ; int sum = 0 ; while ( num > 0 ) { sum += ( num % 10 ) ; num /= 10 ; } return sum ; } public static int sumFromEnd ( int num , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += ( num % 10 ) ; num /= 10 ; } return sum ; } public static float getAverage ( int n , int k , int l ) { int totalDigits = countDigits ( n ) ; if ( totalDigits < ( k + l ) ) return - 1 ; int sum1 = sumFromEnd ( n , l ) ; int sum2 = sumFromStart ( n , k , totalDigits - k ) ; return ( ( float ) ( sum1 + sum2 ) / ( float ) ( k + l ) ) ; } public static void main ( String args [ ] ) { int n = 123456 , k = 2 , l = 3 ; System . out . print ( getAverage ( n , k , l ) ) ; } }
Print N terms of Withoff Sequence | Java program to find Wythoff array ; Function to find the n , k term of Wythoff array ; tau = ( sqrt ( 5 ) + 1 ) / 2 ; Already_stored ; T ( n , - 1 ) = n - 1. ; T ( n , 0 ) = floor ( n * tau ) . ; T ( n , k ) = T ( n , k - 1 ) + T ( n , k - 2 ) for k >= 1. ; Store ; Return the ans ; Function to find first n terms of Wythoff array by traversing in anti - diagonal ; Map to store the Wythoff array ; Anti diagonal ; Driver code ; Function call
import java . util . * ; public class GFG { static int Wythoff ( HashMap < Integer , HashMap < Integer , Integer > > mp , int n , int k ) { double tau = ( Math . sqrt ( 5 ) + 1 ) / 2.0 , t_n_k ; if ( mp . containsKey ( n ) && mp . get ( n ) . containsKey ( k ) && mp . get ( n ) . get ( k ) != 0 ) return mp . get ( n ) . get ( k ) ; if ( k == - 1 ) { return n - 1 ; } else if ( k == 0 ) { t_n_k = Math . floor ( n * tau ) ; } else { t_n_k = Wythoff ( mp , n , k - 1 ) + Wythoff ( mp , n , k - 2 ) ; } mp . put ( n , new HashMap < Integer , Integer > ( k , ( int ) t_n_k ) ) ; return ( int ) t_n_k ; } static void Wythoff_Array ( int n ) { int i = 0 , j = 0 , count = 0 ; HashMap < Integer , HashMap < Integer , Integer > > mp = new HashMap < Integer , HashMap < Integer , Integer > > ( ) ; while ( count < n ) { System . out . print ( Wythoff ( mp , i + 1 , j + 1 ) ) ; count ++ ; if ( count != n ) System . out . print ( " , ▁ " ) ; i ++ ; j -- ; if ( j < 0 ) { j = i ; i = 0 ; } } } public static void main ( String [ ] args ) { int n = 15 ; Wythoff_Array ( n ) ; } }
Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given | Java implementation of the above approach ; Function to return the sum of numbers which are in the ration a : b and after adding x to both the numbers the new ratio becomes c : d ; Driver code
class GFG { static double sum ( double a , double b , double c , double d , double x ) { double ans = ( x * ( a + b ) * ( c - d ) ) / ( ( a * d ) - ( b * c ) ) ; return ans ; } public static void main ( String [ ] args ) { double a = 1 , b = 2 , c = 9 , d = 13 , x = 5 ; System . out . println ( sum ( a , b , c , d , x ) ) ; } }
Triangle of numbers arising from Gilbreath 's conjecture | Java code for printing the Triangle of numbers arising from Gilbreath 's conjecture ; Check whether the number is prime or not ; Set the 0 th row of the matrix with c primes from 0 , 0 to 0 , c - 1 ; Find the n , k term of matrix of Gilbreath 's conjecture ; recursively find ; store the ans ; Print first n terms of Gilbreath sequence successive absolute differences of primes read by antidiagonals upwards . ; map to store the matrix and hash to check if the element is present or not ; set the primes of first row ; print the Gilbreath number ; increase the count ; anti diagonal upwards ; Driver code
import java . util . * ; public class GFG { static boolean is_Prime ( int n ) { if ( n < 2 ) return false ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static void set_primes ( HashMap < Integer , HashMap < Integer , Integer > > mp , HashMap < Integer , HashMap < Integer , Integer > > hash , int c ) { int count = 0 ; for ( int i = 2 ; count < c ; i ++ ) { if ( is_Prime ( i ) ) { if ( ! mp . containsKey ( 0 ) ) { mp . put ( 0 , new HashMap < Integer , Integer > ( ) ) ; } if ( ! mp . get ( 0 ) . containsKey ( count ) ) { mp . get ( 0 ) . put ( count , i ) ; } else { mp . get ( 0 ) . put ( count , i ) ; } count ++ ; if ( ! hash . containsKey ( 0 ) ) { hash . put ( 0 , new HashMap < Integer , Integer > ( ) ) ; } if ( ! hash . get ( 0 ) . containsKey ( count - 1 ) ) { hash . get ( 0 ) . put ( count - 1 , 1 ) ; } else { hash . get ( 0 ) . put ( count - 1 , 1 ) ; } } } } static int Gilbreath ( HashMap < Integer , HashMap < Integer , Integer > > mp , HashMap < Integer , HashMap < Integer , Integer > > hash , int n , int k ) { if ( hash . containsKey ( n ) && hash . get ( n ) . containsKey ( k ) && hash . get ( n ) . get ( k ) != 0 ) return mp . get ( n ) . get ( k ) ; int ans = Math . abs ( Gilbreath ( mp , hash , n - 1 , k + 1 ) - Gilbreath ( mp , hash , n - 1 , k ) ) ; if ( ! mp . containsKey ( n ) ) { mp . put ( n , new HashMap < Integer , Integer > ( ) ) ; } mp . get ( n ) . put ( k , ans ) ; return ans ; } static void solve ( int n ) { int i = 0 , j = 0 , count = 0 ; HashMap < Integer , HashMap < Integer , Integer > > mp = new HashMap < Integer , HashMap < Integer , Integer > > ( ) ; HashMap < Integer , HashMap < Integer , Integer > > hash = new HashMap < Integer , HashMap < Integer , Integer > > ( ) ; set_primes ( mp , hash , 100 ) ; while ( count < n ) { System . out . print ( Gilbreath ( mp , hash , i , j ) + " , ▁ " ) ; count ++ ; i -- ; j ++ ; if ( i < 0 ) { i = j ; j = 0 ; } } } public static void main ( String [ ] args ) { int n = 15 ; solve ( n ) ; } }
Roots of the quadratic equation when a + b + c = 0 without using Shridharacharya formula | Java implementation of the approach ; Function to print the roots of the quadratic equation when a + b + c = 0 ; Driver Code
class GFG { static void printRoots ( long a , long b , long c ) { System . out . println ( 1 + " , ▁ " + c / ( a * 1.0 ) ) ; } public static void main ( String [ ] args ) { long a = 2 ; long b = 3 ; long c = - 5 ; printRoots ( a , b , c ) ; } }
Longest alternative parity subsequence | Java program to find the length of the longest alternative parity subsequence ; Function to find the longest ; Marks the starting of odd number as sequence and alternatively changes ; Finding the longest odd / even sequence ; Find odd number ; Find even number ; Length of the longest even / odd sequence ; Find odd number ; Find even number ; Answer is maximum of both odd / even or even / odd subsequence ; Driver Code
class GFG { static int longestAlternativeSequence ( int a [ ] , int n ) { int maxi1 = 0 ; int f1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( f1 % 2 != 0 ) { if ( a [ i ] % 2 == 1 ) { f1 = 1 ; maxi1 ++ ; } } else { if ( a [ i ] % 2 == 0 ) { maxi1 ++ ; f1 = 0 ; } } } int maxi2 = 0 ; int f2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( f2 % 2 != 0 ) { if ( a [ i ] % 2 == 1 ) { f2 = 1 ; maxi2 ++ ; } } else { if ( a [ i ] % 2 == 0 ) { maxi2 ++ ; f2 = 0 ; } } } return Math . max ( maxi1 , maxi2 ) ; } public static void main ( String [ ] args ) { int a [ ] = { 13 , 16 , 8 , 9 , 32 , 10 } ; int n = a . length ; System . out . println ( longestAlternativeSequence ( a , n ) ) ; } }
Nambiar Number Generator | Java implementation of the approach ; Function to return the Nambiar number of the given number ; If there is no digit to choose ; Choose the first digit ; Chosen digit 's parity ; To store the sum of the consecutive digits starting from the chosen digit ; While there are digits to choose ; Update the sum ; If the parity differs ; Return the current sum concatenated with the Numbiar number for the rest of the string ; Driver code
class GFG { static String nambiarNumber ( String str , int i ) { if ( i >= str . length ( ) ) return " " ; int firstDigit = ( str . charAt ( i ) - '0' ) ; int digitParity = firstDigit % 2 ; int sumDigits = 0 ; while ( i < str . length ( ) ) { sumDigits += ( str . charAt ( i ) - '0' ) ; int sumParity = sumDigits % 2 ; if ( digitParity != sumParity ) { break ; } i ++ ; } return ( " " + sumDigits + nambiarNumber ( str , i + 1 ) ) ; } public static void main ( String [ ] args ) { String str = "9880127431" ; System . out . println ( nambiarNumber ( str , 0 ) ) ; } }
Program to find the Depreciation of Value | Java program to find depreciation of the value initial value , rate and time are given ; Function to return the depreciation of value ; Driver code
import java . io . * ; class GFG { static float Depreciation ( float v , float r , float t ) { float D = ( float ) ( v * Math . pow ( ( 1 - r / 100 ) , t ) ) ; return D ; } public static void main ( String [ ] args ) { float V1 = 200 , R = 10 , T = 2 ; System . out . print ( Depreciation ( V1 , R , T ) ) ; } }
Highly Totient Number | Java program to find highly totient numbers ; Function to find euler totient number ; Consider all prime factors of n and subtract their multiples from result ; Check if p is a prime factor . ; If yes , then update n and result ; If n has a prime factor greater than sqrt ( n ) ( There can be at - most one such prime factor ) ; Function to find first n highly totient numbers ; Count of Highly totient numbers and value of count of phi of previous numbers ; Store all the values of phi ( x ) upto 10 ^ 5 with frequencies ; If count is greater than count of previous element ; Display the number ; Store the value of phi ; Driver code ; Function call
import java . util . * ; class GFG { static int phi ( int n ) { for ( int p = 2 ; p * p <= n ; ++ p ) { if ( n % p == 0 ) { while ( n % p == 0 ) n /= p ; result -= result / p ; } } if ( n > 1 ) result -= result / n ; return result ; } static void Highly_Totient ( int n ) { int count = 0 , p_count = - 1 ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 1 ; i < 100000 ; i ++ ) { if ( mp . containsKey ( phi ( i ) ) ) { mp . put ( phi ( i ) , mp . get ( phi ( i ) ) + 1 ) ; } else { mp . put ( phi ( i ) , 1 ) ; } } int i = 1 ; while ( count < n ) { if ( mp . containsKey ( i ) && mp . get ( i ) > p_count ) { System . out . print ( i ) ; if ( count < n - 1 ) System . out . print ( " , ▁ " ) ; p_count = mp . get ( i ) ; count ++ ; } i ++ ; } } public static void main ( String [ ] args ) { int n = 20 ; Highly_Totient ( n ) ; } }
Program to find the Speed of train as per speed of sound | Java implementation of the approach ; Function to find the Speed of train ; Driver code ; calling Function
class GFG { static int speedOfTrain ( float X , float Y ) { float Speed ; Speed = 1188 * ( ( X - Y ) / Y ) ; return ( int ) Speed ; } public static void main ( String [ ] args ) { float X = 8f , Y = 7.2f ; int result = ( speedOfTrain ( X , Y ) ) ; System . out . println ( result + " ▁ km / hr " ) ; } }
Maximum value of division of two numbers in an Array | Java program to maximum value of division of two numbers in an array ; Function to maximum value of division of two numbers in an array ; Traverse through the array ; Return the required answer ; Driver code
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int Division ( int a [ ] , int n ) { int maxi = Integer . MIN_VALUE , mini = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { maxi = Math . max ( a [ i ] , maxi ) ; mini = Math . min ( a [ i ] , mini ) ; } return maxi / mini ; } public static void main ( String [ ] args ) throws java . lang . Exception { int a [ ] = { 3 , 7 , 9 , 3 , 11 } ; int n = a . length ; System . out . print ( Division ( a , n ) ) ; } }
Card Shuffle Problem | TCS Digital Advanced Coding Question | Java implementation of the approach ; Total cards ; Function to perform the current round ; Create the required empty piles ; Add cards to the piles one by one ; After all the piles have been reversed the new order will be first card of the first pile , second card of the first pile , ... , last pile of the last pile ( from top to bottom ) ; Function to perform all the rounds ; Create the initial list with all the cards ; Perform all the rounds ; Return the nth card ; Driver code ; nth card will be at ( n - 1 ) th index
import java . util . * ; class GFG { static final int CARDS = 100 ; static void currentRound ( List < Integer > list , int totalPiles ) { List < List < Integer > > piles = new ArrayList < > ( ) ; for ( int i = 0 ; i < totalPiles ; i ++ ) piles . add ( new ArrayList < Integer > ( ) ) ; int j = 0 ; for ( int i = 0 ; i < CARDS ; i ++ ) { piles . get ( j ) . add ( list . get ( i ) ) ; j = ( j + 1 ) % totalPiles ; } int pileNo = 0 , i = 0 ; j = 0 ; while ( i < CARDS ) { list . set ( i , piles . get ( pileNo ) . get ( j ) ) ; j ++ ; if ( j >= piles . get ( pileNo ) . size ( ) ) { pileNo ++ ; j = 0 ; } i ++ ; } } static int performRounds ( int piles [ ] , int rounds , int n ) { List < Integer > list = new ArrayList < > ( ) ; for ( int i = 1 ; i <= CARDS ; i ++ ) list . add ( i ) ; for ( int i = 0 ; i < rounds ; i ++ ) currentRound ( list , piles [ i ] ) ; return list . get ( n ) ; } public static void main ( String [ ] args ) { int piles [ ] = { 2 , 2 } ; int rounds = piles . length ; int n = 4 ; n -- ; System . out . print ( performRounds ( piles , rounds , n ) ) ; } }