Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung Nächste Überarbeitung Beide Seiten, nächste Überarbeitung | ||
treffen:codegolfing:004_gc [2019/12/30 22:41] max [Lösungen] |
treffen:codegolfing:004_gc [2022/07/07 13:24] max |
||
---|---|---|---|
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 8: | Zeile 19: | ||
===== Lösungen ===== | ===== Lösungen ===== | ||
Perl, nopx, 191B, {{ : | Perl, nopx, 191B, {{ : | ||
+ | Eine lesbare Lösung mit diesem Ansatz gibt es ganz unten auf dieser Seite. ;) | ||
<code Perl> | <code Perl> | ||
$m=$ARGV[0]-1; | $m=$ARGV[0]-1; | ||
Zeile 49: | Zeile 61: | ||
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 | ||
Zeile 87: | Zeile 120: | ||
<code Java> | <code Java> | ||
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, | ||
+ | |||
+ | 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 ) | ||
</ | </ |