Loading problems/LabOne_ChapterFive.h 0 → 100644 +72 −0 Original line number Diff line number Diff line // // Created by Ari Trachtenberg on 9/10/24. // // CHAPTER 5 #include <string> using namespace std; /** * @param nn A positive integer * @return The sum of the following values: * a. The first digit of nn. * b. The last digit of nn. * c. The number of digits in nn. * * @example * labOne_pFour(1729) returns 14, because: * a. The first digit of 1729 = 1. * b. The last digit of 1729 = 9. * c. The number digits in 1729 = 4. */ int labOne_pFour(int nn); /** * @param str Some string. * @return The reverse of [str] * @note Your function must be *recursive* in nature. * @hint Reverse the substring starting at the second character, * then add the first character to the end. * * @example * labOne_pFour("wolf") returns "flow". */ int labOne_pFive(string str); /** * @param str Some string. * @return true if and only if [str] is a palindrome * @see https://en.wikipedia.org/wiki/Palindrome * * @example 1 * labOne_pSix("deed") == true because "deed" is the same forward as backward. * * @example 2 * labOne_pSix("deeds") == false because "deeds" backwards is "sdeed", and the * two strings are different. * * @example 3 * labOne_pSix("aibophpobia") == true because the string is the same forward as backward. * */ bool labOne_pSix(string str); /** * @param num A positive inteber <= 3628799. * @return The number [num] in the factorial number system. * @see https://en.wikipedia.org/wiki/Factorial * @see https://en.wikipedia.org/wiki/Factorial_number_system * * @example 1 * labOne_pSix(3) = 11 because: * 3 = 1*2! + 1*1! * * @example 2 * labOne_pSix(10) = 120 because: * 10 = 1*3! + 2*2! + 0*1! * * @example 3 * labOne_pSix(463) returns 34101 because: * 463 = 3*5! + 4*4! + 1*3! + 0*2! + 1*1! */ long labOne_pSeven(long num); No newline at end of file problems/LabOne_ChapterFour.h 0 → 100644 +94 −0 Original line number Diff line number Diff line // // Created by Ari Trachtenberg on 9/10/24. // // CHAPTER 4 /** * @input read in two positive integers, height and width * @output a height x width rectangle of stars "*" * @note You may use only *one* loop in your code - no * nested loops. * * @example 1 * height: 3 * width: 4 * **** * **** * **** * * @example 2 * height: 1 * width: 10 * ********** */ void labOne_pZero(); /** * @input max The upper bound of sums * @output The sum of the following terms: * a. The sum of the even integers between 2 and max (inclusive). * b. The sum of all square numbers between 1 and max (inclusive). * c. The sum of all positive powers of two less than or equal to max. * @note: You must use *loops* to compute the component sums. * @see https://en.wikipedia.org/wiki/Square_number * * @example 1 * Max: 2 * 5 * * This is because 2+1+2 = 5: * a. The sum of even integers between 2 and 2 inclusive (i.e., 2) * b. The sum of all squares between 1 and 2 (inclusive) (i.e., 1) * c. The sum of all positive powers of two less than or equal to 2 (i.e., 2) * * @example 2 * MaxL 9 * 47 * * This is because 20+14+13 = 47: * a. 2+4+6+8 = 20 * b. 1+4+9 = 14 * c. 1+4+8 = 13 */ void labOne_pOne(); /** * @input a string * @output all substrings of the input, sorted by length. * * @example * Input: rum * Output: * r * u * m * ru * um * rum */ void labOne_pTwo(); /** * @input an upper bound [u] for the numbers to consider * @output A list of the numbers 2...[u] (inclusive) that * are *not* prime, one per line * * @example * Input: 20 * Output: * 4 * 6 * 8 * 9 * 10 * 12 * 14 * 15 * 16 * 18 * 20 * */ void labOne_pThree(); Loading
problems/LabOne_ChapterFive.h 0 → 100644 +72 −0 Original line number Diff line number Diff line // // Created by Ari Trachtenberg on 9/10/24. // // CHAPTER 5 #include <string> using namespace std; /** * @param nn A positive integer * @return The sum of the following values: * a. The first digit of nn. * b. The last digit of nn. * c. The number of digits in nn. * * @example * labOne_pFour(1729) returns 14, because: * a. The first digit of 1729 = 1. * b. The last digit of 1729 = 9. * c. The number digits in 1729 = 4. */ int labOne_pFour(int nn); /** * @param str Some string. * @return The reverse of [str] * @note Your function must be *recursive* in nature. * @hint Reverse the substring starting at the second character, * then add the first character to the end. * * @example * labOne_pFour("wolf") returns "flow". */ int labOne_pFive(string str); /** * @param str Some string. * @return true if and only if [str] is a palindrome * @see https://en.wikipedia.org/wiki/Palindrome * * @example 1 * labOne_pSix("deed") == true because "deed" is the same forward as backward. * * @example 2 * labOne_pSix("deeds") == false because "deeds" backwards is "sdeed", and the * two strings are different. * * @example 3 * labOne_pSix("aibophpobia") == true because the string is the same forward as backward. * */ bool labOne_pSix(string str); /** * @param num A positive inteber <= 3628799. * @return The number [num] in the factorial number system. * @see https://en.wikipedia.org/wiki/Factorial * @see https://en.wikipedia.org/wiki/Factorial_number_system * * @example 1 * labOne_pSix(3) = 11 because: * 3 = 1*2! + 1*1! * * @example 2 * labOne_pSix(10) = 120 because: * 10 = 1*3! + 2*2! + 0*1! * * @example 3 * labOne_pSix(463) returns 34101 because: * 463 = 3*5! + 4*4! + 1*3! + 0*2! + 1*1! */ long labOne_pSeven(long num); No newline at end of file
problems/LabOne_ChapterFour.h 0 → 100644 +94 −0 Original line number Diff line number Diff line // // Created by Ari Trachtenberg on 9/10/24. // // CHAPTER 4 /** * @input read in two positive integers, height and width * @output a height x width rectangle of stars "*" * @note You may use only *one* loop in your code - no * nested loops. * * @example 1 * height: 3 * width: 4 * **** * **** * **** * * @example 2 * height: 1 * width: 10 * ********** */ void labOne_pZero(); /** * @input max The upper bound of sums * @output The sum of the following terms: * a. The sum of the even integers between 2 and max (inclusive). * b. The sum of all square numbers between 1 and max (inclusive). * c. The sum of all positive powers of two less than or equal to max. * @note: You must use *loops* to compute the component sums. * @see https://en.wikipedia.org/wiki/Square_number * * @example 1 * Max: 2 * 5 * * This is because 2+1+2 = 5: * a. The sum of even integers between 2 and 2 inclusive (i.e., 2) * b. The sum of all squares between 1 and 2 (inclusive) (i.e., 1) * c. The sum of all positive powers of two less than or equal to 2 (i.e., 2) * * @example 2 * MaxL 9 * 47 * * This is because 20+14+13 = 47: * a. 2+4+6+8 = 20 * b. 1+4+9 = 14 * c. 1+4+8 = 13 */ void labOne_pOne(); /** * @input a string * @output all substrings of the input, sorted by length. * * @example * Input: rum * Output: * r * u * m * ru * um * rum */ void labOne_pTwo(); /** * @input an upper bound [u] for the numbers to consider * @output A list of the numbers 2...[u] (inclusive) that * are *not* prime, one per line * * @example * Input: 20 * Output: * 4 * 6 * 8 * 9 * 10 * 12 * 14 * 15 * 16 * 18 * 20 * */ void labOne_pThree();