Courses‎ > ‎Intro to CS - Half Year‎ > ‎Dyrland-Weaver‎ > ‎Work‎ > ‎

### Work 11: 10/3

posted Oct 3, 2018, 12:32 PM by JonAlf Dyrland-Weaver
 Write the following functions in racketsumDigsTakes 1 parameter representing a nonnegative integerReturns the sum of all digits in the numberUse a recursive method to solve this problemExamples:`(sumDigs 0) ==> 0``(sumDigs 5) ==> 5``(sumDigs 612) ==> 9`sumRangeTakes 2 integer argumentsReturns the sum of all the integers between the 2 argumentsExamples`(sumRange 4 4) ==> 4``(sumRange 3 8) ==> 33``(sumRange 8 3) ==> 33`Challenge time!You do not need to complete these problems. Please do not select working on these over bodily necessities, like sleep.The numbers we most commonly interact with are written in a decimal, or base 10, system.This means that every digit represents a multiplier of a power of 10. For example, 45610 = 4*102 + 5 * 101 + 6 * 100.We use this fact to help solve problems involving the individual digits of a number.There are other base systemsIn binary (base 2), we use powers of 2 instead of powers of 10For example, 10112 = 1 * 23 + 0 * 22 + 1 * 21 + 1 *20In octal (base 8), we use powers of 8.138 = 1 * 81 + 3 * 80Write a function that takes a positive decimal integer and returns the number of digits that would be needed to represent that number in binary.(binaryDigits 11) ==> 4(binaryDigits 4) ==> 3Write a function that takes 2 positive decimal integers as arguments and returns the number of digits that would be needed to represent the first argument in the seconds base.(baseNDigits 457 8) would return the numbers of digits needed to represent 45710 in octal.submit this under recursion