Hot answers tagged

1101

This began as a quest but ended as an odyssey. Quest for Tetris Processor, 2,940,928 x 10,295,296 The pattern file, in all its glory, can be found here, viewable in-browser here. This project is the culmination of the efforts of many users over the course of the past 1 & 1/2 years. Although the composition of the team has varied over time, the ...


778

Part 2: OTCA Metapixel and VarLife OTCA Metapixel (Source) The OTCA Metapixel is a construct in Conway's Game of Life that can be used to simulate any Life-like cellular automata. As the LifeWiki (linked above) says, The OTCA metapixel is a 2048 × 2048 period 35328 unit cell that was constructed by Brice Due... It has many advantages... including the ...


747

Part 3: Hardware With our knowledge of logic gates and the general structure of the processor, we can start designing all the components of the computer. Demultiplexer A demultiplexer, or demux, is a crucial component to the ROM, RAM, and ALU. It routes an input signal to one of the many output signals based on some given selector data. It is composed of ...


709

Part 4: QFTASM and Cogol Architecture Overview In short, our computer has a 16-bit asynchronous RISC Harvard architecture. When building a processor by hand, a RISC (reduced instruction set computer) architecture is practically a requirement. In our case, this means that the number of opcodes is small and, much more importantly, that all instructions are ...


665

Part 6: The Newer Compiler to QFTASM Although Cogol is sufficient for a rudimentary Tetris implementation, it is too simple and too low-level for general-purpose programming at an easily readable level. We began work on a new language in September 2016. Progress on the language was slow due to hard to understand bugs as well as real life. We built a low ...


81

JavaScript (ES6),  26 23 17 15  14 bytes Takes input as two ASCII codes in currying syntax (a)(b). Returns 4 for friends or 0 for foes. a=>b=>a*b/.6&4 Try it online! How? NB: only the integer quotient of the division by 0.6 is shown below. Combo | a | b | a*b | / 0.6 | AND 4 ------+----+----+------+-------+------ WU | 87 | 85 |...


77

Groovy, 67 56 50 Bytes {a,b->Math.sin(1.3*((int)b[0]-(int)a[0])).round()} Try it online! Turns out that the rock, paper, scissors game has a pretty cool property. Given strings a and b, take the first letter of each, this results in two of the following: R,P,S The exhaustive list of possible values are (When 2 choices are combined): XX=ASCII=Y=Wanted ...


64

Perl 6, 36 30 bytes {<Spock Lizard Rock>[.comb%4]} Try it online! Gets each output based on the length of the input modulo 4. I think this is probably the optimal strategy.


60

Python, brainfuck and JavaScript, 103 99 bytes Yay under 100 bytes! 0,[.5,];p=["rock","scissors","paper"] 1//1;lambda x:p[p.index(x)-1];""" x=>p[-~p.indexOf(x)%3]//""" In Python, this defines a function which beats the input, in brainfuck it's just a simple cat program, and in JavaScript it loses. Here's a version which gives the functions a name, f, ...


52

Blue Team - SphiNotPi3000 // Char 0: top or bottom ("T" or "B") // Char 1, 2: x/y coords // Char 3, move polarity // Char 4: offset (as codepoint - 128) var twin = 21487; var myself = 2867; var formpos = "T"; var tochar = String.fromCharCode; var movestat = (move % 2).toString(); var inbox = getMsg(twin); // Spoofing the message of a deceased partner if ...


49

Blue Team - SphiNotPi3000 // Char 0: top or bottom ("T" or "B") // Char 1, 2: x/y coords // Char 3, move polarity // Char 4: offset (as codepoint - 128) var myself = 21487; var twin = 2867; var formpos = "B"; var tochar = String.fromCharCode; var movestat = (move % 2).toString(); var inbox = getMsg(twin); // Spoofing the ...


44

C, 50 35 bytes #define f(i)*(short*)(i+7)%51%4%3-1 Call f with a string containing both players, without separator, and it will return whether the first one wins. Explanation: By looking at the nine possible strings, it turns out that the letter pairs on columns 7 and 8 are unique: vv RockPaper PaperScissors ScissorsRock RockRock // ...


41

Python 2, Ruby, Retina, 90 83 bytes -7 bytes thanks to Value Ink s=['rock','paper','scissors'] print s[s.index((0and gets or input()))+(0and-2or-1)] Try it Online: Python, Ruby, Retina Wins in Ruby, loses in Python, and ties in Retina. This solution makes use of the fact that 0 is truthy in Ruby but falsey in Python. It also makes use of negative indexing ...


37

Jelly, 6 bytes ạg105Ị Takes two code points as argument. Yields 1 for friends, 0 for foes. Try it online! Background Let n and m be the code points of two input characters. By taking |n - m|, we need to concern ourselves only with all 2-combinations of characters. The following table shows all 2-combinations of characters the the corresponding absolute ...


35

Python 2, 19 bytes "WUBRGWGRBUW".count Try it online! An anonymous function: returns 1 for friends and 0 for foes.


29

Dyalog APL, 10 bytes (5?69),?26 Dyadic ? is ⍺ distinct random numbers in [1,⍵], and monadic ? is a single random number. Try it here.


29

MATL, 7 12 11 9 8 6 bytes Thanks a lot to @lirtosiast for removing 2 bytes ud7BXf Truthy is an array of nonzero values. Falsy is empty array (no output displayed). As of release 16.2.0, u is stable by default. So the code needs an extra S to sort the output: uSd7BXf (7 bytes). The link includes this modification. Try it online! u % input array ...


29

Not my answer 6 blocks The user Alex found a shorter solution, of length 6. I can confirm that their solution works: O(O(Br G G, 6) Br, 5) They attempted to edit this question to add this answer, so I'm assuming they want it to be displayed here. I don't like how the reputation system works around here. The message they left: The editor doesn't have ...


27

Pyth, 6 bytes suaV+e Test suite This program is very suave. 0 (falsy) means all zeroes, anything else (truthy) means not all zeroes. How it works: suaV+e suaV+eGGGQ Variable introduction. u Q Apply the following function repeatedly to its previous result, starting with the input. Stop when a value occurs which has ...


24

Scratch, 1604 – 125 = 1479 I'm here for the fun, not the golf. Edit: updated scoring method based on community consensus. Main program: Individual sprites: This is the sprite with number 0. The other sprites have the same script, except the number. Play with it online. Code used for byte counting: (Using snippet to hide code) when green flag ...


23

CJam, 58 57 bytes 0WX]2m*qN/{'*f+z}2*f{\~@m<fm<W<}:..+{W<{_'*#'*@'*-,?}/N}/ Input should not end with a linefeed. Output contains 0 for cells without nearby mines. Try it online in the CJam interpreter. Idea We start by padding the input matrix with one row and one column of asterisks. For input *4* **2 this results in *4** **2* **** ...


22

Javascript + jQuery (997) Tested on Chrome 32, Firefox 27, IE9 Open Console (F12) from this page and copy/paste the following code. scroll(0,0);h=1/30;p=[];r=320;n=0;w=80;f=2.5;o=80;t=setInterval;$('#question').children().hide().end().append('<p id="m"></p>').append('<p id="s"></p>').click(function(){v=100});$('#s').css({...


22

GolfScript, 163 :n;:`"You shot the wumpus. ""The wumpus ate you. ""The pit swallowed you. "{19:|rand}2*0|{[:,~,4%"ftvh"=.,+,@-]{20%}%}:^{;.^.+.3$?>"You feel a breeze. "1$6"You smell a wumpus. "4$8{$?-1>*p}2*'"#{'|):|';`head -1`}"'++~{3%}/={=3$=|{"Your shot missed. "p@^3rand=@@}if}{=@;}if.[|4$6$]?.)!}do])= The score is obtained by taking the byte ...


21

C 64,643 bytes, Score: ~6.5 million The following Stack Snippet (courtesy of Mego) outputs all of the code as a single standalone C file: $("#a").text(pako.inflate(atob('eJztPWt347ax3/UrsO6JTVrSVpKd1FlZzslJ2iZtzr233faT10eHoqg1E1lSRWrTbVb//WLwIB4EQJCSvOmGc3YpCcQMBsDMYAYv/y5dxcvdPEG3WT5P1y8f7zq/k5OW6UxLS6Jt/Kjn26art5DWwV93cY7oxzSOtvNp3vmlgzBkj+...


21

Red Team - SeekerBot var myself = 38926; var messages = getMsg(myself).split(';'); var minimalDistanceToFriend = 2; var chosenMove = null; var newDistanceToFriend = null; var minimalVerticalDistanceToEnemy = null, minimalHorizontalDistanceToEnemy = null; var closestFriend = null; var closestEnemy = null; var possibleVictims = []; var possibleMoves = [ {...


21

Brachylog, 10 bytes <.='e3:I'* Try it online! Explanation (?)<. Output > Input .= Assign a value to the Output . 'e3 3 cannot be an element of the Output (i.e. one of its digits) 3:I'*(.) There is no I such that 3*I = Output


21

Befunge-98, 13 12 bytes ~~-9%5%3%!.@ Try it online! Prints 0 for friends and 1 for foes This uses the difference between the ASCII values of the letters. If we take the (((ASCII difference % 9) % 5) % 3), the values for the foes will be 0. Then, we not the value and print it. Thanks to @Martin for the golf


21

V, Brain-flak, and Python 2, 97, 86, 81, 77, 75 bytes o='rock paper scissors'.split() lambda s:o[o.index(s)-1]#ddt.C rHd*wywVp Two bytes saved thanks to @nmjcman101! This was super fun! I like this answer a lot because it's a cool overview of languages I like: My favorite editor, my favorite non-esoteric language, and a language I wrote. (...


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