# The Imperial Ruler

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

• Can we take decimals instead of fractions?
– Okx
Commented Feb 24, 2017 at 20:52
• @Okx No - decimals are not allowed. Commented Feb 24, 2017 at 20:54
• Can I take input as 11/4 instead of 2 3/4 ? Commented Feb 24, 2017 at 21:43
• Could we take input as 2+3/4?
– Blue
Commented Feb 24, 2017 at 21:44
• I was expecting a Star Wars challenge :( Commented Feb 25, 2017 at 4:12

# Pyke, 38 bytes

KQz\/cebj*Bh Fj.DRIIid)ij.Hi'f jRf\/Rs


Try it online!

Not too bad for a language that has literally no fractional support. Explanation later if at all.

## Mathematica, 55 53 bytes

Thanks to JungHwan Min for saving 2 bytes.

DeleteCases[{a=Floor@#,#-a},0,1,1]&/@Range[0,+##2,#]&


Takes three numbers as input, the step width, the integer part of the ruler length, the fractional part of the ruler length.

Output is a list of lists with sublists like {1} or {2, 3/4}.

# Husk, 21 bytes

:"0"mȯwfI§e⌊%1↑≤Σ⁰¡+³


Try it online!

Have to prepend a 0 string before, cause filtering out zeroes messes with it.

Does anybody know how to run the Ohm answer?

## Batch, 213 bytes

@echo off
set n=%4
set/an*=%1,n+=%2*%1/%3
for /l %%i in (0,1,%n%)do call:c %%i %1
exit/b
:c
if %n%==0 echo %i%&exit/b
set/an/=p=n^&-n,d/=p
if %i% gtr 0 set n=%i% %n%
echo %n%/%d%


Takes 4 numbers as input:

1. The number of marks per inch i.e. the reciprocal/denominator of the granularity
2. The numerator of the ruler length
3. The denominator of the ruler length
4. (Optional) The whole number of inches of the ruler length

So for the second example the parameters would be 8 3 4 2. Note that for lengths that are an exact number of integers you still need to specify a dummy fraction e.g. 4 0 1 2, or an improper fraction 4 2 1 would also work.

# Ohm, 17 bytes

II¢/II/a/#:$_*,;  Explanation: II/¢II/a/#:$_*,;  ■Main wire
II/¢              ■Evaluate fraction and save to register
II/           ■Evaluate another fraction
a/         ■Divide first by second evaluating to the required steps
#:    ;  ■foreach _ in range(0,steps){
\$_*,   ■  print (register * _)
■}

• Sorry, I'm not familiar with Ohm. Is there an interpreter somewhere (preferably online) I can use to verify this answer? Commented Mar 1, 2017 at 18:29