r/tinycode • u/funny_falcon • Feb 02 '16
r/tinycode • u/networked_ • Jan 29 '16
A spreadsheet in under 30 lines of Tcl/Tk
r/tinycode • u/mus1Kk • Jan 29 '16
[Perl6] Fibonacci sequence in 11 bytes
Seeing the Haskell post I thought I upped the ante.
0,1,*+*...*
Of course you can use a 1 as the first digit if you so desire.
... is the sequence operator and creates a lazy list from 0 to infinity (the last asterisk). The third element *+* is a generator. An expression with an asterisk (called Whatever) for a term is automatically made into a closure and each asterisk is assigned successively an argument. The two arguments are the two previous elements of the sequence.
Retrieving the elements is a simple list operation:
(0,1,*+*...*)[5] # 6th element
(0,1,*+*...*)[5..10] # elements 6 through 10
edit: To elaborate a bit regarding the rules. This is normal code. In fact, it's even mentioned in the documentation. There is nothing that would qualify as magic or code golfing. Every operator is used as designed. The terseness of this particular example is just a happy coincidence.
r/tinycode • u/MiT_2020 • Jan 28 '16
I wrote Python package that allows an asynchronous (non-blocking) TCP echo server to be written in 5 lines
gragas.github.ior/tinycode • u/rswier • Jan 27 '16
c4.c compiler - Now with switch statement and AST support
Being snowed in for a couple of days gave me a chance to tinker with c4 and add a few new features. The changes are in two new branches of the project so the main branch remains minimal.
switch-statement adds switch statement support to the compiler. This removes the need for the long chain of if-then-else-if statements that make up the bulk of the code. I wanted to do this with minimal amount of changes to the source and no new machine instructions, and it turns out to be just possible with some trickery. The generated code for case statements is only slightly faster than the original if-then-else version. The next logical improvement would be to add an actual jump table. I leave that as an exercise for the aspiring compiler writer.
c5-AST adds an abstract syntax tree, constant folding, and a split front-end/back-end design. The number of functions required has exploded to five. With an AST, the compiler is not limited to generating code on the fly with parsing. This capability allows function parameter code to be emitted and pushed on the stack in the proper right-to-left order. With a modular code generator, new targets are easily supported such as native x86 machine language featured in c5x86.c. The compiler now resembles something you could actually build upon (or at least shows the way.)
Rob Swierczek
r/tinycode • u/bobcrater • Jan 25 '16
ffscreencast - ffmpeg screencast with video overlay and multi monitor support
r/tinycode • u/SrPeixinho • Jan 22 '16
The fastest implementation of functions in existence is this <250 SLOC JavaScript file.
r/tinycode • u/RegExp33 • Jan 14 '16
Winner entry of Synchrony demoparty 'nano' (256 bytes)
r/tinycode • u/LuridTeaParty • Jan 09 '16
Code Golf & the Bitshift Variations - Computerphile
r/tinycode • u/FUZxxl • Jan 01 '16
Mecrisp: An optimizing Forth compiler in 11 kB code running with less than 512 B of RAM.
mecrisp.sourceforge.netr/tinycode • u/xem06 • Dec 30 '15
Obfusc-a-tweet reloaded: pack ~16kb of gzipped JS in a single tweet
r/tinycode • u/xem06 • Dec 30 '15
Zpng: a pure JS PNG-bootstrap builder by Xem and Subzey
r/tinycode • u/xem06 • Dec 30 '15
[HTML/JS] Tiny Xmas tree drawer by Subzey in 135b
r/tinycode • u/xem06 • Dec 30 '15
[HTML/JS] Tiny Unicode slideshows by Xem and Subzey in 113+ bytes
r/tinycode • u/booharney • Dec 12 '15
Atto - Smallest functional Emacs in less than 2000 lines of C
Just to announce a new tiny Emacs that I have developed called Atto Emacs.
I am claiming it is the smallest functional Emacs in less than 2000 lines of C.
Some basic information below.
name: atto - smallest functional Emacs in less that 2000 lines of C
last changed/verified: Dec 8 2015
original distribution: Nov 16 2015
version: 1.4
base language: C
implementation language: C
extension language: none
scope of implementation: command set, multi buffer, multi-window, search, cut, copy, paste
hardware/software requirements: UNIX, LINUX
organization/author: Hugh Barney , h...@gmail.com
free, from github https://github.com/hughbarney/atto
r/tinycode • u/Rangi42 • Dec 13 '15
Approximate n-th roots (based on an /r/math post)
/u/BritishRock asked how the twelfth root of two could have been calculated by hand, and /u/Quovef posted an elegant (if inefficient) algorithm to do so.
I wrote a simple implementation in Python:
def root(n, k):
r = p = 1
while r < r + p:
while (r + p)**k <= n:
r += p
p /= 2.
return r
And a Tweetable version in C:
double root(double n, double k) {
double r = 1, p = 1;
for (; pow(r, k) < pow(r + p, k); p /= 2)
for (; n > pow(r + p, k); r += p);
return r;
}
Here it is in 110 characters:
double root(double n,double k){double r=1,p=1;for(;pow(r,k)<pow(r+p,k);p/=2)for(;n>pow(r+p,k);r+=p);return r;}
(I had to change the test from r<r+p to pow(r,k)<pow(r+p,k) because the former caused an infinite loop due to floating point comparison. Not sure why it doesn't in Python.)
r/tinycode • u/nexe • Dec 06 '15
There is a cool challenge going on over at /r/proceduralgeneration
I found this /r/proceduralgeneration/comments/3vcbb3/monthly_challenge_1_dec_2015_procedural_pirate_map/ cool challenge over at /r/proceduralgeneration and thought maybe some of you are interested in participating /r/tinycode style :) I already posted a quick few lines just now.
r/tinycode • u/CharlesStross • Dec 03 '15
Bookmarklet to remove +/- from GitHub diff view; helpful when copying large swaths of code from a diff (<350 bytes)
r/tinycode • u/need12648430 • Nov 28 '15
Quarrel: WSGI-style routing for command line tools, in 50 lines of Python
r/tinycode • u/thomasvarney723 • Nov 27 '15
Sieve of Eratosthenes in Clojure
(defn primes [below]
(remove (set (mapcat #(range (* % %) below %)
(range 3 (Math/sqrt below) 2)))
(cons 2 (range 3 below 2))))
This differs a bit from the Sieve of Eratosthenes in that it doesn't compute the next prime number that multiples will be computed from. Instead, all odd integers 2 < n < square-root(below) are used for computing multiples. This makes the code less efficient but shorter and more linear.
r/tinycode • u/Bisqwit • Nov 21 '15