Solution to "Integer Identifiers" problem on Learn OCaml
Oct 19, 2019Here’s the problem:
Suppose that a variable
xexists and is an integer.Define a variable
x_power_8that uses three multiplications to calculatexto the power of 8. The only function you are allowed to call is the(*)operator.Hint: use auxiliary variables.
Solve this exercise using a nested sequence of auxiliary variable definitions. Here is a definition of x_power_8 which Learn OCaml recognizes as correct:
This can be written more simply if we use the Jane Street stdlib, Base. Assuming you have the library available, entering the following lines of code into utop will work: