# 可视化最大公约数

28

## 例

``````0  1  2  3  4  5  6  7  8  9 10 11 12
o  .  .  .  o  .  o  .  o  .  .  .  o
``````

``````o...O.O.o...o
``````

## 测试用例

`````` 1  1 -> OO
2  2 -> O.O
1  3 -> OOoo
4  1 -> OOooo
2  6 -> O.O.o.o
2  3 -> o.OOo.o
10  2 -> O.O.o.o.o.o
4  5 -> o...OO..o.o.o..oo...o
8  6 -> o.....O.O...o...o.o.....o
12 15 -> o...........O..O........o.....o.....o........o..o...........o
19 15 -> o..............o...o..........o.......o......o...........o..o..............OO.............o....o.........o........o.....o............o.o..............o.o............o.....o........o.........o....o.............oo..............o..o...........o......o.......o..........o...o..............o
``````

1

Martin Ender'1

1
@MartinBüttner可以是任何字符，只要您一致且两个输入都使用相同的格式即可。
Zgarb'1

2

Akangka '16

@ChristianIrwan是的，允许所有内置插件。
Zgarb

7

# Jolf，52个字节

``````on*'.wm9jJΡR m*Yhm8jJDN?<*%Sj%SJ1'o'.}"'o%o"n"O%O"n
``````

``````on*'.wm9jJ
on         set n
*'.       to a dot repeated
m9jJ  the gcd of two numeric inputs

ΡR m*Yhm8jJDN?<*%Sj%SJ1'o'.}"'o%o"n"O%O"n
*Y                                    multiply (repeat) Y (Y = [])
hm8jJ                                by the lcm of two inputs + 1
_m       DN              }              and map the array of that length
?<*%Sj%SJ1'o'.               "choose o if i%a*(i%b)<1; otherwise choose ."
R                          "'            join by empty string
Ρ                            'o%o"n        replace once (capital Rho, 2 bytes): "o"+n+"o"
"O%O"n   with "O"+n+"O"
implicit printing
``````

Rɪᴋᴇʀ

1
@RikerW是的！我希望Jolf最终能赢得一次。

10

# 利亚，111个110 107 103 96字节

``f(a,b)=replace(join([i%a*(i%b)<1?"o":"."for i=0:lcm(a,b)]),"o\$(d="."^(gcd(a,b)-1))o","O\$(d)O",1)``

``````function f(a::Int, b::Int)
# Construct an array of dots and o's
x = [i % a * (i % b) < 1 ? "o" : "." for i = 0:lcm(a, b)]

# Join it into a string
j = join(x)

# Replace the first pair with distance gcd(a, b) - 1
replace(j, "o\$(d = "."^(gcd(a, b) - 1))o", "O\$(d)O", 1)
end``````

10

## 视网膜，112 109 99 94 91字节

``````^
.
+r`(?<!^\1+). (.+)
\$'\$0
.(?=.* (.+) (.+))(?=\1* |\2* )
o
o(\.*)o((\1\.*o)*) .*
O\$1O\$2
``````

### 说明

``````^
.
``````

``````+r`(?<!^\1+). (.+)
\$'\$0
``````

``````.(?=.* (.+) (.+))(?=\1* |\2* )
o
``````

``````o(\.*)o((\1\.*o)*) .*
O\$1O\$2
``````

@CᴏɴᴏʀO'Bʀɪᴇɴ是的，但是后来我必须用`.`以后的替换它，这需要四个字节（而摆脱转义符只能节省3个字节）。
Martin Ender

5

# 𝔼𝕊𝕄𝕚𝕟，50个字符/ 90个字节

``````⩥Мū⁽îí+1)ⓜ\$%î⅋\$%í?⍘.:⍘o)⨝ċɼ(`o⦃⍘.ĘМũ⁽îí-1)}o”,↪\$ú⬮
``````

Try it here (Firefox only).

# 说明

### 阶段1

``````⩥Мū⁽îí+1)ⓜ\$%î⅋\$%í?⍘.:⍘o)⨝
``````

### 阶段2

``````ċɼ(`o⦃⍘.ĘМũ⁽îí-1)}o”,↪\$ú⬮
``````

3

# MATL，72字节

``````2\$tZm1+:1-bbvtbw\A~otbZ}ZdXK1+ltb(3X53\$X+1K2\$lh*t2=f1)tK+hwg1+Ib('.oO'w)
``````

### 例

``````>> matl
> 2\$tZm1+:1-bbvtbw\A~otbZ}ZdXK1+ltb(3X53\$X+1K2\$lh*t2=f1)tK+hwg1+Ib('.oO'w)
>
> 1
> 1
OO

>> matl
> 2\$tZm1+:1-bbvtbw\A~otbZ}ZdXK1+ltb(3X53\$X+1K2\$lh*t2=f1)tK+hwg1+Ib('.oO'w)
>
> 2
> 3
o.OOo.o

>> matl
> 2\$tZm1+:1-bbvtbw\A~otbZ}ZdXK1+ltb(3X53\$X+1K2\$lh*t2=f1)tK+hwg1+Ib('.oO'w)
>
> 12
> 15
o...........O..O........o.....o.....o........o..o...........o
``````

CalculatorFeline

2

## Japt，83个字节

``````'.pD=U*V/(C=(G=@Y?G\$(\$YX%Y :X} \$(\$UV)+1 £Y%U©Y%V?".:o"} \$.replace(\$E=`o{'.pC-1}o`Eu
``````

ETHproductions 2016年

@Eth我还没有弄清楚如何在没有g标志的情况下进行替换，所以不，我不能。
nicael

2

## 的Javascript，170个164 161 153 145 141 136字节

``````(a,b)=>[...Array(a*b/(c=(g=(a,b)=>b?g(b,a%b):a)(a,b))+1)].map((x,i)=>i%a&&i%b?'.':'o').join``.replace(`o\${e='.'.repeat(c-1)}o`,`O\${e}O`)
``````

Demo，显式定义的变量，因为解释器使用严格模式。

Mama Fun Roll'1

Mama Fun Roll'1

@ןnɟuɐɯɹɐןoɯ谢谢，还用简单的重复替换数组。
nicael

Mama Fun Roll'1

`[...Array((d=a*b/(c=(g=(a,b)=>b?g(b,a%b):a)(a,b)))+1).keys()].map(i=>i%a&&i%b?'.':'o')`为您节省两个字节。（我也尝试使用字符串索引来创建'。'和'o'，但实际上要花费两个字节。）
Neil

1

# Python 2中，217个200 191字节

``````g=lambda a,b:b and g(b,a%b)or a
def f(a,b):
h=g(a,b);x=1+a*b/h;s=["."]*x;v=k=0
for i in range(x):
if(i%a)*(i%b)<1:
if k:s[i]="o"
else:k=i==h+v;s[i]=s[v]="oO"[k]
v=i
return''.join(s)``````

``````def gcd(a,b):                           # recursive gcd function
if b:
return g(b,a%b)
else:
return a
def f(a,b):
h = gcd(a,b)
x = 1 + a*b/h                       # 1 + lcm(a,b)
s = ["."] * x
v = 0
k = 0
for i in range(x):
if i%a == 0 and i % b == 0:
if k == 0:
k = (i == h+v)          # correct distance apart?
if k:                   # if "O" just found
s[i] = s[v] = "O"
else:
s[i] = s[v] = "o"
else:
s[i] = "o"              # if "O" already found, always "o"
v = i                       # If we found an "o" or an "O", i is the new v
return ''.join(s)``````