treffen:codegolfing:004_gc

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen gezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
Letzte Überarbeitung Beide Seiten, nächste Überarbeitung
treffen:codegolfing:004_gc [2019/12/29 11:03]
max
treffen:codegolfing:004_gc [2022/07/07 13:24]
max
Zeile 1: Zeile 1:
-====== 004 CodeGolfing ======+{{:treffen:fir-tree-branch-with-needles-close-up.jpg?400|}}
  
 +[[https://www.freepik.com/photos/christmas|Christmas photo created by senivpetro - www.freepik.com]]
 +
 +
 +
 +====== 004: XMAS Tree ======
 +
 +| Serie | [[treffen:codegolfing|CodeGolfings]] |
 +| Von | [[user:nopx|nopx]] |
 +| Datum | 28. Dezember 2019 |
 +| Download | {{ :treffen:004.pdf |Aufgabenbeschreibung [pdf]}} |
 +| Schweirigkeit | {{:treffen:problemsolving:progress2.png?nolink&160 |}} | 
  
 CodeGolfing bis zu den [[treffen:lightningtalks20191228|Lightningtalks II]] am 28.Dez 2019. CodeGolfing bis zu den [[treffen:lightningtalks20191228|Lightningtalks II]] am 28.Dez 2019.
Zeile 7: Zeile 18:
  
 ===== Lösungen ===== ===== Lösungen =====
-Perl, nopx, 191B +Perl, nopx, 191B, {{ :treffen:004_gc_solution_nopx.pdf |Beschreibung}} 
-<code>+Eine lesbare Lösung mit diesem Ansatz gibt es ganz unten auf dieser Seite. ;)  
 +<code Perl>
 $m=$ARGV[0]-1;sub p{($h,$s)=@_;$_=$"x($m**2+$m+2-$s-$h)."#"x$h.$"x$s;print;chop;print~~reverse.$/}for(0..$m){$w=$m*$_;p(1,$w+$_)for(0..$m);$b=($w+1)*($_!=$m);p($m+2+$w-$b,$b)}p($m)for(0..$m) $m=$ARGV[0]-1;sub p{($h,$s)=@_;$_=$"x($m**2+$m+2-$s-$h)."#"x$h.$"x$s;print;chop;print~~reverse.$/}for(0..$m){$w=$m*$_;p(1,$w+$_)for(0..$m);$b=($w+1)*($_!=$m);p($m+2+$w-$b,$b)}p($m)for(0..$m)
 </code> </code>
 in 'schön': in 'schön':
-<code>+<code Perl>
 $m=$ARGV[0]-1; $m=$ARGV[0]-1;
 sub p{ sub p{
Zeile 33: Zeile 45:
  
 Ruby, Weber, 198B Ruby, Weber, 198B
-<code>+<code Ruby>
 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,m)} a.each{|i|p(0,m)}
 +</code>
 +Hatte Tomaten auf den Augen. Nachgereicht 2022-07-01 (190B):
 +<code Ruby>
 +n=ARGV[0].to_i;m=n-1;$b=n*n-n+2;a=(0..m);def p(f,t);s=" "*f+"#"*t+" "*($b-f-t);puts s.reverse+s[1..-1]end;a.each{|i|c=(n-1)*i;a.each{|j|p(c+j,1)};p(*i==m ?[0,c+n+1]:[c+1,n])};a.each{p(0,m)}
 +</code>
 +
 +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=" "*(w-h-s)+"#"*h+" "*s
 +    print(l[:-1]+l[::-1])
 +for e in r:
 +    for l in r:
 +        p(1,m*e+l)
 +    p(w)if e==m else p(m+1,m*e+1)
 +for _ in r:p(m)
 </code> </code>
  
 Python, v0tti, 226B Python, v0tti, 226B
-<code>+<code Python>
 import sys;n=int(sys.argv[1]);s="#";m=n+1 import sys;n=int(sys.argv[1]);s="#";m=n+1
 for x in range(m*m-1): for x in range(m*m-1):
Zeile 62: Zeile 95:
  
 Python, Okulus, 292B Python, Okulus, 292B
-<code>+<code Python>
 import sys;n=int(sys.argv[1]);i=1-n+n**2;p,r,x=print,range,0;s,w=" #" import sys;n=int(sys.argv[1]);i=1-n+n**2;p,r,x=print,range,0;s,w=" #"
 for a in r(n): for a in r(n):
Zeile 77: Zeile 110:
  
 C, Kai, 323B C, Kai, 323B
-<code>+<code C>
 #include<stdio.h> #include<stdio.h>
 #include<stdlib.h> #include<stdlib.h>
Zeile 85: Zeile 118:
  
 Java, Hanna, 636B Java, Hanna, 636B
-<code>+<code Java>
 public class X{public static void main(String[]b){int n=Integer.valueOf(b[0]);int s=n*(n-1)+1;int r=s*2;char a[]=new char[r+1];for(int k=0;k<n;k++){for(int j=0;j<n;j++){for(int i=0;i<r+1;i++)a[i]=' ';int t=k*n+j-k;a[s-t]='#';a[s+t]='#';p(s,a);l();}if(k==n-1){for(int i=0;i<r+1;i++)a[i]='#';p(s,a);}else{int x=0;for(int i=0;i<r+1;i++){while(x<n){a[s-n-(k*n-k)+x]='#';a[s+n+(k*n-k)-x]='#';x++;}}p(s,a);l();}}for(int i=0;i<r+1;i++)a[i]=' ';int x=0;while(x<n){l();for(int i=s-(n-2);i<=s+(n-2);i++)a[i]='#';p(s,a);x++;}}static void p(int s,char a[]){for(int i=0;i<(s*2)+1;i++){System.out.print(a[i]);}}static void l(){System.out.println();}} public class X{public static void main(String[]b){int n=Integer.valueOf(b[0]);int s=n*(n-1)+1;int r=s*2;char a[]=new char[r+1];for(int k=0;k<n;k++){for(int j=0;j<n;j++){for(int i=0;i<r+1;i++)a[i]=' ';int t=k*n+j-k;a[s-t]='#';a[s+t]='#';p(s,a);l();}if(k==n-1){for(int i=0;i<r+1;i++)a[i]='#';p(s,a);}else{int x=0;for(int i=0;i<r+1;i++){while(x<n){a[s-n-(k*n-k)+x]='#';a[s+n+(k*n-k)-x]='#';x++;}}p(s,a);l();}}for(int i=0;i<r+1;i++)a[i]=' ';int x=0;while(x<n){l();for(int i=s-(n-2);i<=s+(n-2);i++)a[i]='#';p(s,a);x++;}}static void p(int s,char a[]){for(int i=0;i<(s*2)+1;i++){System.out.print(a[i]);}}static void l(){System.out.println();}}
 +</code>
 +
 +Python in schön, nopx
 +<code Python>
 +#!/usr/bin/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,num_spaces :int =0):
 +
 +    line = " "*(l_left - num_hashes - num_spaces) + "#"*num_hashes + " "*num_spaces
 +    # Remove last column, mirror, concatenate together and plot:
 +    print(line[:-1] + line[::-1])
 +
 +# 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 ) 
 </code> </code>
  • treffen/codegolfing/004_gc.txt
  • Zuletzt geändert: 2022/07/07 13:26
  • von max