MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply TodayWrite a function that takes one double input value and returns only the repeating decimal, if any, as a string. Only decimals for which **all** digits are part of the repeating pattern will be counted. (See the 3rd example below.) Inputs will be in the range [0 1].

If no repeating decimal is found, the function should return an empty string. Of course the repeating decimal may break down in the last bit due to floating point arithmetic, but we will ignore that.

Examples:

T = repeatingdec(7/11) % Returns T = '63' T = repeatingdec(1/3) % Returns T = '3' T = repeatingdec(5/6) % Returns T = '' T = repeatingdec(0) % Returns T = '0'

18 correct solutions
61 incorrect solutions

Last solution submitted on Oct 20, 2015

3 players like this problem

1 Comment

Andrew Newell
on 20 Jun 2013

If the number is a true repeater, then multiplying it by 999... for some number of 9's will result in an integer. The difficulty lies in the rounding. I had to tune the tolerance to deal with cases like .123451234512345, which aren't truly repeating.

1 Comment

Khaled Hamed
on 28 Aug 2012

Some cleaning up!

1 Comment