logo CodeStepByStep logo


Language/Type: ML
Author: Marty Stepp (on 2017/03/28)

Define a function named twos that takes a single integer argument and that returns the number of factors of two in the number. For example, the number 168 when expressed as a product of prime factors is 2 * 2 * 2 * 3 * 7, which means that it has three factors of 2, so twos(168) should return 3. Similarly the number -30 would be expressed as -(2 * 3 * 5), which means that it has one factor of 2, so twos(~30) should return 1. You may assume that the value passed to the function is not equal to 0.

Your function must have the following signature:

val twos = fn : int -> int
Type your ML solution code here:

This is a function exercise. Write a ML function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.

If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.