Question: (I need help programming this code. If you can do it in Scala, that would be great. If not, Python works too. Thank you.) INSTRUCTIONS:

(I need help programming this code. If you can do it in Scala, that would be great. If not, Python works too. Thank you.)

INSTRUCTIONS:

Now, write a tail recursive version of the convertToBinary function, called convertToBinaryTail.

Your function should be tail recursive and takes in a single integer argument and returns a String.

Hint You can have more arguments to your tail recursive function but make sure to give them a default value. Alternatively, you can make an explicit helper function.

Restrictions

Use of var and loops forbidden. Inbuilt functions that directly perform conversion are also forbidden. Must be tail recursive.

###CODE

import scala.annotation.tailrec @tailrec // YOUR CODE HERE ???

//BEGIN TEST assert(convertToBinaryTail(1) == "1", "(1)decimal must be 1 binary") assert(convertToBinaryTail(5) == "101", "5 must be 101 binary") assert(convertToBinaryTail(11) == "1011", "(11) must be 1011") assert(convertToBinaryTail(4100) == "1000000000100", "(4100) must be 1000000000100") assert(convertToBinaryTail(30108100) == "1110010110110100111000100", "(30108100) must be 1110010110110100111000100") passed(10) //END TEST

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!