CMU 15-112 Spring 2016 Homework 2 Practice
(Due never)



  1. mostFrequentDigit(n)
  2. isRotation(x, y)
  3. hasOnlyOddDigits(n)
  4. longestDigitRun(n)
  5. nthPalindromicPrime(n)
  6. nthLeftTruncatablePrime(n)
  7. nthPowerfulNumber(n)
  8. countingPrimes
  9. findZerosWithBisection
  10. And More!

  1. mostFrequentDigit(n)
    Write the function mostFrequentDigit(n), that takes a non-negative integer n and returns the digit from 0 to 9 that occurs most frequently in it, with ties going to the smaller digit.

  2. isRotation(x, y)
    Write the function isRotation(x, y) that takes two non-negative integers x and y and returns True if x is a rotation of the digits of y and False otherwise. For example, 3412 is a rotation of 1234, and 321 (with an implicit leading 0) is a rotation of 3210. Any number is a rotation of itself.

  3. hasOnlyOddDigits(n)
    Write the function hasOnlyOddDigits(n) that takes a possibly-negative integer n and returns True if n only has odd digits, and False otherwise (that is, if it has any even digits).

  4. longestDigitRun(n)
    Write the function longestDigitRun(n) that takes a possibly-negative int value n and returns the digit that has the longest consecutive run, or the smallest such digit if there is a tie. So, longestDigitRun(117773732) returns 7 (because there is a run of 3 consecutive 7's), as does longestDigitRun(-677886).

  5. nthPalindromicPrime(n)
    Write the function nthPalindromicPrime(n). See here for details. So nthPalindromicPrime(0) returns 2, and nthPalindromicPrime(10) returns 313.

  6. nthLeftTruncatablePrime(n)
    Write the function nthLeftTruncatablePrime(n). See here for details. So nthLeftTruncatablePrime(0) returns 2, and nthLeftTruncatablePrime(10) returns 53.

  7. nthPowerfulNumber(n)
    Write the function nthPowerfulNumber(n). See here for details. So nthPowerfulNumber(0) returns 1, and nthPowerfulNumber(10) returns 64.

  8. countingPrimes
    Do the "Counting Primes" problem here.

  9. findZerosWithBisection
    Do the "Find Zeros With Bisection" problem here.

  10. And More!
    You can find even more loops-and-conditional problems here.