Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
treffen:codegolfing:004_gc [2019/12/29 11:02] max |
treffen:codegolfing:004_gc [2022/07/07 13:26] (aktuell) max [Lösungen] |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== 004 CodeGolfing ====== | + | {{: |
+ | [[https:// | ||
+ | |||
+ | |||
+ | |||
+ | ====== 004: XMAS Tree ====== | ||
+ | |||
+ | | Serie | [[treffen: | ||
+ | | Von | [[user: | ||
+ | | Datum | 28. Dezember 2019 | | ||
+ | | Download | {{ : | ||
+ | | Schweirigkeit | {{: | ||
CodeGolfing bis zu den [[treffen: | CodeGolfing bis zu den [[treffen: | ||
Zeile 7: | Zeile 18: | ||
===== Lösungen ===== | ===== Lösungen ===== | ||
- | Perl, nopx 191B | + | Perl, nopx, 191B, {{ : |
- | < | + | Eine lesbare Lösung mit diesem Ansatz gibt es ganz unten auf dieser Seite. ;) |
+ | < | ||
$m=$ARGV[0]-1; | $m=$ARGV[0]-1; | ||
</ | </ | ||
in ' | in ' | ||
- | < | + | < |
$m=$ARGV[0]-1; | $m=$ARGV[0]-1; | ||
sub p{ | sub p{ | ||
Zeile 32: | Zeile 44: | ||
</ | </ | ||
- | Ruby, Weber 198B | + | Ruby, Weber, 198B |
- | < | + | < |
n=ARGV[0].to_i | n=ARGV[0].to_i | ||
m=n-1 | m=n-1 | ||
Zeile 48: | Zeile 60: | ||
} | } | ||
a.each{|i|p(0, | a.each{|i|p(0, | ||
+ | </ | ||
+ | Hatte Tomaten auf den Augen. Nachgereicht 2022-07-01 (190B): | ||
+ | <code Ruby> | ||
+ | n=ARGV[0].to_i; | ||
+ | </ | ||
+ | |||
+ | Python, nopx, 224B (nachgereicht) | ||
+ | <code Python> | ||
+ | import sys | ||
+ | n=int(sys.argv[1]) | ||
+ | m=n-1 | ||
+ | w=m*m+m+2 | ||
+ | r=range(n) | ||
+ | def p(h,s=0): | ||
+ | l=" " | ||
+ | print(l[: | ||
+ | for e in r: | ||
+ | for l in r: | ||
+ | p(1,m*e+l) | ||
+ | p(w)if e==m else p(m+1, | ||
+ | for _ in r:p(m) | ||
</ | </ | ||
Python, v0tti, 226B | Python, v0tti, 226B | ||
- | < | + | < |
import sys; | import sys; | ||
for x in range(m*m-1): | for x in range(m*m-1): | ||
Zeile 62: | Zeile 95: | ||
Python, Okulus, 292B | Python, Okulus, 292B | ||
- | < | + | < |
import sys; | import sys; | ||
for a in r(n): | for a in r(n): | ||
Zeile 77: | Zeile 110: | ||
C, Kai, 323B | C, Kai, 323B | ||
- | < | + | < |
# | # | ||
# | # | ||
Zeile 85: | Zeile 118: | ||
Java, Hanna, 636B | Java, Hanna, 636B | ||
- | < | + | < |
public class X{public static void main(String[]b){int n=Integer.valueOf(b[0]); | public class X{public static void main(String[]b){int n=Integer.valueOf(b[0]); | ||
+ | </ | ||
+ | |||
+ | Python in schön, nopx | ||
+ | <code Python> | ||
+ | # | ||
+ | |||
+ | import sys | ||
+ | |||
+ | # Read command line argument: | ||
+ | n = int(sys.argv[1]) | ||
+ | |||
+ | # We often use n-1, so lets use a variable for that: | ||
+ | m = n-1 | ||
+ | |||
+ | # Calculate length of left part | ||
+ | l_left = m**2 + m + 2 | ||
+ | |||
+ | # Helper function to plot a row | ||
+ | def plotline(num_hashes :int ,num_spaces :int =0): | ||
+ | |||
+ | line = " " | ||
+ | # Remove last column, mirror, concatenate together and plot: | ||
+ | print(line[: | ||
+ | |||
+ | # Print tree part | ||
+ | for etagenumber in range(n): | ||
+ | # You may set w = m * etagenumber as we often use that in the following. | ||
+ | for linenumber in range(n): | ||
+ | # Plot lines with on # | ||
+ | plotline(1, m*etagenumber + linenumber) | ||
+ | |||
+ | # Plot line with multiple # | ||
+ | if etagenumber == m: | ||
+ | # Something special for the last etage: | ||
+ | plotline( l_left ) | ||
+ | else: | ||
+ | # For all other etages: | ||
+ | plotline( m+1, m*etagenumber + 1) | ||
+ | |||
+ | # Print trunk | ||
+ | for _ in range(n): plotline( m ) | ||
</ | </ |