51
2
Given two positive integers, A and B, illustrate their least common multiple by outputting two lines of dashes (-
) with length LCM(A, B) after replacing every Ath dash in the first line and every Bth 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, 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
------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|------------|
----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|
3
@LeakyNun Extending an answer from https://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.
– Calvin's Hobbies – 2017-09-25T19:02:49.0831Can I output an array with two strings, one for each line? – BlackCap – 2017-09-25T19:05:19.153
@BlackCap No. Print the strings to stdout or a file or return the whole multiline string. – Calvin's Hobbies – 2017-09-25T19:06:37.397
2Bonus for handling arbitrary number of inputs? – Adám – 2017-09-25T23:49:04.073
Is a leading new-line allowed if the rest of the output is correct? – Kevin Cruijssen – 2017-09-27T17:25:09.377
@KevinCruijssen that sounds ok. – Calvin's Hobbies – 2017-09-27T18:44:33.587
1@HelkaHomba Ok thanks; saved 1 more byte. :) (As if there is any other reason to ask such questions on codegolf challenges. ;p) – Kevin Cruijssen – 2017-09-28T06:58:11.673