codeparrot/xlcost-text-to-code huggingface dataset:
Program for volume of Pyramid | Function to find the volume of triangular pyramid ; Function to find the volume of square pyramid ; Function to find the volume of pentagonal pyramid ; Function to find the volume of hexagonal pyramid ; Driver Code
< ? php function volumeTriangular ( $ a , $ b , $ h ) { $ vol = ( 0.1666 ) * $ a * $ b * $ h ; return $ vol ; } function volumeSquare ( $ b , $ h ) { $ vol = ( 0.33 ) * $ b * $ b * $ h ; return $ vol ; } function volumePentagonal ( $ a , $ b , $ h ) { $ vol = ( 0.83 ) * $ a * $ b * $ h ; return $ vol ; } function volumeHexagonal ( $ a , $ b , $ h ) { $ vol = $ a * $ b * $ h ; return $ vol ; } $ b = 4 ; $ h = 9 ; $ a = 4 ; echo ( " Volume ▁ of ▁ triangular ▁ base ▁ pyramid ▁ is ▁ " ) ; echo ( volumeTriangular ( $ a , $ b , $ h ) ) ; echo ( " STRNEWLINE " ) ; echo ( " Volume ▁ of ▁ square ▁ base ▁ pyramid ▁ is ▁ " ) ; echo ( volumeSquare ( $ b , $ h ) ) ; echo ( " STRNEWLINE " ) ; echo ( " Volume ▁ of ▁ pentagonal ▁ base ▁ pyramid ▁ is ▁ " ) ; echo ( volumePentagonal ( $ a , $ b , $ h ) ) ; echo ( " STRNEWLINE " ) ; echo ( " Volume ▁ of ▁ Hexagonal ▁ base ▁ pyramid ▁ is ▁ " ) ; echo ( volumeHexagonal ( $ a , $ b , $ h ) ) ; ? >
Program to find area of a Trapezoid | Function for the area ; Driver Code
< ? php function Area ( $ b1 , $ b2 , $ h ) { return ( ( $ b1 + $ b2 ) / 2 ) * $ h ; } $ base1 = 8 ; $ base2 = 10 ; $ height = 6 ; $ area = Area ( $ base1 , $ base2 , $ height ) ; echo ( " Area ▁ is : ▁ " ) ; echo ( $ area ) ; ? >
Find number of diagonals in n sided convex polygon | PHP function to find number of diagonals in n sided convex polygon ; Driver Code
< ? php function numberOfDiagonals ( $ n ) { return $ n * ( $ n - 3 ) / 2 ; } $ n = 5 ; echo $ n , " ▁ sided ▁ convex ▁ polygon ▁ have ▁ " ; echo numberOfDiagonals ( $ n ) , " ▁ diagonals " ;
Given a string and an integer k , find the kth sub | Function to prints kth sub - string ; Total sub - strings possible ; If k is greater than total number of sub - strings ; To store number of sub - strings starting with ith character of the string ; Compute the values ; substring [ i - 1 ] is added to store the cumulative sum ; Binary search to find the starting index of the kth sub - string ; To store the ending index of the kth sub - string ; Print the sub - string ; Driver code
< ? php function Printksubstring ( $ str , $ n , $ k ) { $ total = floor ( ( $ n * ( $ n + 1 ) ) / 2 ) ; if ( $ k > $ total ) { printf ( " - 1 STRNEWLINE " ) ; return ; } $ substring = array ( ) ; $ substring [ 0 ] = 0 ; $ temp = $ n ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ substring [ $ i ] = $ substring [ $ i - 1 ] + $ temp ; $ temp -- ; } $ l = 1 ; $ h = $ n ; $ start = 0 ; while ( $ l <= $ h ) { $ m = floor ( ( $ l + $ h ) / 2 ) ; if ( $ substring [ $ m ] > $ k ) { $ start = $ m ; $ h = $ m - 1 ; } else if ( $ substring [ $ m ] < $ k ) $ l = $ m + 1 ; else { $ start = $ m ; break ; } } $ end = $ n - ( $ substring [ $ start ] - $ k ) ; for ( $ i = $ start - 1 ; $ i < $ end ; $ i ++ ) print ( $ str [ $ i ] ) ; } $ str = " abc " ; $ k = 4 ; $ n = strlen ( $ str ) ; Printksubstring ( $ str , $ n , $ k ) ; ? >
Lower Insertion Point | Function to return the lower insertion point of an element in a sorted array ; Base cases ; Final check for the remaining elements which are < X ; Driver code
< ? php function LowerInsertionPoint ( $ arr , $ n , $ X ) { if ( $ X < $ arr [ 0 ] ) return 0 ; else if ( $ X > $ arr [ $ n - 1 ] ) return $ n ; $ lowerPnt = 0 ; $ i = 1 ; while ( $ i < $ n && $ arr [ $ i ] < $ X ) { $ lowerPnt = $ i ; $ i = $ i * 2 ; } while ( $ lowerPnt < $ n && $ arr [ $ lowerPnt ] < $ X ) $ lowerPnt ++ ; return $ lowerPnt ; } $ arr = array ( 2 , 3 , 4 , 4 , 5 , 6 , 7 , 9 ) ; $ n = sizeof ( $ arr ) ; $ X = 4 ; echo LowerInsertionPoint ( $ arr , $ n , $ X ) ; ? >
Number of positions with Same address in row major and column major order | Returns count of required positions ; horizontal 1D array ; vertical 1D array ; iterating for all possible i ; checking if j is integer ; checking if j lies b / w 1 to N ; iterating for all possible j ; checking if i is integer ; checking if i lies b / w 1 to M ; Driver Code
< ? php function getCount ( $ M , $ N ) { $ count = 0 ; if ( $ M == 1 ) return $ N ; if ( $ N == 1 ) return $ M ; if ( $ N > $ M ) { for ( $ i = 1 ; $ i <= $ M ; $ i ++ ) { $ numerator = $ N * $ i - $ N + $ M - $ i ; $ denominator = $ M - 1 ; if ( $ numerator % $ denominator == 0 ) { $ j = $ numerator / $ denominator ; if ( $ j >= 1 and $ j <= $ N ) $ count ++ ; } } } else { for ( $ j = 1 ; $ j <= $ N ; $ j ++ ) { $ numerator = $ M * $ j - $ M + $ N - $ j ; $ denominator = $ N - 1 ; if ( $ numerator % $ denominator == 0 ) { $ i = $ numerator / $ denominator ; if ( $ i >= 1 and $ i <= $ M ) $ count ++ ; } } } return $ count ; } $ M = 3 ; $ N = 5 ; echo getCount ( $ M , $ N ) ; ? >
Middle of three using minimum comparisons | Function to find the middle of three numbers ; Compare each three number to find middle number . Enter only if a > b ; Decided a is not greater than b . ; Driver Code
< ? php function middleOfThree ( $ a , $ b , $ c ) { if ( $ a > $ b ) { if ( $ b > $ c ) return $ b ; else if ( $ a > $ c ) return $ c ; else return $ a ; } else { if ( $ a > $ c ) return $ a ; else if ( $ b > $ c ) return $ c ; else return $ b ; } } $ a = 20 ; $ b = 30 ; $ c = 40 ; echo middleOfThree ( $ a , $ b , $ c ) ; ? >
Arrange given numbers to form the smallest number | Utility function to print the contents of an array ; A comparison function that return true if ' AB ' is smaller than ' BA ' when we concatenate two numbers ' A ' and ' B ' For example , it will return true if we pass 12 and 24 as arguments . This function will be used by sort ( ) function ; Convert first number to string format ; Convert second number to string format ; Check if ' AB ' is smaller or ' BA ' and return bool value since comparison operator ' < = ' returns true or false ;  ; Function to print the arrangement with the smallest value ; If we pass the name of the comparison function it will sort the array according to the compare function ; Print the sorted array ; Driver code
< ? php function printArr ( $ arr , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ arr [ $ i ] ; } function compare ( $ num1 , $ num2 ) { $ A = ( string ) $ num1 ; $ B = ( string ) $ num2 ; if ( ( int ) ( $ A . $ B ) <= ( int ) ( $ B . $ A ) ) { return true ; } else return false ; } function sort_arr ( $ arr ) { for ( $ i = 0 ; $ i < count ( $ arr ) ; $ i ++ ) { for ( $ j = $ i + 1 ; $ j < count ( $ arr ) ; $ j ++ ) { if ( compare ( $ arr [ $ i ] , $ arr [ $ j ] ) == false ) { $ temp = $ arr [ $ i ] ; $ arr [ $ i ] = $ arr [ $ j ] ; $ arr [ $ j ] = $ temp ; } } } return $ arr ; } function printSmallest ( $ N , $ arr ) { $ arr = sort_arr ( $ arr ) ; printArr ( $ arr , $ N ) ; } $ arr = array ( 5 , 6 , 2 , 9 , 21 , 1 ) ; $ N = count ( $ arr ) ; printSmallest ( $ N , $ arr ) ; ? >
Permute two arrays such that sum of every pair is greater or equal to K | Check whether any permutation exists which satisfy the condition . ; Sort the array a [ ] in decreasing order . ; Sort the array b [ ] in increasing order . ; Checking condition on each index . ; Driven Program
< ? php function isPossible ( $ a , $ b , $ n , $ k ) { sort ( $ a ) ; rsort ( $ b ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ a [ $ i ] + $ b [ $ i ] < $ k ) return false ; return true ; } $ a = array ( 2 , 1 , 3 ) ; $ b = array ( 7 , 8 , 9 ) ; $ k = 10 ; $ n = count ( $ a ) ; if ( isPossible ( $ a , $ b , $ n , $ k ) ) echo " Yes " ; else echo " No " ; ? >
Encrypt a string by repeating i | Function to return the encrypted string ; Number of times the current character will be repeated ; Repeat the current character in the encrypted string ; Driver code
< ? php function encryptString ( $ str , $ n ) { $ i = 0 ; $ cnt = 0 ; $ encryptedStr = " " ; while ( $ i < $ n ) { $ cnt = $ i + 1 ; while ( $ cnt -- ) $ encryptedStr . = $ str [ $ i ] ; $ i ++ ; } return $ encryptedStr ; } $ str = " geeks " ; $ n = strlen ( $ str ) ; echo encryptString ( $ str , $ n ) ; ? >
Minimize the difference between the maximum and minimum values of the modified array | Function to return required minimum difference ; finding minimum and maximum values ; returning minimum possible difference ; Driver program ; function to return the answer
< ? php function minDiff ( $ n , $ x , $ A ) { $ mn = $ A [ 0 ] ; $ mx = $ A [ 0 ] ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ mn = min ( $ mn , $ A [ $ i ] ) ; $ mx = max ( $ mx , $ A [ $ i ] ) ; } return max ( 0 , $ mx - $ mn - 2 * $ x ) ; } $ n = 3 ; $ x = 3 ; $ A = array ( 1 , 3 , 6 ) ; echo minDiff ( $ n , $ x , $ A ) ; ? >