# Illustrate the Least Common Multiple

Given two positive integers, $$\A\$$ and $$\B\$$, illustrate their least common multiple by outputting two lines of dashes (-) with length $$\\text{lcm}\$$$$\(A, B)\$$ after replacing every $$\A\$$th dash in the first line and every $$\B\$$th dash in the second line with vertical bars (|).

In this way, the end of each line will be the only place two |'s line up.

For example, if $$\A = 6\$$ and $$\B = 4\$$, $$\\text{lcm}(6, 4) = 12\$$, so:

two lines of 12 dashes:
------------
------------

replace every 6th dash in the first line with a vertical bar:
-----|-----|
------------

replace every 4th dash in the second line with a vertical bar:
-----|-----|
---|---|---|


Thus the final output would be

-----|-----|
---|---|---|


The order of the input numbers should correspond to the order of the lines.

The shortest code in bytes wins.

# Testcases

A B
line for A
line for B

1 1
|
|

1 2
||
-|

2 1
-|
||

2 2
-|
-|

6 4
-----|-----|
---|---|---|

4 6
---|---|---|
-----|-----|

2 3
-|-|-|
--|--|

3 2
--|--|
-|-|-|

3 6
--|--|
-----|

2 5
-|-|-|-|-|
----|----|

4 3
---|---|---|
--|--|--|--|

10 10
---------|
---------|

10 5
---------|
----|----|

10 6
---------|---------|---------|
-----|-----|-----|-----|-----|

24 8
-----------------------|
-------|-------|-------|

7 8
------|------|------|------|------|------|------|------|
-------|-------|-------|-------|-------|-------|-------|

6 8
-----|-----|-----|-----|
-------|-------|-------|

13 11
------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|
----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|

• @LeakyNun Extending an answer from codegolf.stackexchange.com/q/94999 seems easier than from that one. Either way, people will have fun doing this one which is a decent reason imo. Sep 25 '17 at 19:02
• Can I output an array with two strings, one for each line? Sep 25 '17 at 19:05
• @BlackCap No. Print the strings to stdout or a file or return the whole multiline string. Sep 25 '17 at 19:06
• Bonus for handling arbitrary number of inputs?
Sep 25 '17 at 23:49
• @HelkaHomba Ok thanks; saved 1 more byte. :) (As if there is any other reason to ask such questions on codegolf challenges. ;p) Sep 28 '17 at 6:58

# Excel VBA, 79 Bytes

Anonymous VBE immediate window function that takes input from the range [A1:B1] and outputs a visualization of their LCM to the VBE immediate window.

?[Rept(Rept("-",A1-1)&"|",LCM(1:1)/A1)]:?[Rept(Rept("-",B1-1)&"|",LCM(1:1)/B1)]


# Japt, 12 bytes

£×/Ury)î|ù-X


Japt Interpreter

Inputs as an array of numbers. Outputs as an array of strings. The -R flag slightly improves how the output looks, but isn't necessary for the logic.

Explanation:

£              For each of the two inputs as X, print...
|           The string "|"
ù-X        Left-padded with "-" until it is X characters long
î            Repeated until its length is
×/Ury)             The Least Common Multiple

Extra thanks to Shaggy for finding some bytes to save.

• 15 bytes Oct 23 '18 at 19:10
• @Shaggy Interesting, I never thought to use that part of Japt in that exact way. Oct 23 '18 at 19:17
• Knocked another few bytes off Oct 23 '18 at 19:33

# Jelly, 11 bytes

,ḍþælị⁾|-ZY


Try it online!

## How it works

,ḍþælị⁾|-ZY - Main link. Takes A on the left and B on the right
,           - Pair; [A, B]
æl       - LCM; L := LCM(A, B)
þ         - Create a 2×L matrix and for each cell (i,j) i ∈ (A,B), 1 ≤ j ≤ L:
ḍ          -   Is i divisible by j?
ị⁾|-   - Index into "|-", replacing 1 with "|" and 0 with "-"
Z  - Transpose the matrix into a L×2 matrix
Y - Join by newlines


# Pyth - 20 bytes

j.e*/@QtkiFQ+*\-tb\|


# Retina, 67 bytes

\d+
$*- ^((-+)(\2)*) ((\2)+)$
$1$#5$*1¶$4$#3$*11
-1
|
+(-*.)1
$1$1


Try it online! Link includes test cases.

# PHP, 142 bytes

list(,$a,$b)=$argv;for($n=$a;$n<=$a*$b;$n+=$a)if($n%$b==0)break;while($i<$n)echo++$i%$a==0?'|':'-';echo"
";while($j<$n)echo++$j%$b==0?'|':'-';


Try it online !

# AWK, 80 bytes

{for(;++m%$1||m%$2;)for(i=0;i++<2;)r[i]=r[i](m%$i?"-":"|");$0=r[1]"|\n"r[2]"|"}1


Try it online!

For 2 or more values you can use the following 94 bytes:

{m=0;for(x=1;x&&++m;)for(x=i=0;i++<NF;){x+=r=m%$i;R[i]=R[i](r?"-":"|")}for(;++z<i;)print R[z]}  Try it online! I'm probably missing something obvious to shorten this. :) ## Javascript (ES6), 84 bytes f=(a,b,c=1,o=x='-'.repeat(a-1)+'|')=>(o.length%b?f(a,b,0,o+x):o)+(c? +f(b,a,0):'')  Test Cases: f=(a,b,c=1,o=x='-'.repeat(a-1)+'|')=>(o.length%b?f(a,b,0,o+x):o)+(c? +f(b,a,0):'') console.log(f(1,1)); console.log(f(1,2)); console.log(f(2,1)); console.log(f(2,2)); console.log(f(6,4)); console.log(f(4,6)); console.log(f(2,3)); console.log(f(3,2)); console.log(f(10,10)); console.log(f(3, 6)); console.log(f(2, 5)); console.log(f(4, 3)); console.log(f(10, 10)); console.log(f(10, 5)); console.log(f(10, 6)); console.log(f(24, 8)); console.log(f(7, 8)); console.log(f(6, 8)); console.log(f(13, 11)); ## Old answer Javascript (ES6), 91 bytes f=(a,b)=>{for(x=y='',i=0;!i++||q||r;)q=i%a,r=i%b,x+=q?'-':'|',y+=r?'-':'|';return x+'\n'+y}  # Ruby, 45 bytes ->a,b{[a,b].map{|x|(?-*~-x+?|)*(a.lcm(b)/x)}}  Try it online! # PHP, 85 82 bytes for([,$a,$b]=$argv;++$i%$a|$y=$i%$b;$t.="-|"[!$y])$s.=$i%$a?"-":"|";echo"$s|$t|";


# Perl 6, 39 bytes

{@^a>>.&{('-'x$_-1~'|')x([lcm] @a)/$_}}


Try it online!

Takes input as a pair of numbers and returns a list of lines. Note that you can pass in as many integers as you like and it will print the lcm graph of all of them.

# Powershell, 79 bytes

param($a,$b)do{$x+='-|'[!($c=++$i%$a)];$y+='-|'[!($d=$i%$b)]}while($c+$d)
$x;$y


Ungolfed test script:

$f = { param($a,$b) do{$x+='-|'[!($c=++$i%$a)]$y+='-|'[!($d=$i%$b)] }while($c+$d)$x;$y } @( ,(1,1,"| |") ,(1,2,"|| -|") ,(2,1,"-| ||") ,(6,4,"-----|-----| ---|---|---|") ,(4,6,"---|---|---| -----|-----|") ,(2,3,"-|-|-| --|--|") ,(3,2,"--|--| -|-|-|") ,(3,6,"--|--| -----|") ,(2,5,"-|-|-|-|-| ----|----|") ,(4,3,"---|---|---| --|--|--|--|") ,(10,10,"---------| ---------|") ,(10,5,"---------| ----|----|") ,(10,6,"---------|---------|---------| -----|-----|-----|-----|-----|") ,(24,8,"-----------------------| -------|-------|-------|") ,(7,8,"------|------|------|------|------|------|------|------| -------|-------|-------|-------|-------|-------|-------|") ,(6,8,"-----|-----|-----|-----| -------|-------|-------|") ,(13,11,"------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|------------| ----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|") ) | % {$a,$b,$expected = $_$result = &$f$a $b "$(""$result"-eq"$expected"): $a,$b"
\$result
}


Output:

True: 1,1
|
|
True: 1,2
||
-|
True: 2,1
-|
||
True: 6,4
-----|-----|
---|---|---|
True: 4,6
---|---|---|
-----|-----|
True: 2,3
-|-|-|
--|--|
True: 3,2
--|--|
-|-|-|
True: 3,6
--|--|
-----|
True: 2,5
-|-|-|-|-|
----|----|
True: 4,3
---|---|---|
--|--|--|--|
True: 10,10
---------|
---------|
True: 10,5
---------|
----|----|
True: 10,6
---------|---------|---------|
-----|-----|-----|-----|-----|
True: 24,8
-----------------------|
-------|-------|-------|
True: 7,8
------|------|------|------|------|------|------|------|
-------|-------|-------|-------|-------|-------|-------|
True: 6,8
-----|-----|-----|-----|
-------|-------|-------|
True: 13,11
------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|
----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|


# Julia 1.0, 52 47 bytes

p->println.(@.("-"^(p-1)*"|").^(lcm(p...).÷p))


Anonymous function; takes a list or tuple of two integers and prints the ASCII-art. Try it online!

### Explanation

p->                 Function of p (a list or tuple of two integers):
println.(   )       Print with newline, vectorized:
@.(   )             Vectorize throughout the following expression:
"-"^(p-1)*"|"      String of x-1 hyphens and one pipe for each x in p
(   ).^(   )        each repeated this many times:
lcm(p...)         LCM of the two integers in p
.÷p      divided by each number in p
`
• 40 bytes Jan 1 '19 at 20:00