99 cervezas en la pared

99 cervezas en la pared

99 Bottles of Beer, es un sitio que no muchos conocen donde la canción de las 99 botellas de cerveza la colocaron en 1342 lenguajes de programación diferentes, pasando desde el tan conocido C, hasta los lenguajes esotéricos creados por personas creativas para nuevos lenguajes de programación.

Aquí el ejemplo en C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <linux/fs.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/init.h>
#include <asm/uaccess.h>
 
#define DRIVER_MAJOR 240
#define BUFFERSIZE 160
#define PLURALS(b) (b>1)?"s":""
 
MODULE_AUTHOR("Stefan Scheler <sts[at]synflood[dot]de>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("The 99 Bottles of Beer Linux Kernel Module");
MODULE_SUPPORTED_DEVICE("Bottle of Beer");
 
struct _instance_data {
    int bytes_avail, bytes_sent, bottles;
    char buf[BUFFERSIZE];
};
 
static void fill_buffer(char *buf, int b) {
    char line[BUFFERSIZE/2];
    if (b>0) {
        sprintf(buf, "%d bottle%s of beer on the wall, %d bottle%s of beer.\n" \
                     "Take one down and pass it around, ", b, PLURALS(b), b, PLURALS(b));
        if (b==1)
            strcat(buf, "no more bottles of beer on the wall.\n");
        else {
            sprintf(line, "%d bottle%s of beer on the wall.\n", b-1, PLURALS(b-1));
            strcat(buf, line);
        }
    } else {
        sprintf(buf, "No more bottles of beer on the wall, no more bottles of beer.\n" \
                     "Go to the store and buy some more, 99 bottles of beer on the wall.\n");
    }
}
 
static ssize_t driver_read(struct file *instance, char *userbuffer, size_t count, loff_t *offset)
{
    struct _instance_data *iptr = (struct _instance_data *)instance->private_data;
 
    int to_copy;
    int not_copied;
 
refillbuffer:
    fill_buffer(iptr->buf, iptr->bottles);
    iptr->bytes_avail = strlen(iptr->buf)+1;
    to_copy = iptr->bytes_avail-iptr->bytes_sent;
 
    if (to_copy>0) {
        if (to_copy> count) to_copy=count;
        not_copied=copy_to_user(userbuffer, iptr->buf+iptr->bytes_sent, to_copy);
        iptr->bytes_sent += to_copy-not_copied;
        return (to_copy-not_copied);
    }
 
    if ((to_copy==0) && (iptr->bottles>0)) {
        iptr->bytes_sent=0;
        iptr->bottles--;
        goto refillbuffer;
    }
 
    return 0;
}
 
int driver_open(struct inode *devicefile, struct file *instance)  {
    struct _instance_data *iptr;
    iptr = (struct _instance_data *)kmalloc(sizeof(struct _instance_data), GFP_KERNEL);
 
    if (!iptr)
        return -1;
 
    iptr->bytes_sent = 0;
    iptr->bottles = 99;
    instance->private_data = iptr;
 
    return 0;
}
 
int driver_close(struct inode *devicefile, struct file *instance)  {
    if (instance->private_data)
        kfree(instance->private_data);
    return 0;
}
 
static struct file_operations fops = {
    .owner   = THIS_MODULE,
    .open    = driver_open,
    .release = driver_close,
    .read    = driver_read,
};
 
static int __init __init_module(void) {
    if(register_chrdev(DRIVER_MAJOR, "99 Bottles of Beer", &fops) == 0)
        return 0;
    return -EIO;
}
 
static void __exit __cleanup_module(void) {
    unregister_chrdev(DRIVER_MAJOR, "99 Bottles of Beer");
}
 
module_init(__init_module);
module_exit(__cleanup_module);

Aquí el ejemplo en LOLCODE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
HAI
    VISIBLE "O HAI! IM IN UR BEERZ!"
    I HAS A VAR
    LOL VAR R 99
    IM IN YR LOOP
        VISIBLE VAR!
        VISIBLE " BOTTLZ OF BEER N TEH WALL, "!
        VISIBLE VAR!
        VISIBLE " BOTTLZ OF BEER!"
        VISIBLE "TAKE 1 DWN, PAS IT AROUN, "!
        NERFZ VAR!!
        IZ VAR LIEK 0?
            YARLY
                VISIBLE "NO MOAR"!
            NOWAI
                VISIBLE VAR!
        KTHX
        VISIBLE " BOTTLZ OF BEER N TEH WALL!"
        IZ VAR LIEK 0?
            GTFO
        KTHX
    KTHX
    VISIBLE "GIEV MOAR PLZ! KTHXBAI!"
KTHXBYE