# Tag Info

1

Scratch 3.0, 11 blocks/92 bytes For those who are tired of the old way of introducing these answers (I'm looking at you a'_' (ಠ ͟ʖಠ) ), I'll put the ScratchBlocks Syntax first: define f(n if<(n)<(0)>then set[r v]to(-1 else if<(n)>(0)>then set[r v]to(1 else set[r v]to(0 I decided to use a function instead of the old when gf clicked ...

1

05AB1E, 2 bytes A signum built-in. .± Try it online!

2

Binary Lambda Calculus, 2.125 Bytes 00010110 00110001 0 Translation into lambda calculus: \n. n (\x. n) (\x. x)

1

Keg, 11 bytes (SBCS) Now I realized that Keg is pretty hard to use... ¿Ï_^'(Ï_')" Try it online!

0

GolfScript, 12 bytes ~),(;{),(;}% Try it online!

0

W j f, 3 bytes It's actually pretty trivial in W ... M_M Explanation a % Take an input, say 3 M % Identity map every item in numeric value 3 % Since it is prohibited, a range is generated, % namely [1 2 3] a M % For every item in [1 2 3]: % Note that single items are 1, 2, and 3, *not* the whole list a % Generate a ...

2

GolfScript, 4 3* bytes ~1| Try it Online! *thanks to user a'_'

1

Keg, -hr, 13 bytes :0<[0;|0>[1|0 Try it online! A very simple switch like comparison happening here.

2

naz, 46 bytes, score 32.2 2a2a1o2m1o7s1o5m1o2s2s1o6m1o2s2s1o1a1o1a1o2s1o Simply outputs each digit in 4815162342 one at a time.

1

naz, 70 bytes 2a2x1v4a8m2x2v1x1f1r3x2v2e1o3f0x1x2f1a1o0x1x3f1r3x1v4e1o3f0x1x4f0a0x1f Works for any input integer, provided it's passed as a file terminated with the control character STX (U+0002). Explanation (with 0x commands removed) 2a2x1v # Set variable 1 equal to 2 4a8m2x2v # Set variable 2 equal to 48 ("0") 1x1f1r3x2v2e1o3f # ...

1

Pyth, 18 numbers 579 t Another challenge where being infix rather than prefix would be nice. This uses the space to "hide" some of the numbers and the decrement to get more numbers. Here's all of the outputs. [ 57 t9 ] => '57' [ 57t 9 ] => '57\n8' [ 59 t7 ] => '59' [ 59t 7 ] => '59\n6' [ 5 7t9 ] => '5\n8' [ 5 9t7 ] => '5\n6' [ 5 t79 ] =&...

1

JavaScript I'm actually not sure it's possible. I suspect if a solution exists, it's purely arithmetic. So the content of any cell will be from this set 0123456789+-*/ ~!%^|&. I tried for several hours without success. The main problem is that for the last column (or row) to have any meaningful calculation, one of the rows (or columns) leading to it ...

14

Polyglot, 10x10 0 14 5 16 7 18 9 20 10 12 13 This yields the following row/column/diagonal programs (one per line): 0 01 0 2 3 4 5 6 7 8 9 10 011 12 13 0 ...

13

05AB1E, 4x4 5x5 8www4 w3Tαw Uw₃4< XθнĀ· wTwºß Try it online. (Loops over the rows; columns; main diagonal; and main anti-diagonal of the square, and will run it was 05AB1E code with .V, after which it discards everything that remains on the stack for the next iteration with )\.) Explanation: The w are no-ops, so I'll ignore them in the explanations ...

1

W, 5 numbers 3S*4+ The permutations can be printed by the following program, given that the Python interpreter is in your PATH. Don't count the preceding & trailing 0's as they are simply return codes: import itertools import os for i in list(itertools.permutations("3S*4+",5)): os.system("echo "+''.join(list(i))+">code.w") os.system("W.py ...

10

Jelly, A simple 3 by 3 Surely we can get a bigger one in Jelly, but if not... 5+2 +ḷ* 1+2 Try them online! (splits on new lines (Ỵ) and evaluates (V) each (€) as Jelly programs) 5+2 : 5 + 2 = 7 5+1 : 5 + 1 = 6 5ḷ2 : left(5, 2) = 5 2*2 : 2 ^ 2 = 4 1+2 : 1 + 2 = 3 2ḷ1 : left(2, 1) = 2 +ḷ* : left((0 + 0), 0) ^ 0 = 1 +ḷ+ : left((0 + 0), 0) + 0 = 0

13

Keg, 4x4 magic square 0601 7.92 3._. 8654 Try it online! Outputs 0601 - 1 7.92 - 7 3._. - 3 8654 - 4 /||||\ 98652 0 I can't believe this actually works! Programs need the -hr flag to properly output the required result. Test suite. Uncomment each line to run it. The -in flag is purely to make the test suite a nicer experience, as otherwise, the ...

0

Brainf*ck, 39 bytes Try it online! ,>,>,<[->+<]<[->>-<<]>,[->-<]>[-->+<]>. The input/output are the ASCII values of characters. Using "aaz0" gives "%" as output, as it corresponds to the case 97 122 97 48 which is solved by moving 37 units of liquid, the % symbol. Could shave a couple of bytes if the ...

1

Perl 6 Raku, 12 11 bytes (*-*-*+*)/2 Try it online! Edit: I realized that I could take the parameters in any order. Four parameters are: liquid in container 1, liquid in container 2, volume of container 1, volume of container 2.

1

naz, 64 bytes 9a5m2x1v3a2x2v1x1f1o0m1a1o0x1x2f1o0x1x3f1r3x1v1e3x2v2e0m1a1o0x3f Explanation (with 0x commands removed) 9a5m2x1v # Set variable 1 equal to 45 ("-") 3a2x2v # Set variable 2 equal to 48 ("0") 1x1f1o0m1a1o # Function 1 # Output once, set the register equal to 1, and output ...

0

PHP, 165 156 110 bytes $o=[$j=$i=$s=$m=0];for(;$i<strlen($n=$argn);)$o[]=$n[$i++]=='<'?++$m:--$s;for(;$j<=$i;)echo$o[$j]-$s,$n[$j++]; Try it online! Ungolfed <?php $min=0;$max=0; $current=0;$order = ; for ($i=0;$i<strlen($argn);$i++){ $compare=$argn[$i]; if ($compare=='<') { $max++;$current=$max; } ... 0 Haskell, 95 bytes s=show ('<':y)!(a:b)=s a++'<':y!b (x:y)!z=s(last z)++x:y!init z _!(y:_)=s y f x=x![0..length x] Try it online! 0 PHP, 50 bytes <?=array_sum(str_split(decbin($argn&-2^$argn*2))); Try it online! Unfortunately, really don't think I can get it any more golfed than this! The idea is to count transitions 1->0 or 0->1. 1 x86-16, IBM PC DOS, 47 bytes Binary: 00000000: 33c9 bd0a 0050 0bc0 7d09 50b8 2d0e cd10 3....P..}.P.-... 00000010: 58f7 d833 d2f7 f552 410b c075 f658 b40e X..3...RA..u.X.. 00000020: 0c30 cd10 e2f7 b020 cd10 5840 75d7 c3 .0..... ..X@u.. Build and test using xxd -r Unassembled listing: 33 C9 XOR CX, CX ; clear counter B3 0A MOV ... 1 C (gcc), 39 25 bytes f(a,b,c,d){a=b-d-a+c>>1;} Wrote a testing framework for possible future testcases. Takes as input 4 integers: a: capacity of first container b: capacity of second container c: amount of liquid in first container d: amount of liquid in second container Explanation: f(a,b,c,d) Function implicitly returning int with four ... 0 TI-BASIC, 26 21 bytes Prompt A,B,C,D:.5abs(A-C-B+D Input is a series of prompts for each value. A = volume1 B = volume2 C = liquid1 D = liquid2 Output is the amount of liquid that needs to be moved from the fuller container to the emptier one. Explantion: Prompt A,B,C,D ;Prompt the user to input the values .5abs(A-C-B+D ;Compute the amount of ... 1 C (clang), 29 28 bytes Saved a bytes thanks to meetaig!!! #define f(a,b,c,d)b-d-a+c>>1 Try it online! 1 Python 3, 27 26 25 bytes Saved a bytes thanks to meetaig!!! lambda a,b,c,d:b-d-a+c>>1 Try it online! 0 Retina 0.8.2, 19 bytes \d+;?$* +1,1 , 11 Try it online! Link includes test cases. Explanation: \d+;? $* Convert to unary and sum the middle two numbers. +1,1 , Subtract the outer numbers from that sum. 11 Divide by 2 and convert to decimal. 1 Excel, 16 bytes =(B1-D1-A1+C1)/2 Same approach as others 1 Whitespace, 79 bytes [S S S N _Push_0][S N S _Dupe_0][T N T T _Read_STDIN_as_integer][T T T _Retrieve_input_vol1][S N S _Dupe_input_vol1][S N S _Dupe_input_vol1][T N T T _Read_STDIN_as_integer][T T T _Retrieve_input_liq1][T S S T _Subtract_vol1-liq1][S N S _Dupe_vol1-liq1][S N S _Dupe_vol1-liq1][T N T T ... 1 Java 8 / CoffeeScript 2, 22 21 bytes (V,v,L,l)->v-l-V+L>>1 Port of @Grimmy's second 05AB1E answer. -1 byte by porting @Arnauld's approach, golfing the (...)/2 I had to ...>>1. Try it online in Java 8. Try it online in CoffeeScript 2. Explanation: (V,v,L,l)-> // Method with four integer parameters and integer return-type v-l ... 3 Jelly, 3 bytes ISH Try it online! A monadic link taking as its argument [[l1, v1], [v2, l2]] and returning the volume needed to move. A relatively rare ASCII-only Jelly answer! Explanation I | Increments S | Sum H | Half 2 Keg, 14 13 bytes -±¿-¿+½:0<[±] Try it online! A port of Arnauld's original javascript answer. Takes input in form of: volume1 container1 volume2 container2 -1 byte by utilising implicit input correctly. 5 05AB1E, 3 bytes ®β; Try it online! Input is an array of volumes in the order [first liquid, first container, second container, second liquid]. Alternative 3-byter: ÆÆ; Try it online! Input is a nested array: [[first container, first liquid], [second container, second liquid]]. 7 JavaScript (ES6) / C#, 21 bytes (v,V,q,Q)=>V-Q-v+q>>1 Try it online! (JS) Try it online! (C#) 1 Javascript (node.js), 94 bytes Try it online s=>[,...s].reduce((x,v,i)=>v>'<'?[...x.map(v=>v+1),0]:[...x,i]).reduce((x,v,i)=>x+s[i-1]+v) Ungolfed: s => [,...s].reduce((x, v, i) => v > '<' ? [...x.map(v => v + 1), 0] : [...x, i]) .reduce((x, v, i) => x + s[i-1] + v) 0 Burlesque, 122 bytes pe'1'9r@3co{".-"".*""./"}z[)FL{'0'0'.".+"}+]j{{}{tp}{)<-<-}{tp)<-}}j!!e!<-Ppra{pPj<-d!}msJ'=_+j{><}gB3co{rtp^}mwpe?+'.;;++ Try it online! Takes args as: "[[1,2],[2,3],[0,3],[1,0],[1,1]]" 3 pe # Push args to stack '1'9r@ # Range of characters [1,9] 3co # Split into ... 0 Burlesque, 38 bytes sarzPp{J'>=={PPl_}{PPg_j}x/iePp}]mPP?+ Try it online! Using xnor's algorithm sarz # Generate range [0,N_comp] Pp # Push this into state stack { J'>== # Non destructive test if is ">" {PPl_}{PPg_j}x/ie # If it is, take the head of the range ... 0 05AB1E, 57 54 bytes εžm3ôí…/*-ø"00.+"ª€SIFøí}yθèyнè}JD'=s.γžh'.«så}R2ôR».VJ Uses 0-based coordinates similar as the challenge description, and [0,1,2,3] for [0,90,180,270] respectively as inputs. Try it online or verify all test cases. Explanation: ε # Map over each of the (implicit) input-coordinates: žm # Push ... 1 PHP, 267 235 229 225 221 213 bytes <?php$t=[1,12,15,4,1];$j=$t[$k=$argv];($o=$i=$t[$k+1])<5&&$o--;foreach(json_decode($argv)as$c){echo$s='/*-+963.85207410'[($c*$i+$c*$j+$o)%16];strpos(' /*-+',$s)&&$e="($e)";$e.=$s;}eval("echo'=',$e;"); Try it online! 6 bytes thanks to @Kevin Cruijssen. Input directions are: 0 is 0, 1 is ... 0 05AB1E, 13 bytes €NIgª'<¡íJ'<ý Port of @MartinEnder's CJam answer, so make sure to upvote him as well! Try it online or verify all test cases. Explanation: €N # Insert the 0-based index before each character of the (implicit) # input-string, which also converts the input-string into a list Ig # Push the input ... 0 APL, 13 characters/bytes +/2≠/0,2⊥⍣¯1⊢ base 10 to base 2 conversion with all necessary digits 2⊥⍣¯1⊢ 2⊥⍣¯1⊢4812390 ---> 1 0 0 1 0 0 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 add a leading 0 0, 0,1 0 0 1 0 0 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 ---> 0 1 0 0 1 0 0 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 pair-wise reduction that gives 1 if consecutive elements are ... 2 Burlesque, 8 bytes rib2gnL[ Try it online! ri # Read as integer b2 # Convert to binary gn # Collapse like bits L[ # Find length 29 bytes ri0j{j+.j2dg)n!2ug}{^^nz}w!vv Try it online! Actually doing the calculation ri #Read val as int 0j #Push a 0 (counter) to the bottom of the stack { j+.j # Increment counter and put back 2dg ... 0 PHP, 55 52 bytes for($i=$argn;$i;$c++,$i^=(1<<log($i,2)+1)-1);echo$c; Try it online! All done arithmetically/bitwise (no strings). Am stuck getting it smaller than the 51 byte answer though...

1

Python 3, 207 bytes def s(n): p=1 while n>=2*p: p*=2 return n if n<=p else s(n+p//2)if n>=3*p/2 else s(m)if (m:=s(n-p)+p)!= n else n a=lambda n,m:(b:=n&m)>-1 and s(a(a(a(s((n|m)-b%4),b//4*2),b//4),b%4*2+b%4//2))if m else n Try it Online! (Verify all test cases) Explanation This program directly manipulates the binary translations of ...

2

Keg, 4 bytes :0=+ Try it online! Explanation ¿: # Take 2 inputs 0= # Check whether the input is 0 # (Yields 1 if the input is 0) # (Yields 0 otherwise) + # Add the input with this result # i.e. 0->1, 5->5

1

W, 2 bytes 1| Explanation a # Take an input 1| # Logical or with 1 # If n is 0, this evaluates to 1 # It evaluates to 0 otherwise

Top 50 recent answers are included