# Tag Info

17

Befunge-93 - 404 371 361 352 339 337 323 bytes <xyXYvp01<>110vv5_v#0+1:_v#+!-"g"\<v"<":::<>1v#p03-1_>! g20gp00g1+0v25p v2g02 < p0 20p<+vp020p01-10$_:"p"-!^>>-!\ v^ <>0p20pv|!*-";"\+1::~p0< v2-10<^v# ^#< <<$< < ^+!-"_"\+!-"?"<&...

10

Python 3, will score later from collections import defaultdict from functools import lru_cache import sys NUMERIC_OUTPUT = True @lru_cache(maxsize=1024) def to_befunge_num(n): # Convert number to Befunge number, using base 9 encoding (non-optimal, # but something simple is good for now) assert isinstance(n, int) and n >= 0 if n == 0: ...

9

When using a multi-line loop, try to use as much of it as possible: >1234....v ^ < vs >1234v ^....<

9

Need to drop a value after a conditional (e.g. because the other path depends on the value, but this one doesn't)? Instead of using >$or$<, take advatage of the fact that you know the truth value of the variable and use _ instead to both change direction and pop stack. Example '* : v >$.. @ Prints number in binary followed ... 8 Don't forget that 0 is always on the stack. For example, this means that, with an empty stack, g is equivalent to 00g and p is equivalent to 000p. 6 If you need to push a number larger than 15, use ' to fetch the ASCII value of the next character: '* to push 42 rather than: 4a*2+ 6 Befunge-98, 4 ~,#@ Try it online! It works because ~ acts like r when there is no more input (credit to David Holderness for finding this in the funge-98 spec) 5 Instead of using |, requiring another line (often with many extra spaces), try using j. For example: 01-j@more code here would stop if the number on top of the stack was negative and continue onward otherwise. If you need multiple characters, use n*j where n is the number of characters you need when the value passed to j is 0. Example: 01-4*j01-*more ... 5 In Befunge-93, if the first thing you're pushing onto the stack is a string, you can often get away with dropping the opening quote. For example this: "!iH",,,@ could be simplified to this: !iH",,,@ Try it online! What's happening is the interpreter first tries to execute the characters in the unquoted string. The ! performs a harmless not, and the i ... 5 JavaScript (V8), 134 bytes f=D=>eval('for(w=D[c=x=y=X=0].length,h=D.length;c--||(c=D[y][x],D[y][x]=f,c>2?c=[,X=c-4]:c<f);y=(--t%2+y+h)%h)x=-(t=X,--t%2-x-w)%w;c') Try it online! Optimized from tsh's, input map {"A":"a","B":"b","<":"6",">":"4","^":"5&... 5 JavaScript (V8), 218 bytes -3 thanks to @Arnauld d=>eval('x=y=r=0,p=[],q=1;while(((m=d[y][x])-6)*(m-7)*!p.includes(w=x+[,y])){p.push(w);[q,r]=[[0,-1],[1,0],[0,1],[-1,0],[q,r],[q,r]][m];x=(x-q*~(m==5)+(z=d.length))%z;y=(y-r*~(m==5)+(z=d.length))%z};"AB"[m-6]||"T"') Try it online! 5 7 solutions, 26 points I'm typing this on my phone, because I don't have access to my computer currently. I actually had to work out Puzzle 6 by pen & paper. Puzzle 1 (Score 3): 4f52d5b243 1v v:< < >.1+:56+-| @ This one is fairly straight forward. Get a 1 on the stack, then print-increment-compare-loop until 11 is hit. Puzzle 2 (... 5 Charcoal, 55 bytes ＷＳ⊞υ⪪ι¹≔⁰θＷ¬№αψ«≔§§υⅉⅈψ§≔§υⅉⅈTＦ№>^<vψ≔⊗⌕>^<ψθＭ⊕⁼#ψ✳θ»⎚ψ Try it online! Link is to verbose version of code. Takes input as a newline-terminated list of strings and outputs A or B, or T for a tie. Explanation: ＷＳ⊞υ⪪ι¹ Input the map and split it into characters. ≔⁰θ Start off facing right. Ｗ¬№αψ« Repeat while the last seen ... 4 JavaScript (V8), 125 bytes a=>eval("for(d=5,w=a[x=y=0].length,h=a.length;(c=a[y%=h][x%=w])<9;d%2?x+=w+m:y+=h+m)a[y][x]='T',d=c>2?c:d,m=(d%3-1)*-~!+c;c") Try it online! '<': '3', '^': '6', '>': '5', 'v': '8', '.': '2', '#': '0', 'A': 'A', 'B': 'B', 4 In Befunge-93, the character input command (~) can often be used as a shortcut for -1, since that is the value it returns on EOF. As an example, the code below will output -1: ~.@ Try it online! This is not recommended in production code, since when run in an interactive environment, the program would pause and wait for user input. And obviously if the ... 4 In Befunge-93, it can often be advantageous to flatten a loop into a single line, with the loop section of code being executed in both directions. For example, consider the code below, which outputs the letter a eight times: "a"9>1-:#v_@ ^\,:\< This can flatten be flattened into a single line by interspersing the loop sequence with bridge ... 4 Python 3.8, 134 bytes f=lambda s,r=0,c=0,d=5,*v:(g:=s[r][c])//9+((r,c)in v)or f(s,(r+(d:=g%8or d)//3*(k:=g//8+1)-k)%len(s),(c+d%3*k-k)%len(s),d,*v,(r,c)) Try it online! Takes advantage of the looser input/output formats. In particular the input grid is mapped in the following way: { '^': 1, 'v': 7, '<': 3, '>': 5, '#': 8, '.': 0, 'A': 18, 'B': 27 }... 3 4 solutions, 15 points I hope I didn't mess up the trailing whitespace anywhere when generating the hashes. Puzzle 1 (Score 3): de1de4c4c8 v v< > >1+:.:9!| @ Puzzle 3 (Score 5): 071cad0879 "!dlroW"v >,,,, ,,v , " , , o l , l , e " @ ^,"H" < ... 3 APL(Dyalog Unicode), 149 147 bytes SBCS p v o g←(1 1)(0 1)⍬⎕ l←{v⊢←0 ¯1} r←{v⊢←0 1} u←{v⊢←¯1 0} d←{v⊢←1 0} b←{o,←⊂p⋄p+←v⋄p⊢←1+(⍴g)|p-1} {o∊⍨⊂p:'T'⋄'.'=⍨x←p⌷g:b⍵⋄x∊⎕A:x⋄⍎x,'⍵⋄b⍵'}⍣{⊃⍵∊⎕A}0 Try it on APLgolf! A tradfn submission which takes the grid as a character matrix. I'm sure there's multiple places to improve this. ><^v# → rludb and the rest of ... 3 J, 116 bytes g=.1#.,@] f=._3 g@{[:,/]((*0&=),:[(]]](2*[)`[@.(|@g*4>|@g)(*0&~:))](%|)@|.~0j_1+.@*(*4>|)@g)/^:a:@,:]{:@,:0,~0{,^3~:, Try it online! Will try to add explanation later. The concept is more elegant than the J itself for this one. 3 Output by exit code, where this is an allowed output form. If the challenge asks you to print one number, you can save a byte by ending the program with q instead of .@ 3 Don't forget that 0k does not execute the next instruction. This means that instead of doing: ;some boolean test;!jv;code if false; ;code if true;< You can save a character by doing ;some boolean test;kv;code if false; ;code if true;< 3 Use the direction of the IP when dealing with _ or |, rather than using an extra character for !. Real example (from this post): #v~ ,>:!#@_ Can be changed to #v~ :<,_@# 3 C (gcc), 853 815 801 787 770 bytes #define z(a,b);a(){b;} S[1<<20],*s=S,x,y,m,r,c=-1,t;Mz(b,*s=!*s)z(G,m=1)z(k,c+=x;r+=y)z(H,s--)z(E,*--s%=s)z(K,scanf("%d",++s))z(B,*--s*=s)z(A,*--s+=s)z(i,putchar(*s--))z(a,*--s-=s)z(I,printf("%d ",*s--))z(d,*--s/=s)z(g,1[s++]=*s)z(L,x=-1;y=0)z(R,x=1;y=0)z(w,t=*--s;*s=*++s;*s=... 2 Don't forget about the k operator. Instead of "!dlroW olleH",,,,,,,,,,,,@, do "!dlroW olleH"bk,@. Note that k does the operation on the cell that it is at so 9k, would print not 9 times but 10; 9 times with the k, and once with ,. 2 AWK, 267 258 bytes R=NR,C=NF{for(j=0;k=$++j;v=v?v:k)b[R][j]=k!="."?k:0}END{c=d=f=1;a["^"]=-3;a["v"]=3;a[">"]=4;a["<"]=-4;s["A"]=s["B"]=1;for(s--;y=="#"||!s[v];z=s[v=b[d][f]]>0?v:"tie"){y=="#"?0:w=a[v]?g=c=a[v]:b[d][f]=1;d=(d+=g%2)?d>R?0:d:R;f=(f+...

2

Python 3, 221 bytes def f(g,*a):x,y,a,b,s=a or[0,0,1,0,[]];c=g[y][x];k=(c=="#")+1;a,b=c in".#"and(a,b)or[(1,0),(0,1),(-1,0),(0,-1)][">v<".find(c)];return"T"if(x,y)in s else c in"AB"and c or f(g,(x+a*k)%len(g),(y+b*k)%len(g),a,b,s+[(x,y)]) Try it online! Perfectly ties Redwolf's JS, by pure ...

1

As little white space as possible. If you have a 10x5 (50) code, can you make it into a 6x8 (48): some code goes here and it is exactly 50 characters goes to put a bi t of cod e here a nd count all of 4 0 chars!

1

Use String Mode to Allow the IP to Pass Through Other Code If you need the IP to get from here to there and there's a bunch of existing and unmovable code in the way in every direction, just push a 0, go into string mode, pass through the code, come out of string mode, and pop all the garbage before continuing. This trick employed in Wim Rijnder's Wumpus ...

1

Merge branches as soon as possible If two or more code branches are merging together and they all end with the same sequence of instructions, you can merge them immediately before the instructions they have in common. This is a fairly common circumstance to be on the lookout for. As an example, I have this subprogram for reading input onto the playing field ...

Only top voted, non community-wiki answers of a minimum length are eligible