Erzeugen Sie eine Modulo-Rosette

22

Das coole Zeug

Die folgende Rosette kann bei der Berechnung von Modulo-7-Zahlen hilfreich sein.

Bildbeschreibung hier eingeben

Dazu müssen Sie bei 0 beginnen und einige Schritte im Uhrzeigersinn drehen, die von der ersten Ziffer vorgegeben werden. Folgen Sie dann für jede nachfolgende Ziffer dem Pfeil und drehen Sie die durch diese Ziffer angegebene Anzahl von Schritten im Uhrzeigersinn.

So gehen Sie für die Nummer 294 vor:

  1. Sie beginnen bei Kreis 0.
  2. Sie drehen die durch die erste Ziffer angegebene Anzahl von Schritten im Uhrzeigersinn (das ist eine 2, Sie landen bei 2).
  3. Sie folgen dort dem Pfeil (Sie landen bei 6).
  4. Sie drehen die durch die zweite Ziffer angegebene Anzahl von Schritten im Uhrzeigersinn (das ist eine 9, Sie landen bei 1).
  5. Sie folgen dort dem Pfeil (Sie landen bei 3).
  6. Sie drehen die durch die dritte Zahl gegebene Anzahl von Schritten im Uhrzeigersinn (das ist 4, Sie landen bei 0).
  7. 294 mod 7 = 0 (was bedeutet, dass 294 ein Vielfaches von 7 ist).

( Video Erklärung, wenn Sie es immer noch nicht verstanden haben )

Das Ziel

Finde heraus, wie das funktioniert (ich weiß, aber ich werde es dir nicht sagen).

Erstellen Sie ein Programm, das eine Zahl nals Parameter annimmt und für das eine Rosette generiert wird mod n.

Die Rosette kann mit beliebigen Mitteln angezeigt werden (ASCII, PNG generieren, SVG generieren, ...), solange sie von einem 8-jährigen Kind verwendet werden kann ( also keine Liste von Regeln, ich möchte ein Bild )!

Sie können Zwangslinien verwenden, auch wenn diese etwas weniger klar sind als das, was ich für das Beispiel gemacht habe, aber Sie müssen die Zahlen, die auf sich selbst verweisen, mit einer Art Schwanzbeißpfeil deutlich anzeigen.

Testfälle

(Ich gebe nur die Verknüpfungen zwischen den Zahlen an. Sie können meine Frage jederzeit bearbeiten, sobald Ihr Programm sie erfolgreich generiert hat.)

mod 2:

0 -> 0
1 -> 0

mod 3:

0 -> 0
1 -> 1
2 -> 2

mod 4:

0 -> 0
1 -> 2
2 -> 0
3 -> 2

mod 5:

0 -> 0
1 -> 0
2 -> 0
3 -> 0
4 -> 0

mod 6:

0 -> 0
1 -> 4
2 -> 2
3 -> 0
4 -> 4
5 -> 2

mod 7:

0 -> 0
1 -> 3
2 -> 6
3 -> 2
4 -> 5
5 -> 1
6 -> 4

mod 8:

0 -> 0
1 -> 2
2 -> 4
3 -> 6
4 -> 0
5 -> 2
6 -> 4
7 -> 6

mod 9:

0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 6
7 -> 7
8 -> 8

mod 10:

0 -> 0
1 -> 0
2 -> 0
3 -> 0
4 -> 0
5 -> 0
6 -> 0
7 -> 0
8 -> 0
9 -> 0

Regeln

Dies ist , der kürzeste Code in Bytes gewinnt.

Lücken und Cheats sind wie immer verboten.

SteeveDroz
quelle
3
Für diejenigen, die (wie ich) keine Videoerklärungen
Luis Mendo
@SteeveDroz Ist das in meiner Antwort verwendete Format in Ordnung?
Loovjo

Antworten:

12

Mathematica, 192 Bytes

Für diese Art von Herausforderung (nicht-triviale mathematische Berechnung zusammen mit Grafikausgabe auf hohem Niveau) ist Mathematica gemacht!

(d=#;r_~t~n_:=r{Sin[#],Cos[#]}&[6.3n/d];m=Mod[10#,d]&;Graphics@{Array[#~Text~t[9,#]&,d,0],Array[Arrow@{t[9,#+1/7],t[9,#+6/7]}&,d],Array[Arrow@BezierCurve@{t[8,#+1/9],{0,0},t[8,m@#-1/9]}&,d]})&

Erweitert und erklärt:

[1] (
[2] d = #; r_~t~n_ := r {Sin[#], Cos[#]} &[6.3 n/d]; m = Mod[10 #, d] &;
[3] Graphics@{
[4]   Array[#~Text~t[9, #] &, d, 0],
[5]   Array[Arrow@{t[9, # + 1/7], t[9, # + 6/7]} &, d],
[6]   Array[Arrow@BezierCurve@{t[8, # + 1/9], {0, 0}, t[8, m@# - 1/9]} &, d]
[7]          }
[8] ) &

Die Zeilen 1 und 8 begrenzen eine unbenannte Funktion eines Arguments. Die Zeilen 3 und 7 begrenzen mehrere Befehle, die Grafiken ausgeben.

Zeile 2 speichert die Eingabe als d; definiert eine Binärfunktion, tdie die Koordinaten eines Punktes n/ddes Weges um den Radiuskreis rim Uhrzeigersinn von oben angibt (im Geiste dieser Site habe ich ein Byte durch Runden von 2π auf 6.3! gespeichert ); und definiert eine unäre Funktion, mdie das Ziel des Pfeils berechnet, beginnend an seinem Argument.

Zeile 4 macht die Zahlen 0an d–1gleich beabstandeten um den Kreis mit dem Radius 9 (der genauen Radius unwichtig, gewählt Ästhetik unterliegen Einpassen in einem Byte zu maximieren).

In Linie 5 werden die geraden Pfeile im Uhrzeigersinn um den Umfang des Kreises gerendert. Das 1/7und 6/7lassen genug Platz, um die Zahlen zu lesen.

Die Linie 6 rendert die gekrümmten Pfeile von jeder Zahl bis (10-mal die Zahl Modulo d). ZeichnetBezierCurve automatisch eine Bézier-Kurve unter Verwendung der angegebenen Kontrollpunkte. Glücklicherweise führt die Verwendung des Ursprungs als einzelner Innenkontrollpunkt zu einer angemessenen Ausgabe.

Beispielausgabe (beachten Sie, dass die Fälle 9, 10 und 11 auf unterschiedliche Weise trivial sind):

d = 7

d = 7

d = 8

d = 8

d = 9

d = 9

d = 10

d = 10

d = 11

d = 11

d = 12

d = 12

d = 13

d = 13

d = 37

d = 37

Diese letzte Eingabe wurde gewählt, weil 37 10 ^ 3–1 dividiert und die inneren Pfeile (ohne den obligatorischen Selbstpfeil von 0 bis 0) viele Dreieckszyklen bilden.

Greg Martin
quelle
1
Wenn ich mir die Ausgabe für d = 37 anschaue, bin ich viel älter als 8 und ich werde eine verdammt lange Zeit danach haben, dass O_O
Gabriel Benamy
Und doch, besonders vergrößert, ist es vollständig nachvollziehbar! (wenn wir die Regeln kennen) Aber ja, wenn Sie mehr Bytes ausgeben, kann dies die visuelle Benutzerfreundlichkeit erheblich verbessern.
Greg Martin
10

Python 2, 294 Bytes

n=input()
r,R="",range(n)
for i in R:r+=["   ","__ "][10*i%n==i]
r+="\n"
for i in R:r+=["   ","|/ "][10*i%n==i]
print r
print">>".join(map(str,R))
for i in R:
    o,r=10*i%n,""
    for j in R:
        r+="|"
        if i<=j<o:r+=">>"
        elif i>j>=o:r+="<<"
        else:r+="  "
    print r

Druckt das Diagramm in diesem Format:

__                   
|/                   
0>>1>>2>>3>>4>>5>>6
|  |  |  |  |  |  |  
|  |>>|>>|  |  |  |  
|  |  |>>|>>|>>|>>|  
|  |  |<<|  |  |  |  
|  |  |  |  |>>|  |  
|  |<<|<<|<<|<<|  |  
|  |  |  |  |<<|<<|  

Ich weiß nicht, ob dieses Format in Ordnung ist, daher lasse ich diese Antwort vorerst als ungültig. Ja, es ist gültig!

Probieren Sie es auf repl.it!

Loovjo
quelle
@DJMcMayhem Das OP hat gesagt, dass ASCII-Grafik zulässig ist, es liegt also am OP.
mbomb007
Das sieht gut aus! Sie sollten versuchen, die Formatierung so einzurichten, dass sie mit n-stelligen Zahlen funktioniert. Ich bin mir nicht sicher, ob die Herausforderung es erfordert, dass Sie es n>9trotzdem tun .
Kade
1
Sieht für mich gut aus, es bedarf keiner weiteren Erklärung als das ursprüngliche Beispiel.
SteeveDroz
6

PHP + SVG, 500 Bytes

kleiner Pfeil für Verbindungen zwischen gleichen Werten

<svg viewBox=0,0,500,500><def><marker id=t viewBox=0,0,9,9 refX=1 refY=5 orient=auto><path d=M0,0L10,5L0,10z /></marker></def><circle cx=250 cy=250 r=150 fill=#ccc /><?for($i=0;$i<$n=$_GET[n];$i++){$w=deg2rad((($i*10%$n)-$i)*360/$n);echo"<g transform=rotate(".$i*360/$n.",250,250)><path d=M250,110L".(250+(sin($w)*135)).",".(250-cos($w)*145)." fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>$i</text></g>";}?></svg>

um die pfeile zu den gleichen werten zu sehen benutze ich diesen farbwert rgba(255,0,0,0.3). es ist eine Möglichkeit, es kurzzuschließen.

erweitert

    <svg viewBox=0,0,500,500>
<def>
<marker id=t viewBox=0,0,10,10 refX=1 refY=5 markerWidth=5 markerHeight=5 orient=auto>
<path d=M0,0L10,5L0,10z />
</marker>
</def>
<circle cx=250 cy=250 r=150 fill=#ccc stroke=#a00 />
<?php for($i=0;$i<$n=$_GET[n];$i++){
$w=deg2rad((($i*10%$n)-$i)*360/$n);
echo"<g transform=rotate(".$i*360/$n.",250,250)>
<path d=M250,110L".(250+(sin($w)*135)).",".(250-cos($w)*145)." fill=none stroke=#0f0 marker-end=url(#t) />
<circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) />
<text x=250 y=105 text-anchor=middle>$i</text>
</g>";
}?>
</svg>

Ausgabe für n = 45

<svg viewBox=0,0,500,500><def><marker id=t viewBox=0,0,10,10 refX=1 refY=5 markerWidth=5 markerHeight=5 orient=auto><path d=M0,0L10,5L0,10z /></marker></def><circle cx=250 cy=250 r=150 fill=#ccc stroke=#a00 /><g transform=rotate(0,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>0</text></g><g transform=rotate(8,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>1</text></g><g transform=rotate(16,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>2</text></g><g transform=rotate(24,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>3</text></g><g transform=rotate(32,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>4</text></g><g transform=rotate(40,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>5</text></g><g transform=rotate(48,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>6</text></g><g transform=rotate(56,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>7</text></g><g transform=rotate(64,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>8</text></g><g transform=rotate(72,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>9</text></g><g transform=rotate(80,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>10</text></g><g transform=rotate(88,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>11</text></g><g transform=rotate(96,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>12</text></g><g transform=rotate(104,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>13</text></g><g transform=rotate(112,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>14</text></g><g transform=rotate(120,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>15</text></g><g transform=rotate(128,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>16</text></g><g transform=rotate(136,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>17</text></g><g transform=rotate(144,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>18</text></g><g transform=rotate(152,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>19</text></g><g transform=rotate(160,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>20</text></g><g transform=rotate(168,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>21</text></g><g transform=rotate(176,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>22</text></g><g transform=rotate(184,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>23</text></g><g transform=rotate(192,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>24</text></g><g transform=rotate(200,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>25</text></g><g transform=rotate(208,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>26</text></g><g transform=rotate(216,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>27</text></g><g transform=rotate(224,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>28</text></g><g transform=rotate(232,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>29</text></g><g transform=rotate(240,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>30</text></g><g transform=rotate(248,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>31</text></g><g transform=rotate(256,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>32</text></g><g transform=rotate(264,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>33</text></g><g transform=rotate(272,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>34</text></g><g transform=rotate(280,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>35</text></g><g transform=rotate(288,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>36</text></g><g transform=rotate(296,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>37</text></g><g transform=rotate(304,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>38</text></g><g transform=rotate(312,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>39</text></g><g transform=rotate(320,250,250)><path d=M250,110L250,105 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>40</text></g><g transform=rotate(328,250,250)><path d=M250,110L378.39262969985,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>41</text></g><g transform=rotate(336,250,250)><path d=M250,110L329.35100905948,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>42</text></g><g transform=rotate(344,250,250)><path d=M250,110L170.64899094052,367.30746418437 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>43</text></g><g transform=rotate(352,250,250)><path d=M250,110L121.60737030015,205.19253581563 fill=none stroke=#0f0 marker-end=url(#t) /><circle cx=250 cy=100 r=10 fill=rgba(255,0,0,0.3) /><text x=250 y=105 text-anchor=middle>44</text></g></svg>

320 Bytes arbeiten mit Rect

<svg viewBox=0,0,<?=$w=30+10*$n=$_GET[n]?>,<?=20*$n?>><?for($i=0;$i<$n;$i++)echo"<rect x=0 y=".($y=$i*20)." fill=none width=$w height=20 stroke=grey /><text x=5 y=".($y+17).">$i</text><path d=M".($x=$i*10+25).",".($y+17)."L$x,".($m=($i*10%$n)*20+5)." fill=none stroke=blue /><circle cx=$x cy=$m r=2 fill=#0f0 />"?></svg>

erweitert

<svg viewBox=0,0,<?=$w=30+10*$n=$_GET[n]?>,<?=20*$n?>>
<?for($i=0;$i<$n;$i++)
echo"<rect x=0 y=".($y=$i*20)." fill=none width=$w height=20 stroke=grey />
<text x=5 y=".($y+17).">$i</text>
<path d=M".($x=$i*10+25).",".($y+17)."L$x,".($m=($i*10%$n)*20+5)." fill=none stroke=blue />
<circle cx=$x cy=$m r=2 fill=#0f0 />"?>
</svg>

Ausgabe für n = 72

<svg viewBox=0,0,750,1440><rect x=0 y=0 fill=none width=750 height=20 stroke=grey /><text x=5 y=17>0</text><path d=M25,17L25,5 fill=none stroke=blue /><circle cx=25 cy=5 r=2 fill=#0f0 /><rect x=0 y=20 fill=none width=750 height=20 stroke=grey /><text x=5 y=37>1</text><path d=M35,37L35,205 fill=none stroke=blue /><circle cx=35 cy=205 r=2 fill=#0f0 /><rect x=0 y=40 fill=none width=750 height=20 stroke=grey /><text x=5 y=57>2</text><path d=M45,57L45,405 fill=none stroke=blue /><circle cx=45 cy=405 r=2 fill=#0f0 /><rect x=0 y=60 fill=none width=750 height=20 stroke=grey /><text x=5 y=77>3</text><path d=M55,77L55,605 fill=none stroke=blue /><circle cx=55 cy=605 r=2 fill=#0f0 /><rect x=0 y=80 fill=none width=750 height=20 stroke=grey /><text x=5 y=97>4</text><path d=M65,97L65,805 fill=none stroke=blue /><circle cx=65 cy=805 r=2 fill=#0f0 /><rect x=0 y=100 fill=none width=750 height=20 stroke=grey /><text x=5 y=117>5</text><path d=M75,117L75,1005 fill=none stroke=blue /><circle cx=75 cy=1005 r=2 fill=#0f0 /><rect x=0 y=120 fill=none width=750 height=20 stroke=grey /><text x=5 y=137>6</text><path d=M85,137L85,1205 fill=none stroke=blue /><circle cx=85 cy=1205 r=2 fill=#0f0 /><rect x=0 y=140 fill=none width=750 height=20 stroke=grey /><text x=5 y=157>7</text><path d=M95,157L95,1405 fill=none stroke=blue /><circle cx=95 cy=1405 r=2 fill=#0f0 /><rect x=0 y=160 fill=none width=750 height=20 stroke=grey /><text x=5 y=177>8</text><path d=M105,177L105,165 fill=none stroke=blue /><circle cx=105 cy=165 r=2 fill=#0f0 /><rect x=0 y=180 fill=none width=750 height=20 stroke=grey /><text x=5 y=197>9</text><path d=M115,197L115,365 fill=none stroke=blue /><circle cx=115 cy=365 r=2 fill=#0f0 /><rect x=0 y=200 fill=none width=750 height=20 stroke=grey /><text x=5 y=217>10</text><path d=M125,217L125,565 fill=none stroke=blue /><circle cx=125 cy=565 r=2 fill=#0f0 /><rect x=0 y=220 fill=none width=750 height=20 stroke=grey /><text x=5 y=237>11</text><path d=M135,237L135,765 fill=none stroke=blue /><circle cx=135 cy=765 r=2 fill=#0f0 /><rect x=0 y=240 fill=none width=750 height=20 stroke=grey /><text x=5 y=257>12</text><path d=M145,257L145,965 fill=none stroke=blue /><circle cx=145 cy=965 r=2 fill=#0f0 /><rect x=0 y=260 fill=none width=750 height=20 stroke=grey /><text x=5 y=277>13</text><path d=M155,277L155,1165 fill=none stroke=blue /><circle cx=155 cy=1165 r=2 fill=#0f0 /><rect x=0 y=280 fill=none width=750 height=20 stroke=grey /><text x=5 y=297>14</text><path d=M165,297L165,1365 fill=none stroke=blue /><circle cx=165 cy=1365 r=2 fill=#0f0 /><rect x=0 y=300 fill=none width=750 height=20 stroke=grey /><text x=5 y=317>15</text><path d=M175,317L175,125 fill=none stroke=blue /><circle cx=175 cy=125 r=2 fill=#0f0 /><rect x=0 y=320 fill=none width=750 height=20 stroke=grey /><text x=5 y=337>16</text><path d=M185,337L185,325 fill=none stroke=blue /><circle cx=185 cy=325 r=2 fill=#0f0 /><rect x=0 y=340 fill=none width=750 height=20 stroke=grey /><text x=5 y=357>17</text><path d=M195,357L195,525 fill=none stroke=blue /><circle cx=195 cy=525 r=2 fill=#0f0 /><rect x=0 y=360 fill=none width=750 height=20 stroke=grey /><text x=5 y=377>18</text><path d=M205,377L205,725 fill=none stroke=blue /><circle cx=205 cy=725 r=2 fill=#0f0 /><rect x=0 y=380 fill=none width=750 height=20 stroke=grey /><text x=5 y=397>19</text><path d=M215,397L215,925 fill=none stroke=blue /><circle cx=215 cy=925 r=2 fill=#0f0 /><rect x=0 y=400 fill=none width=750 height=20 stroke=grey /><text x=5 y=417>20</text><path d=M225,417L225,1125 fill=none stroke=blue /><circle cx=225 cy=1125 r=2 fill=#0f0 /><rect x=0 y=420 fill=none width=750 height=20 stroke=grey /><text x=5 y=437>21</text><path d=M235,437L235,1325 fill=none stroke=blue /><circle cx=235 cy=1325 r=2 fill=#0f0 /><rect x=0 y=440 fill=none width=750 height=20 stroke=grey /><text x=5 y=457>22</text><path d=M245,457L245,85 fill=none stroke=blue /><circle cx=245 cy=85 r=2 fill=#0f0 /><rect x=0 y=460 fill=none width=750 height=20 stroke=grey /><text x=5 y=477>23</text><path d=M255,477L255,285 fill=none stroke=blue /><circle cx=255 cy=285 r=2 fill=#0f0 /><rect x=0 y=480 fill=none width=750 height=20 stroke=grey /><text x=5 y=497>24</text><path d=M265,497L265,485 fill=none stroke=blue /><circle cx=265 cy=485 r=2 fill=#0f0 /><rect x=0 y=500 fill=none width=750 height=20 stroke=grey /><text x=5 y=517>25</text><path d=M275,517L275,685 fill=none stroke=blue /><circle cx=275 cy=685 r=2 fill=#0f0 /><rect x=0 y=520 fill=none width=750 height=20 stroke=grey /><text x=5 y=537>26</text><path d=M285,537L285,885 fill=none stroke=blue /><circle cx=285 cy=885 r=2 fill=#0f0 /><rect x=0 y=540 fill=none width=750 height=20 stroke=grey /><text x=5 y=557>27</text><path d=M295,557L295,1085 fill=none stroke=blue /><circle cx=295 cy=1085 r=2 fill=#0f0 /><rect x=0 y=560 fill=none width=750 height=20 stroke=grey /><text x=5 y=577>28</text><path d=M305,577L305,1285 fill=none stroke=blue /><circle cx=305 cy=1285 r=2 fill=#0f0 /><rect x=0 y=580 fill=none width=750 height=20 stroke=grey /><text x=5 y=597>29</text><path d=M315,597L315,45 fill=none stroke=blue /><circle cx=315 cy=45 r=2 fill=#0f0 /><rect x=0 y=600 fill=none width=750 height=20 stroke=grey /><text x=5 y=617>30</text><path d=M325,617L325,245 fill=none stroke=blue /><circle cx=325 cy=245 r=2 fill=#0f0 /><rect x=0 y=620 fill=none width=750 height=20 stroke=grey /><text x=5 y=637>31</text><path d=M335,637L335,445 fill=none stroke=blue /><circle cx=335 cy=445 r=2 fill=#0f0 /><rect x=0 y=640 fill=none width=750 height=20 stroke=grey /><text x=5 y=657>32</text><path d=M345,657L345,645 fill=none stroke=blue /><circle cx=345 cy=645 r=2 fill=#0f0 /><rect x=0 y=660 fill=none width=750 height=20 stroke=grey /><text x=5 y=677>33</text><path d=M355,677L355,845 fill=none stroke=blue /><circle cx=355 cy=845 r=2 fill=#0f0 /><rect x=0 y=680 fill=none width=750 height=20 stroke=grey /><text x=5 y=697>34</text><path d=M365,697L365,1045 fill=none stroke=blue /><circle cx=365 cy=1045 r=2 fill=#0f0 /><rect x=0 y=700 fill=none width=750 height=20 stroke=grey /><text x=5 y=717>35</text><path d=M375,717L375,1245 fill=none stroke=blue /><circle cx=375 cy=1245 r=2 fill=#0f0 /><rect x=0 y=720 fill=none width=750 height=20 stroke=grey /><text x=5 y=737>36</text><path d=M385,737L385,5 fill=none stroke=blue /><circle cx=385 cy=5 r=2 fill=#0f0 /><rect x=0 y=740 fill=none width=750 height=20 stroke=grey /><text x=5 y=757>37</text><path d=M395,757L395,205 fill=none stroke=blue /><circle cx=395 cy=205 r=2 fill=#0f0 /><rect x=0 y=760 fill=none width=750 height=20 stroke=grey /><text x=5 y=777>38</text><path d=M405,777L405,405 fill=none stroke=blue /><circle cx=405 cy=405 r=2 fill=#0f0 /><rect x=0 y=780 fill=none width=750 height=20 stroke=grey /><text x=5 y=797>39</text><path d=M415,797L415,605 fill=none stroke=blue /><circle cx=415 cy=605 r=2 fill=#0f0 /><rect x=0 y=800 fill=none width=750 height=20 stroke=grey /><text x=5 y=817>40</text><path d=M425,817L425,805 fill=none stroke=blue /><circle cx=425 cy=805 r=2 fill=#0f0 /><rect x=0 y=820 fill=none width=750 height=20 stroke=grey /><text x=5 y=837>41</text><path d=M435,837L435,1005 fill=none stroke=blue /><circle cx=435 cy=1005 r=2 fill=#0f0 /><rect x=0 y=840 fill=none width=750 height=20 stroke=grey /><text x=5 y=857>42</text><path d=M445,857L445,1205 fill=none stroke=blue /><circle cx=445 cy=1205 r=2 fill=#0f0 /><rect x=0 y=860 fill=none width=750 height=20 stroke=grey /><text x=5 y=877>43</text><path d=M455,877L455,1405 fill=none stroke=blue /><circle cx=455 cy=1405 r=2 fill=#0f0 /><rect x=0 y=880 fill=none width=750 height=20 stroke=grey /><text x=5 y=897>44</text><path d=M465,897L465,165 fill=none stroke=blue /><circle cx=465 cy=165 r=2 fill=#0f0 /><rect x=0 y=900 fill=none width=750 height=20 stroke=grey /><text x=5 y=917>45</text><path d=M475,917L475,365 fill=none stroke=blue /><circle cx=475 cy=365 r=2 fill=#0f0 /><rect x=0 y=920 fill=none width=750 height=20 stroke=grey /><text x=5 y=937>46</text><path d=M485,937L485,565 fill=none stroke=blue /><circle cx=485 cy=565 r=2 fill=#0f0 /><rect x=0 y=940 fill=none width=750 height=20 stroke=grey /><text x=5 y=957>47</text><path d=M495,957L495,765 fill=none stroke=blue /><circle cx=495 cy=765 r=2 fill=#0f0 /><rect x=0 y=960 fill=none width=750 height=20 stroke=grey /><text x=5 y=977>48</text><path d=M505,977L505,965 fill=none stroke=blue /><circle cx=505 cy=965 r=2 fill=#0f0 /><rect x=0 y=980 fill=none width=750 height=20 stroke=grey /><text x=5 y=997>49</text><path d=M515,997L515,1165 fill=none stroke=blue /><circle cx=515 cy=1165 r=2 fill=#0f0 /><rect x=0 y=1000 fill=none width=750 height=20 stroke=grey /><text x=5 y=1017>50</text><path d=M525,1017L525,1365 fill=none stroke=blue /><circle cx=525 cy=1365 r=2 fill=#0f0 /><rect x=0 y=1020 fill=none width=750 height=20 stroke=grey /><text x=5 y=1037>51</text><path d=M535,1037L535,125 fill=none stroke=blue /><circle cx=535 cy=125 r=2 fill=#0f0 /><rect x=0 y=1040 fill=none width=750 height=20 stroke=grey /><text x=5 y=1057>52</text><path d=M545,1057L545,325 fill=none stroke=blue /><circle cx=545 cy=325 r=2 fill=#0f0 /><rect x=0 y=1060 fill=none width=750 height=20 stroke=grey /><text x=5 y=1077>53</text><path d=M555,1077L555,525 fill=none stroke=blue /><circle cx=555 cy=525 r=2 fill=#0f0 /><rect x=0 y=1080 fill=none width=750 height=20 stroke=grey /><text x=5 y=1097>54</text><path d=M565,1097L565,725 fill=none stroke=blue /><circle cx=565 cy=725 r=2 fill=#0f0 /><rect x=0 y=1100 fill=none width=750 height=20 stroke=grey /><text x=5 y=1117>55</text><path d=M575,1117L575,925 fill=none stroke=blue /><circle cx=575 cy=925 r=2 fill=#0f0 /><rect x=0 y=1120 fill=none width=750 height=20 stroke=grey /><text x=5 y=1137>56</text><path d=M585,1137L585,1125 fill=none stroke=blue /><circle cx=585 cy=1125 r=2 fill=#0f0 /><rect x=0 y=1140 fill=none width=750 height=20 stroke=grey /><text x=5 y=1157>57</text><path d=M595,1157L595,1325 fill=none stroke=blue /><circle cx=595 cy=1325 r=2 fill=#0f0 /><rect x=0 y=1160 fill=none width=750 height=20 stroke=grey /><text x=5 y=1177>58</text><path d=M605,1177L605,85 fill=none stroke=blue /><circle cx=605 cy=85 r=2 fill=#0f0 /><rect x=0 y=1180 fill=none width=750 height=20 stroke=grey /><text x=5 y=1197>59</text><path d=M615,1197L615,285 fill=none stroke=blue /><circle cx=615 cy=285 r=2 fill=#0f0 /><rect x=0 y=1200 fill=none width=750 height=20 stroke=grey /><text x=5 y=1217>60</text><path d=M625,1217L625,485 fill=none stroke=blue /><circle cx=625 cy=485 r=2 fill=#0f0 /><rect x=0 y=1220 fill=none width=750 height=20 stroke=grey /><text x=5 y=1237>61</text><path d=M635,1237L635,685 fill=none stroke=blue /><circle cx=635 cy=685 r=2 fill=#0f0 /><rect x=0 y=1240 fill=none width=750 height=20 stroke=grey /><text x=5 y=1257>62</text><path d=M645,1257L645,885 fill=none stroke=blue /><circle cx=645 cy=885 r=2 fill=#0f0 /><rect x=0 y=1260 fill=none width=750 height=20 stroke=grey /><text x=5 y=1277>63</text><path d=M655,1277L655,1085 fill=none stroke=blue /><circle cx=655 cy=1085 r=2 fill=#0f0 /><rect x=0 y=1280 fill=none width=750 height=20 stroke=grey /><text x=5 y=1297>64</text><path d=M665,1297L665,1285 fill=none stroke=blue /><circle cx=665 cy=1285 r=2 fill=#0f0 /><rect x=0 y=1300 fill=none width=750 height=20 stroke=grey /><text x=5 y=1317>65</text><path d=M675,1317L675,45 fill=none stroke=blue /><circle cx=675 cy=45 r=2 fill=#0f0 /><rect x=0 y=1320 fill=none width=750 height=20 stroke=grey /><text x=5 y=1337>66</text><path d=M685,1337L685,245 fill=none stroke=blue /><circle cx=685 cy=245 r=2 fill=#0f0 /><rect x=0 y=1340 fill=none width=750 height=20 stroke=grey /><text x=5 y=1357>67</text><path d=M695,1357L695,445 fill=none stroke=blue /><circle cx=695 cy=445 r=2 fill=#0f0 /><rect x=0 y=1360 fill=none width=750 height=20 stroke=grey /><text x=5 y=1377>68</text><path d=M705,1377L705,645 fill=none stroke=blue /><circle cx=705 cy=645 r=2 fill=#0f0 /><rect x=0 y=1380 fill=none width=750 height=20 stroke=grey /><text x=5 y=1397>69</text><path d=M715,1397L715,845 fill=none stroke=blue /><circle cx=715 cy=845 r=2 fill=#0f0 /><rect x=0 y=1400 fill=none width=750 height=20 stroke=grey /><text x=5 y=1417>70</text><path d=M725,1417L725,1045 fill=none stroke=blue /><circle cx=725 cy=1045 r=2 fill=#0f0 /><rect x=0 y=1420 fill=none width=750 height=20 stroke=grey /><text x=5 y=1437>71</text><path d=M735,1437L735,1245 fill=none stroke=blue /><circle cx=735 cy=1245 r=2 fill=#0f0 /></svg>

Jörg Hülsermann
quelle
3

Python 2, 540 464 431 Bytes

Einige Golfer mögen es, kürzere Variablennamen zu verwenden, Variablen zu ersetzen, Listen zu verstehen und alles in Weiß zu ändern (außer dem Text). Die größte Einsparung war das dynamische Ändern der vorberechneten Positionen (siehe L).

from cv2 import*
from numpy import*
D=1024
G=zeros((D,D,3),uint8)
n=7
w=(1,1,1)
R=range(n)
c=circle
I=int
L=lambda i,r=400:(I(sin(2*pi*i/n)*r+D/2),I(D/2-cos(2*pi*i/n)*r))
for i in R:
 p,q=L(i),L((i*10)%n)
 line(G,p,L((i+1)%n),w,5)
 line(G,p,q,w,5)
 f=lambda z:I(.15*p[z]+.85*q[z])
 c(G,[(f(0),f(1)),L(i,450)][p==q],25,w,-1)
for i in R:
 c(G,L(i),50,w,-1)
 putText(G,`i`,(L(i)[0]-30,L(i)[1]+30),0,2,(0,0,0),2)
imwrite('m.png',G*255)

L Berechnet die Positionen der Kreise nach dem Abstand zum Ursprung für die großen Kreise mit den Zahlen und die äußeren kleinen Kreise, die auf Selbstzeigen hinweisen.

Die erste Schleife zeichnet die Verbindungen: Die erste Linie ist der Kreis und die zweite Linie befindet sich im Inneren. Ein kleiner Kreis wird hinzugefügt, um die Richtung oder die Selbstausrichtung anzuzeigen.

Zweite Schleife setzt großen Kreis und Zahl.

Es ist offensichtlich nicht so schön, wie die Mathematica antwortet, aber alles von Grund auf neu gemacht.

Bildbeschreibung hier eingeben

Karl Napf
quelle
2

Mathematica, 124 121 Bytes

Graph[Join@@Thread[{k->Mod[k+1,#],k->Mod[10k,#]}~Table~{k,0,#-1}],VertexLabels->"Name",GraphLayout->"CircularEmbedding"]&

Erzeugt eine Figur als Diagramm mit gerichteten Kanten. Die Grafikausgabe folgt jetzt demselben Muster, außer gegen den Uhrzeigersinn. Ich bevorzuge Greg Martins Lösung viel mehr, da die Ausgabe viel ästhetischer ist.

Mit kann für 82 Bytes ein weniger ansprechender Graph erzeugt werden

Graph[Join@@({k->Mod[k+1,#],k->Mod[10k,#]}~Table~{k,0,#-1}),VertexLabels->"Name"]&

Für d = 8

Abbildung 8

Meilen
quelle
Ja, ich wollte verwenden Graph, hatte aber die gleiche negative Reaktion. Außerdem ist es für den Algorithmus wichtig, zwischen den Flanken "im Uhrzeigersinn" und den Flanken "mal 10" zu unterscheiden. Ich bin mir sicher, dass es Optionen für Graphdieses Handle gibt - aber dann kommen noch mehr Bytes ...
Greg Martin
@ GregMartin Ich habe mehr durchgelesen Graph Funktionen und Tricks gefunden, wie man ->anstelle von verwendet DirectedEdge. Ich habe diese anfängliche 100-Byte-Version auf 82 Byte verkürzt, aber dann durch Korrigieren im richtigen Format weitere 42 Byte hinzugefügt.
Meilen
Das ist interessant: Ich habe es versucht CircularEmbedding, aber es hat die Eckpunkte nicht im Uhrzeigersinn angeordnet n=7(ich gebe zu, ich habe keine anderen Eingaben versucht). Funktioniert es bei dir mit n=7?
Greg Martin
1
Es scheint von der Reihenfolge der Kanten in der Eingabeliste abzuhängen. Ich benutzte Joinund Transposedamit die Außenkanten zuerst vor den Innenkanten aufgeführt würden. Die Scheitelpunkte sind entlang einer Kreisbahn korrekt angeordnet, aber da die Kanten lieber gerade sind, ähnelt dies einem n- Eck.
Meilen
1

Python 2 + Grafik, 147 Bytes

from graphviz import*
d=Digraph()
k=input()
p=d.edge
for j in[d.node(`i`,`i`)or i for i in range(k)]:
 p(`j`,`-~j%k`);p(`j`,`10*j%k`)
d.render("o")

Zeichnet nicht immer einen Kreis, gibt eine aufgerufene PDF-Datei aus o

Ausgabe für 7

Blau
quelle
1

Haskell, 350 Bytes

Inspiriert von @Loovjo verwende ich auch ASCII-Kunst. Dies funktioniert für Nummern unter 100000 (oder so ähnlich).

g k="\t"++(foldl (++) ""$map (\y->show y++"|") [0..k])
n k=length$g k
r z x=(show x)++":\t"++(replicate f ' ')++(replicate d s)++"\n" where y=mod (x*10) z;(a,b)=(min x y,max x y);s=(case compare y x of LT->'<';EQ->'.';GT->'>');f=n (a-1)-1;d=n b-f-2
w z=(g (z-1))++"\n"++(foldl1 (++) (map (r z) [0..(z-1)]))
main=do{n<-getLine;putStrLn (w$read n);}

Grundsätzlich zeigen Sie von x auf (x * 10)% n.

Sie können dies versuchen hier . Da das Codepad keine Eingabe unterstützt, ändern Sie q in den gewünschten Wert von n und reichen Sie ihn erneut ein. (Beachten Sie, dass das Gabeln nicht funktioniert. Kopieren Sie die Daten von der Hauptseite und reichen Sie sie erneut ein.) Der dort übermittelte Code ist etwas anders, da die obige Version Eingaben von der Konsole entgegennimmt.

Ich hoffe die Ausgabe ist intuitiv. Komprimierungsvorschläge sind willkommen (besonders wenn das schlägt 294 ;)).

Mriganka Basu Roy Chowdhury
quelle
Willkommen bei PPCG! Schöner erster Beitrag!
29.
Sie können viele Leerzeichen entfernen, z. B. die infoldl (++) ""$map (\...
Cyoce
1

Batch, 394 Bytes

@echo off
set/an=%1-1
set s=
for /l %%j in (0,1,%n%)do call:h %%j
echo %s%
for /l %%i in (0,1,%n%)do call:r %%i %1
exit/b
:h
set "s=%s%^>%1^>"
exit/b
:r
set/ar=%1*10%%%2
set s=
for /l %%j in (0,1,%n%)do call:l %%j %1
echo %s%
exit/b
:l
if %1==%r% set "s=%s%^>%1^<"&exit/b
if %2 geq %1 if %1 geq %r% set "s=%s%^<%1%^<"&exit/b
if %2 leq %1 if %1 leq %r% goto h
set "s=%s% %1 "

In Batch zu flüchten ist im besten Fall hässlich. Beispielausgabe für 7:

>0>>1>>2>>3>>4>>5>>6>
>0< 1  2  3  4  5  6
 0 >1>>2>>3< 4  5  6
 0  1 >2>>3>>4>>5>>6<
 0  1 >2<<3< 4  5  6
 0  1  2  3 >4>>5< 6
 0 >1<<2<<3<<4<<5< 6
 0  1  2  3 >4<<5<<6<
Neil
quelle
Welche Art von Bild gibt diese Ausgabe aus? Diese Herausforderung ist die grafische Ausgabe .
mbomb007
@ mbomb007 Wie ist das für die Ausgabe? Die >0<zeigt , dass 0sich abbildet, während >2<<<3<zeigt , dass die 3Karten zu 2.
Neil