Quantcast
Channel: The (Easy) Road to Code - Code Golf Stack Exchange
Browsing latest articles
Browse All 26 View Live

Answer by emanresu A for The (Easy) Road to Code

Vyxal, 91 bytes£:0=[¥(n₂[`| | |`|`| |`],)|1=[¥(ðn*n₂[`\ \ \\`|`\ \\`]+,)|¥(ð¥‹n-*n₂[`/ / /`|`/ /`]+,Try it Online!A little better.

View Article



Answer by Oliver for The (Easy) Road to Code

Japt-R, 40 bytesÆ=Vg"|\\/";²i1S+iX%2?S:U)iSp[TZÊ-YY]gVÃwTry it online!Explanation:Æ=Vg"|\\/";²i1S+iX%2?S:U)iSp[TZÊ-YY]gVÃw // U = road size // V = directionÆÃ // Loop X through [0...U] = ; // Set U...

View Article

Answer by dzaima for The (Easy) Road to Code

Canvas, 23 22 bytesB}⁴H‟m↶⁷?/|∙/╋]\|∙\╋]}Try it here!Uses the direction inputs 0, 1 and 2.Explanation:...‟ push "--¶¶- ¶¶--" m mold the horizontal length to the 1st input - a horizontal road↶ rotate...

View Article

Answer by Olivier Grégoire for The (Easy) Road to Code

Java (JDK), 116 bytesd->n->{for(int c="\\|/".charAt(d),i=n;i-->0;)System.out.printf("%"+(d<1?n-i:d>1?i+1:1)+"c%2c %c%n",c,i%2<1?c:32,c);}Try it online!Takes d as one of 0, 1 or 2.

View Article

Answer by Spencer D for The (Easy) Road to Code

Ruby, 90 bytesn,a=*$*.map{|i|-i.to_i}c='|\/'[a]n.upto(-1){|i|puts''*(i*a-n)+c+''+['',c][i%2]+''+c}Try it online!UPDATE: Thank you, Kevin, for pointing out that my original submission was missing spaces...

View Article


Answer by nwellnhof for The (Easy) Road to Code

Perl 6, 66 bytes->\n,\d{{(''x--$ *d%-+^n~('',<\ | />[d+1])[1,(n+$++)%2,1])xx n}}Try it online!Returns a list of lines.Explanation->\n,\d{ } # Block taking n, d { } # Reset $ variables ( )xx...

View Article

Answer by palme for The (Easy) Road to Code

Swift 4.2, 112 108 bytes-4 bytes thanks to Sriotchilism O'Zaiclet c=["\\","|","/"][d];(0..<n).map{print((0..<n-$0*(d-1)).map{_ in""}.joined()+c+" \($0%2==0 ?c:"") "+c)}[0,1,2] instead of...

View Article

Answer by xnor for The (Easy) Road to Code

Python 2, 66 bytesn,d=input()s=''+'|\/'[d]for c in(s*n)[n:]:print''*n+s,c+s;n+=dTry it online!Uses d=-1 for NE, d=0 for N, and d=1 for NW. Takes advantage of leading spaces being allowed. The rule that...

View Article


Answer by recursive for The (Easy) Road to Code

Stax, 23 bytesù╒←∩♂2Ωⁿ¡├∩22♀Ç○=÷â╧δÖ↑Run and debug itInput is two integers separated by a space.The first is d. -1 specifies north-east. 0 for north. 1 for north-west.The second parameter is n.These...

View Article


Answer by Gymhgy for The (Easy) Road to Code

C# (Visual C# Interactive Compiler), 129107103 93 bytesa=>b=>{for(char i=a,W="/|\\"[b+1];i>0;)Write("{0,"+(a-i*b+5)+"} {1} {0}\n",W,--i%2<1?W:'');}-1 for north-east, 1 for north-west, 0 for...

View Article

Answer by user73921 for The (Easy) Road to Code

perl -M5.010 -Mfeature=signatures, 97 bytessub f($n,$d){$x=qw[| / \\][$d];say""x($d<1?$_*-$d:$n-$_),$x,$",($n-$_)%2?$":$x,$",$x for 1..$n;}

View Article

Answer by Jonathan Allan for The (Easy) Road to Code

Jelly,  31  30 bytes⁶ẋẋƤḂ};€ị“\/|”ẋ3KƊ}Ṛ⁹¡⁶-2¦€ÐeṚA dyadic Link accepting the length on the left and the negated-direction* on the right which yields a 2d array of characters.* [north-west, north,...

View Article

Answer by Gymhgy for The (Easy) Road to Code

Japt, 53 bytesW="|/\\"gV;Æ"{W} {YÉ %2?W:' } {W}"ùVÄ?V?Y+5:5:U-Y+4ÃwTry it Online!

View Article


Answer by Galen Ivanov for The (Easy) Road to Code

Red, 157 bytesfunc[s d][p: pick"\|/"d set[a b]reduce pick[[4 1]0[5 + s -1]]d repeat n s[print pad/left form reduce pick[[p""p][p p p]]odd?(n + pick[1 0]odd? s)a: a + b]]Try it online!1 North-West2...

View Article

Answer by Rene for The (Easy) Road to Code

1. Python 3.5, 122 120 bytesScript takes two params: n, d.d: 0, 1, 2 -> \ | /tio.runimport sys;(n,d)=[*map(int,sys.argv[1:3])];c="\\|/"[d]for i in...

View Article


Answer by ovs for The (Easy) Road to Code

Python 2, 93 bytesn,d=input();p=''while n:g='|/\\'[d];n-=1;print['',''*n,p][d]+g+' %s '%(g,'')[n%2]+g;p+=''Try it online!

View Article

Answer by Giacomo Garabello for The (Easy) Road to Code

C (gcc), 100 90 bytesf(a,b,c,d){for(c=a,d="\\|/"[b+1];c--;)printf("%*c %c %c\n",b>0?c+1:b?a-c:0,d,c%2?32:d,d);}Try it online!Well written version

View Article


Answer by Neil for The (Easy) Road to Code

Charcoal, 3329 23 bytes↷NNη⊘⊕ηUE¹¦¹F⟦²±²⟧«Jι⁰ηTry it online! Link is to verbose version of code. Now that all of the underlying Charcoal bugs seem to be fixed I can advertise the optimal code....

View Article

Answer by t-clausen.dk for The (Easy) Road to Code

TSQL code, 171 117 bytesI realized this could be written much shorter as code.DECLARE @n INT=7,@d INT=0,@...

View Article

Answer by Galen Ivanov for The (Easy) Road to Code

J, 64 bytes' \|/'{~(_2&|*[:i.[*1 _1{~3=])|."_1((5+[){."1(5,~[)|.@$]*#:@689)Try it online!1 North-West2 North3 North-EastWill try to golf it later

View Article

Answer by Veskah for The (Easy) Road to Code

PowerShell, 88828074 71 bytes-8 bytes thanks to Mazzy-6 bytes thanks to AdmBorkBork and Mazzy-3 bytes thanks to AdmBorkBorkparam($n,$d)$n..1|%{''*($_,($n-$_))[$d]+($y='/\|'[$d])," $y"[$_%2],$y}Try it...

View Article


Answer by Adam for The (Easy) Road to Code

Kotlin, 96 92 bytes{n,d->val c="\\|/"[d];(0..n-1).map{println("".repeat(n-it*(d-1))+"$c ${" $c"[it%2]} $c")}}Accepts [0, 1, 2] instead of [-1, 0, 1]It works similarly to solutions in other...

View Article


Answer by Henry T for The (Easy) Road to Code

Python 2, 127 bytesn,d=input()c='|/\\'[d]for i in range(n):t=0if d==0else(i if d<0else n-i);print(''*t+'{} {} {}'.format(c,''if i%2==0else c,c))Try it online!First two lines taken from @TFeld.

View Article

Answer by TFeld for The (Easy) Road to Code

Python 2, 797873 72 bytesn,d=input()c='|\/'[d]i=nwhile i:print''*(n-i*d)+c,i%2*c or'',c;i-=1Try it online!Takes [1,0,-1] for [north-west, north, north-east]-1 byte, thanks to Neil

View Article

Answer by Arnauld for The (Easy) Road to Code

JavaScript (ES8),  90 87  85 bytesTakes input as (direction)(length). Expects \$0\$ for North-West, \$1\$ for North or \$2\$ for North-East.d=>g=(n,w=n)=>n?(c='/|\\'[d]).padStart([n--,,w-n][d])+`...

View Article


The (Easy) Road to Code

Input:An integer \$n\$, which is guaranteed to be \$\ge3\$.An integer \$d\$, which is one of \$[-1,0,1]\$.Output:A road of size \$n\$, which will be in a north-west direction if \$d=-1\$; a north...

View Article
Browsing latest articles
Browse All 26 View Live




Latest Images