New answers tagged

4

JavaScript, 946 bytes i=>i.split(/\n *\n/).slice(n=0,-1).map(x=>[...(x=x.split` `)[0]].map((_,i)=>parseInt([0,1,2,3,4].map(j=>"_/\\|".indexOf(x[j][i])+1).join(""),5)).map((n,i,x)=>o[x.slice(i).map(a=>v=v*5+a,v=0).find(v=>o[v])]||"").join``," ...


0

Nim, 107 bytes import os,terminal var f=0 while 0<1:eraseScreen();sleep 999;echo ["_o_\n 0 \n/ \\","\\o/\n_0_\n"][f];f=1-f Don't Try it online!


4

Dash, 67 bytes Also bash, ksh, zsh, ash, yash and probably many more besides. While it apparently works in these other shells, their own features and idiosyncrasies may allow for further golfing. I'll leave that as an exercise for the reader. Notably not fish or tcsh. f(){ clear;echo "$1";sleep 1;f "$2" "$1";};f '_o_ 0 / \' '...


3

Python 3, 110 109 bytes Down to 109 thanks to att def f(l,p='',a=0,o=0): x,c=l;print(p+(('+L'[o]+'-- ')*a)+x) for i in c:f(i,p+('| '[o]+' ')*a,1,c[-1]is i) Call as: f(["kingdom",[["mineral",[]],["animal",[["dog",[["schnauzer",[]],["whippet",[]]]]]],["vegetable",[["cabbage",[]...


1

TI-Basic, 58 56 bytes While 1 ClrHome If not(Ans Disp "_o_"," 0","/ \ If Ans Disp "\o/","_0_" not(Ans If dim(rand(70 End -2 bytes for assuming that the code is run on a fresh interpreter.


4

Perl 5, 146 bytes sub f{my$r=@_-1;my$p=$r?pop:[];while(my$n=shift){my($t,$c)=@$n;say$r?((map$_?'| ':$"x4,@$p),@_?'+':L,'-- '):(),$t;f(@$c,[@$p,$r?!!@_:()])if@$c}} Try it online!


3

K (ngn/k), 96 bytes ` 0:4_'{r:o@x,y[1]," ";(,x,(*y),"-- ",*z),/$[z@1;("+|"r/:-1_z@1),"L "r/:-1#z@1;""]}["";" ";]@ Try it online! Quite a shame that this took so long, but I'm glad that I stuck with the problem. Recursive function which prints each line of the tree separately. ngn/k's ...


1

APL(Dyalog Unicode), 26 25 bytes SBCS Taking some inspiration from coltim's K answer. -1 byte thanks to Razetime! (⎕C⍪⊖)'RNBQKBNR'⍪8/⍪'P..' Try it on APLgolf! or Get some intermediate values APL(Dyalog Unicode), 30 28 bytes SBCS (⎕C∘⊖⍪⊢)⍉'..P'⍪⍤1⍪'RNBQKBNR' Try it on APLgolf! ⍪'RNBQKBNR' Make a 8x1 matrix of characters '..P'⍪⍤1 Prepend three columns made ...


2

Vyxal L, 17 bytes «æ≠⁺tO«ƛ`p..`+Ḃ⇧+ Try it Online! -1 thqnks to Aaron Miller. «...« # Compressed string `rnbqkbnr` ƛ # Map... `p..`+ # Append `p..` to each Ḃ # Duplicate, reverse ⇧+ # Uppercase the reversed copy and append # (L flag) vertical join (rotate 90°) at the end.


1

Vyxal C, 17 bytes »÷rṡF»S¦øṁ½ƛ÷⋎;øm Explanation »÷rṡF»S - 123456789 as string ¦ - Take all the prefixes øṁ - Vertical mirror ½ƛ÷⋎; - Halve and split, then join while removing the duplicate ends. øm - Horizontal palindromize. <C flag> - Center and ...


4

Vyxal J, 26 24 31 28 25 bytes -2 bytes thanks to the j flag. +7 bytes, added code to swap Q and K to make it valid. -3 bytes thanks to Aaron Miller! -3 bytes thanks to Kevin Cruijssen «æ≠⁺tO«\p8*\.8*:W⁋Ḃ⇧‛KQḂV Explanation «æ≠⁺tO« - Push "rnbqkbnr" \p8* - Push "pppppppp" \.8*: ...


1

JavaScript (V8), 65 bytes _=>`rnbqkbnr pppppppp `+`........ `.repeat(4)+`PPPPPPPP RNBQKBNR` Try it online! Explanation : _ => // beginning of function param is not needed so we do _ instead of () `rnbqkbnr pppppppp ` // first two lines are written better than doing line1+\n+line2+\n + // add to it `........ `...


3

Dash*, 69 bytes seq -- -8 8|xargs -I: sh -c 'seq -s"`printf "%:s_"`" 10'|sed s/_1*//g Hopefully this iteration is fairly self explanatory -- pretty much a straight swap of for to xargs. Try it online! Dash*, 87, 86, 73 bytes for p in `seq -- -8 8`;do seq -s"`printf "%${p}s_"`" 10;done|sed s/_1*//g Try it online! ...


1

TI-Basic, 40 35 bytes Input N ": For(I,0,N-1 Disp Ans If not(I ":- If I Ans+") End -5 bytes thanks to MarcMush -3 bytes if the input is already stored in Ans instead of having to use Input N.


1

APL(Dyalog Unicode), 20 bytes SBCS {,\⍵⍴':-',')'⍴⍨|⍵-2} Try it on APLgolf! Monadic function {...} monadic function, takes n on right ⍵-2 n minus 2 | abs (No. of braces, call it x) ⍨ swap x with ')' brace for ⍴ dyadic reshape to get x braces , concat with ':-' smiley head ⍵⍴ take first n (monadic reshape) ,\ prefixes (ravel scan)


4

jq -nr, 55 bytes range(17)-8|fabs|" "*.+"123456789"[:9-.]+"87654321"[.:] fabs is not supported on TIO but you can try it on https://jqplay.org/. Alternatively try it on TIO with .*.|sqrt instead of fabs, for 59 bytes.


4

jq -rn, 76 65 60 59 bytes -6 bytes thanks to ovs and another -6 (plus -5 more indirectly) thanks to Michael Chatiskatzi def r:range(9),7-range(8);r|[8-.-r|"\(" "*.//1-.)"[:1]]|add Try it online! Explanation The -n flag specifies that there is no input; the -r flag outputs the result strings, each on its own line, without quotes. def r: ...


2

jq -r, 47 41 39 bytes -2 bytes thanks to Michael Chatiskatzi . as$n|range(.),0|" "*($n-.)+"**"*.+"*" Try it online! Add 2 bytes if a leading space is not acceptable. . as$n Store the input number in $n | With that number as . range(.) ...


0

Excel, 80 bytes =CONCAT(LET(x,ABS(9-ROW(1:17)),y,9-ABS(9-COLUMN(A:R)),IFS(y>x,y-x,y," ",1," "))) Link to Spreadsheet


1

Excel, 74 bytes =LET(x,MOD(COLUMN(A:J),10),CONCAT(x&IF(x,REPT(" ",ABS(ROW(1:17)-9))," "))) Link to Spreadsheet The version without LET that would have been valid when the question was asked is only 2 bytes longer. Without LET, 76 bytes =CONCAT(RIGHT(COLUMN(A:J))&IF(COLUMN(A:J)>9," ",REPT(" ",ABS(ROW(1:17)-9)...


0

Java (JDK), 105 103 bytes a->{for(int j,i=-9;i++<8;){var s="";for(j=0;j++<9;)s+=j+" ".repeat(i<0?-i:i);System.out.println(s+0);}} Try it online! Thanks to ceilingcat for -2


1

Deadfish~, 2606 bytes ioi{iii}cccccccc{ddd}o{iii}ccccccccd{ii}ci{dd}cccccccc{ii}c{dd}cccccccci{ii}cd{dd}ccccccccii{ii}cdd{dd}ccccccccd{{{i}}}odsddddcccccccc{{{i}}}oddsddddcccccccci{ddd}soiii{ii}cccccccc{{d}}o{i}ci{d}oi{iii}ccccccc{ddd}o{iii}cccccccd{ii}ci{dd}ccccccc{ii}c{dd}ccccccci{ii}cd{dd}cccccccii{ii}cdd{dd}cccccccd{{{i}}}odsddddccccccc{{{i}}}...


4

jq -nr, 50 46 45 bytes [range(9)+1,0|@sh]|join(range(17)-8|" "*fabs) Try it on jqplay! [range(9)+1,0|@sh] generates the array ["1", "2", ..., "9", "0"]. This list is then joined by each of the results from: range(17)-8: -8, -7, ..., 7, 8 " "*fabs a string of absolute value spaces


5

14 15 languages, 487 bytes brainfuck, Thue, Fission, Rail, Perl, ><>, Surface, Whitespace, Gol><>, Befunge-93, Hexagony, Python 3, PingPong, Cardinal, Ruby #\&v/,[.,][ .hzPSIv?:< #!oan-2l.1*8=;?(1:i::< # :< /2_0#!x%x2$:_.#-@#1: #>,>, \ # o->+o #/o? </ #&...


Top 50 recent answers are included