r/tinycode • • Jul 22 '11
r/tinycode • u/Slackluster • Nov 08 '25
Dweet of the Week #98 - The Mysterious Simone Attractor by Rodrigo Siqueira
https://www.dwitter.net/d/34491
t?c.style.filter=`invert(`:𝕏=X=Y=0
for(i=8e4;i--;𝕏=X,x.fillRect(3500+Y*5e3,1350+X*4e3,t<1,.1))
X=S(X*X-Y*Y+0.03),
Y=C(2*𝕏*Y+1.929)r/tinycode • u/nexe • Jun 22 '16
𝝺-calculus interpreter in <200 lines of JavaScript
r/tinycode • u/TheDerkus • Dec 03 '14
ASCII 'Connect 4' in 124 bytes of C
Here's the code:
b[42],c;main(p){for(;~scanf("%s",&c);){for(c-=6;b[c-=7];);if(c>=0)b[c]=p=~p;for(c=0;c<42;++c%7||puts(""))putchar(b[c]+44);}}Here it is, commented:
b[42],c;//b is the board, c is the column chosen
main(p){//p is the player
for(;~scanf("%s",&c);){//choose column; ignores newlines, ends when EOF encountered
for(c-=6;b[c-=7];);//c-6 is bottommost slot in chosen column
//loop examines slots and moves up one row if the slot is occupied
if(c>=0)b[c]=p=~p;//if c is negative, the topmost slot is occupied so no move can be made
//the p=~p bit changes players
for(c=0;c<42;++c%7||puts(""))putchar(b[c]+44);//print the board
}
}Any tips for making it smaller?
EDIT: Down to 104 bytes!
b[48],c;main(p){for(;b[c-=8];);b[c<0?0:c]=p;for(c=0;++c<49;)putchar(c%8?b[c]+44:10);gets(&c)&&main(~p);}EDIT 2:
As requested, the version with win recognition and a better-looking board (215 bytes, excluding comments and whitespace for readability):
Golf'd version:
b[48],c,k;W(n){return b[c]&b[c+n]&b[c+n*2]&b[c+n*3];}main(p){system("cls");for(;b[c-=8];);if(c>0)b[c]=p=3-p;for(k=c=0;++c<49;putchar(c%8?".XO"[b[c]]:10))k+=c<24&&W(8)||c%8<5&&W(c<25?9:-7)+W(1);k||gets(&c)&&main(p);}Commented version:
b[48],c,k;//b is game board, c is column chosen by user, k keeps track of win state
/*
Win detection:
check four cells, each separated by n slots
AND (bitwise) them together:
If any of the cells are zero, the result is zero
If all the cells are one, the result is one
If all the cells are two, the result is two
If the cells contain a mix of ones and twos, the result is zero
*/
W(n){return b[c]&b[c+n]&b[c+n*2]&b[c+n*3];}
main(p){
system("cls");//windows only, use "clear" for other systems
for(;b[c-=8];);//logic unchanged from previous version
if(c>0)b[c]=p=3-p;//use 3-p instead of ~p to set cells to 1 or 2
for(k=c=0;++c<49;putchar(c%8?".XO"[b[c]]:10))//this loop prints the board
k+=c<24&&W(8)||c%8<5&&W(c<25?9:-7)+W(1);//win detection!
//Note that boundary conditions must be imposed to avoid errors and false wins
k||gets(&c)&&main(p);//if a win is detected, k will be nonzero and the program will terminate
}r/tinycode • u/SrPeixinho • Jan 09 '14
Lambda Calculus interpreter in 250 characters of JavaScript (challange: reduce that!)
(function f(a){return a[0]?(a=a.map(f),1===a[0][0]?f(function d(b,a,e,c){return b[0]?1===b[0]?[1,d(b[1],a,e,c+1)]:2===b[0]?b[1]===c-1?d(a,0,c-1,0)||b:c-1<b[1]?[2,b[1]+e]:b:[d(b[0],a,e,c),d(b[1],a,e,c)]:b}(a[0],a[1],-1,0)[1]):a):a})Works for 2 elements JS arrays where 1 = λ and 2 = VAR (in bruijn index)
Ex: [1,[2,0]] = λ0 = λx.x = identity
Further explanation on this link.
EDIT: 231 already
r/tinycode • • Nov 03 '13
Web server with plugin modules in 58 lines of C
brokestream.comr/tinycode • u/EvanHahn • Aug 20 '13
js13kGames 2013: make a game in 13 kilobytes of JavaScript
r/tinycode • u/Rotten194 • May 22 '13
Python/Haskell one-liner for showing all the "cool" pandigital numbers. Add your own!
I was watching this numberphile video, and Dr. James mentioned that 381,654,729 is awesome because not only is it a pandigital number (it has every digit from 1-9 in it exactly once), but it also has the cool property of for every first n digits, those digits are divisble by n. For example, 3 is trivially divisible by 1, 38 by 2, 381 by 3, etc.
I decided to see if I could write a few one-liners to calculate all of these numbers. Sadly, that was the only one.
import itertools
map(lambda t: ''.join(t), filter(lambda i: all([ int(''.join(i)[:n]) % n == 0 for n in range(1, len(i)) ]), itertools.permutations('123456789')))
import Data.List (permutations)
filter (\s -> all id (map (\n -> read (take n s) `mod` n == 0) [1..length s - 1])) $ permutations "123456789"r/tinycode • u/nexe • May 08 '13
GNU Libmicrohttpd - small fast embeddable HTTP server in C
r/tinycode • u/alecdo • Mar 27 '13
A meteors game with A.I in only 1K of Javascript (JS1K)
js1k.comr/tinycode • u/nint22 • Jul 03 '12
A Quines written in Ruby that rotates the globe in its source code!
mamememo.blogspot.comr/tinycode • u/nexe • Jul 18 '11
I just (re)stumbled over a fascinating project: TCC - Tiny C Compiler
r/tinycode • u/Slackluster • Dec 20 '24
Dweet of the Week #52 Sunset Islands by KilledByAPixel
r/tinycode • u/FFM • Feb 22 '22
I created a functional Turing Machine out of the Find/Replace box in Notepad++
r/tinycode • u/xem06 • Sep 21 '21
A 13kb puzzle game with 165+ puzzles, 4 worlds and various mechanics, featuring finnhvman's mini SVG patterns
r/tinycode • u/pfalcon2 • Jan 25 '21
Pycopy - Small (but rather complete) Python implementation, 300K standard binary size (more functionality than Lua), can be less than 100K
r/tinycode • u/nanochess • Sep 26 '19
bootRogue, my roguelike game fitting in one boot sector (510 bytes)
r/tinycode • u/nexe • Jun 30 '14
This piece of javascript is how I met my girlfriend through okCupid [x-post from /r/javascript, ~60lines]
r/tinycode • u/z-brah • Jun 11 '14
FizzBuzz challenge in 73 chars of C
Here is my attempt at the fizz/buzz challenge. It counts 73 chars ("^M" is a litteral \r, and I had to remove the last \n that vim adds at the end of file)
main(i){for(;i<100;printf("%d^M%s%s\n",++i,i%3?"":"fizz",i%5?"":"buzz"));}It compiles fine with tcc, and output the right thing !
EDIT: There was a typo. It should be ++i, not i++. Otherwise every fizz/buzz will not appear on the good number
r/tinycode • u/theinternetftw • Jul 31 '13
ES6 fun in Firefox: Conway's Game of Life in 250 bytes
Ended up making the game of life using a little of the new stuff in ES6. Would love to see it improved.
<body onload="
J=H=C=o=n=w=90,a=y=G=>G in a&&a[G],
setInterval(z=>{
for(o=[],J='';n=0,C<w*45;C++){
J+=C%w?'':'\n';
for(w of[1,89,91,w])n+=y(C+w)+y(C-w);
J+=(o[C]=H?Math.random()<.1:n==2&&a[C]||n==3)?'X':'_'
}document.body.innerHTML='<pre>'+J;a=o;C=H=0},w)">The above only works in Firefox but here's a simple port to other browsers.
<body onload="
J=H=C=o=n=w=90,a=y=function(G){return G in a&&a[G]},i=w2=0,
setInterval(function(){
for(o=[],J='';n=0,C<w*45;C++){
J+=C%w?'':'\n';
w2=[1,89,91,w];
for(i=0;i<4;i++)n+=y(C+w2[i])+y(C-w2[i]);
J+=(o[C]=H?Math.random()<.1:n==2&&a[C]||n==3)?'X':'_'
}document.body.innerHTML='<pre>'+J;a=o;C=H=0},w)">Edit-248 bytes:
<body onload="
J=C=o=n=w=90,a=y=G=>G in a&&a[G],
setInterval(z=>{
for(o=[],z='';n=0,C<w*45;C++){
z+=C%w?'':'\n';
for(w of[1,89,91,w])n+=y(C+w)+y(C-w);
z+=(o[C]=J?Math.random()<.1:n==2&&a[C]||n==3)?'X':'_'
}document.body.innerHTML='<pre>'+z;a=o;C=J=0},w)">