Posterous theme by Cory Watilo

Filed under: cool

És ha 10 millió majom használna AWK-t?

Cross posted from Proggit. Though they don't show self-posts there, so it is good as dead. Copy and paste to terminal and enjoy!

awk 'function wl() {rate=4000; return int((rate/160)*(0.87055^(int(rand()*10))))}; BEGIN {srand(); wla=wl(); while(1) {wlb=wla; wla=wl(); if (wla==wlb) wla*=2; d=(int(rand()*10+5)*rate/4); a=0; b=0; c=128; ca=40/wla; cb=20/wlb; de=rate/10; di=0; for (i=0;i<d;i++) {a++; b++; di++; c+=ca; c+=cb; if (a>wla) {a=0; ca*=-1}; if (b>wlb) {b=0; cb*=-1}; if (di>de) {di=0; ca*=0.9; cb*=0.9}; printf("%c",c)}; c=int(c); while(c!=128) {c<128?c+=1:c-=1; printf("%c",c)};};}' > /dev/dsp

If you run OSSv4, use rate=64000 Someone with a better sense of pitch might want to find rate numbers that are more in tune. If it stutters on your computer (though you'd need to have a Pentium 2 for this to happen) use mawk instead.

It uses a pentatonal scale, so it'll probably sound slightly out of tune no matter what you do.

It is also my first awk script, go easy on me. Improvements welcome.

Edit: formatted for your viewing pleasure.

awk 'function wl() {\
        rate=4000; \
        return int((rate/160)*(0.87055^(int(rand()*10))))}; \
    BEGIN {\
        srand(); \
        wla=wl(); \
        while(1) {\
            wlb=wla; \
            wla=wl(); \
            if (wla==wlb) \
                wla*=2; \
            d=(int(rand()*10+5)*rate/4); \
            a=0; b=0; c=128; \
            ca=40/wla; cb=20/wlb; \
            de=rate/10; di=0; \
        for (i=0;i<d;i++) {\
            a++; b++; di++; c+=ca; c+=cb; \
            if (a>wla) \
                {a=0; ca*=-1}; \
            if (b>wlb) \
                {b=0; cb*=-1}; \
            if (di>de) \
                {di=0; ca*=0.9; cb*=0.9}; \
            printf("%c",c)}; \
        c=int(c); \
        while(c!=128) {\
            c<128?c+=1:c-=1; \
            printf("%c",c)};};}' > /dev/dsp

Na ez egy jó hír magyarokról

Hungarian Designers Debut Stringbike, a Chain-Free Bike

By Mark Brown

Bicycle designers from Hungary have revealed the Stringbike in Padova, Italy, a bike design that drops the common chain in favour of a wire and pulley system.

While it might seem like a complicated answer to a non-existent problem, the Hungarian creators assure that their symmetric system lends itself to an extra level of comfort and efficiency.

Typical bikes, of course, have a chain and gears on just one side of the bike. The Stringbike creators, at bike manufacturing company Schwinn Csepel Zrt, write that “asymmetry has been the source of lots of problems”. However, other than slipping chains and oily jeans, they’re mostly “unnoticeable” problems, until you’ve tried a symmetrical system first hand.

The new design’s mechanics are considerably more complicated than the traditional chain, and is possibly best left to the video (embedded below) to explain. In the most basic terms, the movement of the pedal forces a swinging arm to move about its shaft, pulling a taught cable around a pulley system. With each push, the task is swapped from the left side to the right.

The Stringbike offers up a few extra advantages over its chain-driven predecessor. The pedal system can be replaced with different discs for separate purposes, for example. Racing and touring could use different shaped and sized parts, to alter performance and function. Plus, the rear wheel can be removed in seconds, for portability.

You’ll also have no grease or oil to deal with, but it doesn’t look like you’ll be able to fix this quite as easily as replacing a knackered chain. The official website mentions that while you will be able to take it an appropriate service location, you can repair a Stringbike at home. Although, that would presumably be the least of your worries if a fast-moving, taught, metal wire lashed off its piston next to your leg. Ouch.

Gyorsan azonnal megoldani

És akkor most egy sokmillió soros fájlon cseréljük ki az utolsó 'F' betűt 'N'-re, de csak akkor ha az előző sor vége is 'N' és az utolsó sor vége is 'N'.

     cp sokmiiliosorosfajl.txt{,.orig}

     vim -c "%s:^\(.\{228\}N\)\(\_..\{228\}\)F\(\_..\{228\}N\):\1\2N\3:" -c "wq" sokmiiliosorosfajl.txt &

     make coffee

Ez sem volt benne a függvénytáblázatban

Tupper's Self-Referential Formula
DOWNLOAD Mathematica Notebook
Tupper's formula

J. Tupper concocted the amazing formula

 1/2<|_mod(|_y/(17)_|2^(-17|_x_|-mod(|_y_|,17)),2)_|,

where |_x_| is the floor function and mod(b,m) is the mod function, which, when graphed over 0<=x<=105 and n<=y<=n+16 with

 n=96093937991895888497167296212785275471500433 
966012930665150551927170280239526642468964284217 
435071812126715378277062335599323728087414430789 
132596394133772348785773574982392662971551717371 
699516523289053822161240323885586618401323558513 
604882869333790249145422928866708109618449609170 
518345406782773155170540538162738096760256562501 
698148208341878316384911559022561000365235137034 
387446184837873723819822484986346503315941005497 
470059313833922649724946175154572836670236974546 
101465599793379853748314378684180659342222789838 
8722980000748404719,

gives the self-referential "plot" illustrated above.

Tupper's formula can be generalized to other desired outcomes. For example, L. Garron (pers. comm.) has constructed generalizations for n=13 to 29.

SEE ALSO: Self-Recursion