|  Beide Seiten, vorherige Überarbeitung
 Vorherige Überarbeitung
 Nächste Überarbeitung
 | 
                     Vorherige Überarbeitung
 | 
                
                        
                
                    treffen:codegolfing:002_gc [2017/12/18 10:08] max                  | 
                
                    treffen:codegolfing:002_gc [2021/08/25 08:15] (aktuell) max                  | 
            
        
| ====== 002 CodeGolfing - Zahlenspirale ====== | {{:treffen:codegolfing:nautiluscutawaylogarithmicspiral.jpg?400|}}  | 
|   |   | 
|   | [[https://creativecommons.org/licenses/by-sa/3.0/deed.de|CC-BY-SA 3.0]] by [[https://commons.wikimedia.org/wiki/User:Chris_73|Chris 73]] at Wikimedia Commons. [[https://de.wikipedia.org/wiki/Datei:NautilusCutawayLogarithmicSpiral.jpg|Link]]  | 
|   |   | 
|   | ====== 002: Zahlenspirale ======  | 
|   |   | 
|   | | Serie | [[treffen:codegolfing|CodeGolfings]] |  | 
|   | | Von | [[user:nopx|nopx]] |  | 
|   | | Datum | 06.Januar 2017 |  | 
|   | | Download | {{ :treffen:20171216_codegolfing_002.pdf |Aufgabenbeschreibung [pdf]}} |  | 
|   | | Schweirigkeit | {{:treffen:problemsolving:progress3.png?nolink&160 |}} |   | 
| **Eingabe**:  | **Eingabe**:  | 
| <code> | <code> | 
| testcasesEchoString = [ | testcasesEchoString = [ | 
|   {"name": "1", "n": 1,"result": "1\n"}, |   {"name": "1", "n": 1,"result": "1\n"}, | 
|   {"name": "2", "n": 2,"result": "1-2\n--\n"}, |   {"name": "2", "n": 2,"result": "1-2\n---\n"}, | 
|   {"name": "5", "n": 5,"result": "1-2-3\n----4\n----5\n"}, |   {"name": "5", "n": 5,"result": "1-2-3\n----4\n----5\n"}, | 
|   {"name": "13", "n": 13,"result": "-1--2-3-4\n12-13---5\n11------6\n10--9-8-7\n"}, |   {"name": "13", "n": 13,"result": "-1--2-3-4\n12-13---5\n11------6\n10--9-8-7\n"}, | 
| ] | ] | 
| </code> | </code> | 
|   |  | 
|   |  | 
|   | ==== Lösungen ==== | 
|   | === Max (Perl) 470B === | 
|   | {{ :treffen:document.pdf |Beschreibung.pdf}} | 
|   | <code> | 
|   | use POSIX;$n=$ARGV[0];$d=ceil sqrt$n;sub v($$){$_[$_[0]<$_[1]]}sub c($$){$_[$_[0]>$_[1]]}sub len{1+length@_[0]}sub g{($x,$y)=@_;$s=0;$l=c(c($x,$y),$d-v($x,$y)-1);$s+=v(1,4*$d-8*$_-4)for 0..$l-1;$u=$d-2*$l;$a=$y-$l;$b=$x-$l;$s+=$a==0?($b+1):$b==$u-1?($u+$a):$a==$u-1?(3*$u-$b-2):$b==0?(4*$u-$a-3):0;$s>$n?0:$s;}for(0..$d-1){$z=$_;for(0..$d-1){$q=$_;$m=0;$g=g($q,$_),$m = $g>$m?$g:$m for 0..$d-1;$j=g($_,$z);print"-"x(($_!=0)+len($m)-len($j));print$j!=0?$j:'-';}print$/;} | 
|   | </code> | 
|   |  | 
|   | <code> | 
|   | use POSIX; | 
|   |  | 
|   | $n=$ARGV[0]; | 
|   | $d=ceil sqrt$n; | 
|   |  | 
|   | sub v($$){$_[$_[0]<$_[1]]} | 
|   | sub c($$){$_[$_[0]>$_[1]]} | 
|   | sub len{1+length@_[0]} | 
|   |  | 
|   | sub g { | 
|   | 	($x,$y)=@_; | 
|   | 	$s=0; | 
|   | 	$l=c(c($x,$y),$d-v($x,$y)-1); | 
|   | 	$s+=v(1,4*$d-8*$_-4) for 0..$l-1; | 
|   |  | 
|   | 	$u=$d-2*$l; | 
|   | 	$a=$y-$l; | 
|   | 	$b=$x-$l; | 
|   |  | 
|   | 	$s+=$a==0?($b+1):$b==$u-1?($u+$a):$a==$u-1?(3*$u-$b-2):$b==0?(4*$u-$a-3):0; | 
|   | 	$s>$n?0:$s; | 
|   | } | 
|   |  | 
|   | for(0..$d-1) { | 
|   | 	$z=$_; | 
|   | 	for(0..$d-1) { | 
|   | 		$q=$_; | 
|   | 		$m=0; | 
|   | 		$g=g($q,$_),$m = $g>$m?$g:$m for 0..$d-1; | 
|   | 		$j=g($_,$z); | 
|   | 		print"-"x(($_!=0)+len($m)-len($j)); | 
|   | 		print$j!=0?$j:'-'; | 
|   | 	} | 
|   | 	print$/; | 
|   | } | 
|   | </code> | 
|   |  | 
|   |  |