Hot answers tagged

934

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 ...


677

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 ...


648

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 ...


621

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 ...


605

Part 5: Assembly, Translation, and the Future With our assembly program from the compiler, it's time to assemble a ROM for the Varlife computer, and translate everything into a big GoL pattern! Assembly Assembling the assembly program into a ROM is done in much the same way as in traditional programming: each instruction is translated into a binary ...


582

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 ...


82

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 |...


73

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=...


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 ...


47

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 message of a deceased partner if ...


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 // ...


42

LOLCODE, 1397 Note: I submitted this before I noticed the winning requirement was changed from popularity with golf tie-break to golf with popularity tie-break. There's not really any strict syntax, but I'm sure this is acceptable. HAI I HAS A CRAZY, LUCKY, CHALLENGE, TREAT I HAS YUMMY ITZ "LOL U LOZED" I HAS MEH ITZ "NOWAI TIED" I HAS ...


40

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 ...


38

sed, 35 Raising the bar a bit with a postage-stamp sed meditation. s/> / >/ s/ </< / s/0</0>/ s/>1/<1/ The meditation is enjoyed on stdin/stdout on two computers, not necessarily connected by a network. The meditation begins in the state 0 < 1 with guru zero on the left and one on the right. The angle bracket ...


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

C# - Stack Exchange Hangman Guess names of Stack Exchange websites in this Hangman game: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z New game This was done using ASP.NET MVC 3.0. Here's the code of the Controller that does the trick: public class HangmanController : Controller { public ActionResult Index() { var game = Session["...


35

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


31

JavaScript (553 512 bytes) Link to playable version c=0;a=b=d=-1;e=[f=[20,7],[20,8]];i=Math.random;~function n(){if(c&&(87==a||83==a ))c=0,d=87==a?-1:1;if(d&&(65==a||68==a))d=0,c=65==a?-1:1;p([j=e[0][0]+c,k=e[0][1 ]+d])||!j||39==j||!k||10==k?b+=" | GAME OVER":(e.unshift([j,k]),p(f)?(f=[1+38*i( )|0,1+9*i()|0],b++):e.pop());for(m=h="";11>h;...


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.


28

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 ...


27

Conway's Game of Life +1 generation - +5 generations - zoom in - zoom out Load pattern: random - glider - gunstar - snail - lwss - lightspeedoscillator1 - tumbler Used Python and SVG output. I have tried using single pixels at first (so you could toggle single cells), but it did not work out, because the browser does not load images in order. Also, ...


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 ...


25

Python 3, 68 50 48 bytes EDIT: Thanks to 3 tricks from Neil, and 2 from Mr. Xcoder Each input string has a distinct fourth character, so I'm using that to distinguish them. If you arrange the elements in the cycle (scissors, paper, rock, lizard, spock), then each element beats the element directly after it and the element 3 spots to the right, cyclically. ...


24

Javascript, 883 (+ 70 HTML) c=document.getElementById('c').getContext('2d') c.fillStyle="#FFF" c.font="60px monospace" w=s=1 p=q=a=b=0 m=n=190 x=300;y=235 u=-5;v=3 setInterval(function(){if(w&&!s)return;s=0 c.clearRect(0,0,640,480) for(i=5;i<480;i+=20)c.fillRect(318,i,4,10) m+=p;n+=q m=m<0?0:m;m=m>380?380:m n=n<0?0:n;n=n>380?380:n x+=...


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 ...


24

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 ...


23

GolfScript n"Draw" Above code implements the required functionality. Additionally, it ensures that the player will never be left angry because of a (perceived) unfairness of computer's strategy. Ungolfed version n"Draw" How to invoke the program The input (a single character of 'r', 'p', 's') has to be provided on STDIN, possibly terminated with ...


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

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+...


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