What’s the coolest thing you can get a computer to do in 10 lines of code?

Tomohiko Sakamoto

Why 10 lines, when one of the most awesome and cool algorithm can be implemented in roughly 5 lines of code.

My Lords, Ladies, and Gentlemen, I present to you  Tomohiko Sakamoto’s Algorithm, to find the day of week from any given date.

1.int dow(int y, int m, int d) {
2.static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
3.y -= m < 3;
4.return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;

To understand, how it works please refer to

How does Tomohiko Sakamoto’s Algorithm work?


A seven line Perl program by Keith Winstein and Marc Horowitz of MIT, descrambles a DRM-protected DVD in real time. Short enough to be included in email signatures and printed on t-shirts, it took on a life of its own as something of an emblem for the anti-DRM movement. Winstein noted, “I think there’s some value in demonstrating how simple these things really are and how preposterous it is to try to restrict their distribution.”

#!/usr/bin/perl -w
# 531-byte qrpff-fast, Keith Winstein and Marc Horowitz <sipb-iap-dvd@mit.edu>
# MPEG 2 PS VOB file on stdin -> descrambled output on stdout
# arguments: title key bytes in least to most-significant order

1 $_='while(read+STDIN,$_,2048){$a=29;$b=73;$c=142;$t=255;@t=map{$_%16or$t^=$c^=(
2 $m=(11,10,116,100,11,122,20,100)[$_/16%8])&110;$t^=(72,@z=(64,72,$a^=12*($_%16
3 -2?0:$m&17)),$b^=$_%64?12:0,@z)[$_%8]}(16..271);if((@a=unx"C*",$_)[20]&48){$h
4 =5;$_=unxb24,join"",@b=map{xB8,unxb8,chr($_^$a[--$h+84])}@ARGV;s/...$/1$&/;$
5 d=unxV,xb25,$_;$e=256|(ord$b[4])<<9|ord$b[3];$d=$d>>8^($f=$t&($d>>12^$d>>4^
6 $d^$d/8))<<17,$e=$e>>8^($t&($g=($q=$e>>14&7^$e)^$q*8^$q<<6))<<9,$_=$t[$_]^ 7 (($h>>=8)+=$f+(~$g&$t))for@a[128..$#a]}print+x"C*",@a}';s/x/pack+/g;eval

WhatsApp prank

Creator Profile:Superhuman07/Whatsapp-Multiple-Messenger-Bot

I recently started learning js so build this program that allows you to send a whatsapp message multiple times through WhatsApp Web site :p

The whatsapp has limit of 4000 emogis at one time that you can send after that it crashes on the sender and the receiver side as well :p

Here is the code just connect your whatsapp to your PC using WhatsApp Web site using whatsapp internal code scanner and open the recipient you want to send the message multiple time and annoy your friend :p then open console on your browser using control + shift + j to open console and paste this code and let the game begin :p

Here is the code, I have added some comments and indentations(which has increased the lines of codes)to configure the code yourself:-

// control + shift + j to open console and paste
var count = 4000; //number of times to send
var message = "spam message nr "; //spam message
var i = 0;var timer = setInterval(function() {
var evt = document.createEvent("TextEvent");
evt.initTextEvent("textInput", true, true, window, message + i, 0, "en-US");
document.querySelector(".input-container .input").focus();
document.querySelector(".input-container .input").dispatchEvent(evt);
i++;if (i == count)clearInterval(timer);console.log(i + " messages sent");var event = new MouseEvent('click', {'view': window,'bubbles': true,'cancelable': true});document.querySelector(".icon.btn-icon.icon-send").dispatchEvent(event);
}, 10);

Use it wisely on your friends they might get pissed 😛

Extract all files from sub-folders into parent folder, then remove empty sub-folders.

This trick is very useful to people who download lots of TV series episodes every week. When you download a new episode, usually the torrent makes a folder in your downloads directory with the video file inside it. and your folder structure looks like this: Each episode inside a separate folder. how annoying…

Instead, you want the Season 1 folder to contain just the contents and no other crap, like this:

In order to do this manually, you need to:

  1. Go inside a folder
  2. Cut the content
  3. Come back to the parent folder
  4. Paste the content there
  5. Delete the empty folder.

But this can be automated to a single click activity. and that too just with 3 Lines of code written in old faithful notepad, nothing else is required actually!

You need to create a batch file for this. follow the below steps:

Step 1: Open notepad, and paste the following 3 lines

@echo off

for /f “tokens=*” %%f in (‘dir /a:-D /s /b’) do move “%%f” .

for /f “tokens=*” %%f in (‘dir /a:D /s /b’) do rd “%%f”

Step 2: Save this file as a .bat file using “Save as type” as All Files.

Step 3: You are done! Keep this BAT file in a safe place. Whenever you want to extract the contents from sub-folders, keep the bat file in the parent folder and just double click on it.

before double clicking

After double clicking

Disclaimer: To avoid copyright issues and possible piracy accusation I have used a dummy TV series name with dummy fake files. Any Resemblance to Actual Persons, Living or Dead, is Purely Coincidental.

p.s. No animals, including Dragons were harmed during writing of this answer.

Shortest Sudoku Solver

written in python

def r(a):i=a.find('0');~i or exit(a);[min[(i-j)%9*(i/9^j/9)*(i/27^j/27|i%9/3^j%9/3)or a[j]forj in range(81)]or r(a[:i]+m+a[i+1:])for m in'%d'%5**18]from sys import*;r(argv[1])

Sleep Sort

This amazing code known as Sleep Sort is used to sort elements without any comparison.

Here is the code in c :
1 #include
2 #include
3 #include <sys/types.h>
4 #include <sys/wait.h>
5 int main(int c, char **v)
6 { while (--c > 1 && !fork());
7 sleep(c = atoi(v[c]));
8 printf("%d\n", c);
9 wait(0);
10 return 0;}

on running it by typing in console
./a.out 5 1 3 2 11 6 4

you get this

Now how does the code works . Basically it prints k after k seconds. For example

it will print 5 after 5 seconds,1 after 1 second , 3 after 3 seconds and so on and hence we get the output in a sorted manner.

This is one of the most sexiest code I have ever seen .Truly, flabbergasted!!!

Many people are questioning about the practicality of this code. To be honest it’s not very practical. For examples if the array elements are large say 1200 then we have to wait for 20 mins to sort this number and you don’t wanna wait for 20 mins for sorting array elements that’s for sure. But you can’t deny the “out of the box” thinking that is required for designing codes like these and that makes this code quite amazing.


One thought on “What’s the coolest thing you can get a computer to do in 10 lines of code?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s