7
Given a ruler length in inches and fractions of an inch, and a granularity in fractions of an inch, output the values of all marks on the ruler, starting from 0, in ascending order.
Input ruler length will be a mixed fraction (integer and proper fraction)
Input granularity will be a proper fraction in the form 1/(2ⁿ)
, where 1 ≤ n ≤ 6
.
Output numbers will all be expressed similarly to the input. For values where the number of inches is a whole number, no fractional part will be expressed. For values where the number of inches is 0 < n < 1
, only the fractional part will be expressed.
If the input granularity is not fine enough to represent the ruler length, then the final number will be the closest representable number below the ruler length.
Examples
Input 1
1/2
would output:
0
1/2
1
Input 2 3/4
1/8
would output:
0
1/8
1/4
3/8
1/2
5/8
3/4
7/8
1
1 1/8
1 1/4
1 3/8
1 1/2
1 5/8
1 3/4
1 7/8
2
2 1/8
2 1/4
2 3/8
2 1/2
2 5/8
2 3/4
Input 2 3/4
1/2
would output:
0
1/2
1
1 1/2
2
2 1/2
1Can we take decimals instead of fractions? – Okx – 2017-02-24T20:52:59.297
@Okx No - decimals are not allowed. – Digital Trauma – 2017-02-24T20:54:02.147
1Can I take input as 11/4 instead of 2 3/4 ? – cleblanc – 2017-02-24T21:43:14.417
1Could we take input as
2+3/4
? – Blue – 2017-02-24T21:44:54.273@cleblanc Input ruler length will be a mixed fraction (integer and proper fraction) - No, sorry. – Digital Trauma – 2017-02-24T21:58:48.127
@muddyfish I was intentionally vague about out how fractions are presented. So yes, this is fine. – Digital Trauma – 2017-02-24T22:00:29.327
7I was expecting a Star Wars challenge :( – Daniel – 2017-02-25T04:12:16.050