ඔබගේ ප්‍රියතම භාෂාවෙන් වෙනත් භාෂාවකින් වැඩසටහන ලියන්න [වසා ඇත]


169

අධිෂ් Real ාන තාත්වික ක්‍රමලේඛකයාට ඕනෑම භාෂාවකින් ෆෝට්‍රාන් වැඩසටහන් ලිවිය හැකිය.

සැබෑ ක්‍රමලේඛකයින්ගෙන් පැස්කල් භාවිතා නොකරන්න

ඔබේ කර්තව්‍යය වන්නේ ඔබ කැමති ක්‍රමලේඛන භාෂාවෙන් වැඩසටහන ලිවීමයි, නමුත් ඔබට වෙනත් භාෂාවක් පමණක් භාවිතා කිරීමට අවසර ඇත. එනම්, සියලු කේතීකරණ සම්මුතීන් එක් භාෂාවකින් ඉවත දමා ඒවා වෙනත් භාෂාවෙන් කේතකරණ සම්මුතීන් මගින් ප්‍රතිස්ථාපනය කරන්න. තව තවත් වඩා හොඳ. ඔබේ වැඩසටහන වෙනත් භාෂාවකින් ලියා ඇති ආකාරයට පෙනේ.

උදාහරණයක් ලෙස, ජාවාට වෛර කරන පයිතන් රසිකයාට ජාවා හි පයිතන් වැඩසටහනෙන් පසුව ලිවිය හැකිය:

void my_function()                                                             {
    int i = 9                                                                  ;
    while(i>0)                                                                 {
        System.out.println("Hello!")                                           ;
        i = i - 1                                                              ;}}

සී භාවිතා කිරීමට බල කරන පැස්කල් උද්යෝගයට මෙය ලිවිය හැකිය:

#define begin {
#define end }
#define then
#define writeln(str) puts(str)

if (i == 10) then
begin
    writeln("I hate C");
end

ඔබ සම්පූර්ණ වැඩසටහනක් ලිවිය යුතුය. වැඩසටහනට ප්‍රයෝජනවත් කිසිවක් කිරීමට අවශ්‍ය නැත.

වාසනාව. මෙය ජනප්‍රිය තරගයක් බැවින් වැඩි ඡන්ද ප්‍රමාණයක් ලබාගත් කේතය ජය ගනී!


1
file m.buettner දිගුව සමඟ ඔබේ ගොනුව සාදන්න .litcoffee. එය උදව් විය හැකිය.
ඉස්මයිල් මිගෙල්

පිළිතුරක් සඳහා මඳක් දිගු (සහ කලින් ලියා ඇති; සහ ස්වයං අන්තර්ගත නොවේ), නමුත්: සී හි තැපැල් පිටපත් වල තැපැල් පිටපත් ස්කෑනරය .
luser droog

51
ඔබ (හෝ පිළිතුරු වලින් බහුතරයක්) උපුටා දැක්වීමේ කාරණය තේරුම් ගනී යැයි මම නොසිතමි. රියල් ක්‍රමලේඛකයෙකු පැස්කල් හෝ LISP හි ලිවුවද ෆෝට්රාන් මෙන් පෙනෙන කේතයක් ලියන බවක් නොවේ: පැස්කල් හෝ LISP හි ලිවීමේදී පවා ඔහු ෆෝට්රාන් සිතීමේ ක්‍රමයක් අනුගමනය කරයි; උදා: " සියලු තාත්වික ක්‍රමලේඛකයින් දන්නා පරිදි, එකම ප්‍රයෝජනවත් දත්ත ව්‍යුහය අරාව වේ. " විශිෂ්ට පිළිතුරු වනුයේ Prolog හි කාර්ය පටිපාටික කේතය, C හි ක්‍රියාකාරී කේතය, පැස්කල්හි වස්තු-නැඹුරු කේතයයි.
පීටර් ටේලර්

1
මම හිතන්නේ කවුරුහරි ලිස්ප් උපභාෂාවක් කරයි, හොඳයි, තවත් ලිස්ප් උපභාෂාවක් හැර වෙන කිසිවක් ...
ජයිඩ්

6
@itsjeyd ග්‍රීන්ස්පන්ගේ ක්‍රමලේඛනයේ දහවන රීතිය : "ප්‍රමාණවත් තරම් සංකීර්ණ C හෝ ෆෝට්රාන් වැඩසටහනක තාවකාලික, අවිධිමත් ලෙස නිශ්චිතව දක්වා ඇති, දෝෂ සහිත, පොදු ලිස්ප් වලින් අඩක් මන්දගාමීව ක්‍රියාත්මක කිරීම අඩංගු වේ."
ජෝෂුවා ටේලර්

Answers:


142

සී ++ හි සී

#include <stdio.h>

int main(int argc, char** argv)
{
        printf("Hello world!\n");
        return 0;
}

60
ඔබ එහි කළ දේ මට පෙනේ;)
el.pescado

27
හොඳයි, එය ලාභ උපක්‍රමයක් වන අතර, C ++ සී සමඟ 'පසුපසට අනුකූල වේ'
Agi Hammerthief

5
Lex ඇලෙක්ස්එම්. මම මේ දීර්ඝ (කාර්ය පටිපාටික) උදාහරණය පැහැදිලිව සමහර පන්ති හා වන සමහර STL යහපත්කම තවත් බොහෝ සාධාරණ (කියන්න වනු ඇත එහිදී වෙනත් සී ස්පාඥ භාවිතා භාවිතා ප්රතිලාභ ලැබෙන නම් එය ප්රශ්නයක් බලය වැඩි කළ හැකි යැයි සිතන char*වෙනුවට std::string).
මාටින් එන්ඩර්

47
C, C ++, Objective-C, සහ Objective-C ++ වලංගු වේ ! මොනතරම් පුදුම සහගත බහු භාෂා පිළිතුරක්ද?
nneonneo

7
En බෙන් ජැක්සන් පීඑස්, සැබෑ සී ක්‍රමලේඛකයින් භාවිතා කරයි char *argv[]!
තෝමස්

123

x86 GNU C හි එකලස් කිරීම

නැත, මම යතුරුපදය පමණක් භාවිතා නොකළෙමි asm, මෙය ස්ථාපිත කර ඇති ප්‍රශ්නය සැබෑ ක්‍රමලේඛකයින් සඳහා වන බැවින් ... මෙය ARM මත හොඳින් ක්‍රියාත්මක විය යුතුය.

(කාරණය සනාථ කිරීම සඳහා, මම එකලස් කිරීම කිසිසේත් ලියා නැත - එය ඉහළින් අදහස් දැක්වූ කේතය සඳහා ජීසීසී ක්ලැන්ග් (503.0.38) විසින් නිපදවන ලද ප්‍රතිදානය වන අතර එය අන්ධ ලෙස මැක්‍රෝස් බවට පරිවර්තනය කර ඇත.)

මෙය ක්‍රියාත්මක වන්නේ 32-බිට් ප්‍රකාරයේදී පමණි. සැබෑ ක්‍රමලේඛකයින් කෙසේ හෝ වචන ප්‍රමාණයට කේත කරන බැවින් එය හොඳයි .

#include <stdio.h>
#include <stdint.h>
/*
int fac(int x) {
    if (x < 1) return 1; else return x * fac(x - 1);
}

int fib(int x) {
    if (x < 2) return x; else return fib(x - 1) + fib(x - 2);
}

int main(void) {
    int a = fib(10), b = fac(10);
    printf("%d %d\n", a, b);
    return 0;
}
*/

typedef union REG {
    intptr_t i; int _i; void * v; union REG * r;
} REG;

#define LPAREN (
#define RPAREN )
#define MACRO(N) ); N##_MACRO LPAREN

#define push MACRO(PUSH)
#define pop  MACRO(POP)
#define mov  MACRO(MOV)
#define sub  MACRO(SUB)
#define add  MACRO(ADD)
#define imul MACRO(IMUL)
#define cmp  MACRO(CMP)
#define jge  MACRO(JGE)
#define jmp  MACRO(JMP)
#define call MACRO(CALL)
#define ret  MACRO(RET) _
#define label MACRO(LABEL)

#define NO_OP(X) 

#define PUSH_MACRO(VAL) *(esp -= 4) = (REG)(VAL)
#define POP_MACRO(DST) (DST) = (typeof(DST))(esp->i); esp += 4
#define MOV_MACRO(VAL, DST) (DST) = (typeof(DST))((REG)VAL).i;
#define SUB_MACRO(VAL, DST) CMP_MACRO(VAL, DST); \
    (DST) = (typeof(DST))(((REG)DST).i - ((REG)VAL).i)
#define ADD_MACRO(VAL, DST) DST = (typeof(DST))(((REG)DST).i + ((REG)VAL).i); \
    ZF = ((REG)DST).i == 0; OF = 0; SF = ((REG)DST).i < 0
#define IMUL_MACRO(VAL, DST) DST = (typeof(DST))(((REG)DST).i * ((REG)VAL).i); \
    ZF = ((REG)DST).i == 0; OF = 0; SF = ((REG)DST).i < 0
#define CMP_MACRO(L, R) CMP_MACRO_(((REG)L).i, ((REG)R).i)
#define CMP_MACRO_(L, R) (OF = 0, ZF = L == R, SF = (R - L) < 0)
#define JGE_MACRO(TGT) if (SF == OF) { goto TGT; } else {}
#define JMP_MACRO(TGT) goto TGT;
#define CALL_MACRO(PROC) CALL_MACRO_(PROC, __COUNTER__)
#define CALL_MACRO_(PROC, CTR) PUSH_MACRO(CTR - STARTIP); \
    goto PROC; case CTR - STARTIP:
#define RET_MACRO(_) eip = esp->i; esp += 4; if (eip) { continue; } else { goto *finalreturn; }
#define LABEL_MACRO(NAME) NAME

#define MY_ASM(X) do { const int STARTIP = __COUNTER__; \
    switch(eip) { case 0: MY_ASM_1 X } } while (1);
#define MY_ASM_1(X) MY_ASM_2(NO_OP LPAREN 0 X RPAREN;)
#define MY_ASM_2(X) X

#define CAT(L, R) _CAT(L, R)
#define _CAT(L, R) L##R

#define callASM(F) callASM_(F, CAT(_TMP_, __COUNTER__))
#define callASM_(F, LABEL) (({ PUSH_MACRO(0); stackbase = esp; finalreturn = &&LABEL; \
    goto F; LABEL:; }), (intptr_t)eax)


const int STACKSIZE = 4096;
REG callstack[STACKSIZE], * stackbase;
REG * eax, * ecx, * edx, * ebx, * esi, * edi, * esp, * ebp;
int SF, ZF, OF, eip; void * finalreturn;

int main(void) {
    eax = ecx = edx = ebx = esi = edi = esp = ebp = &callstack[STACKSIZE - 1];
    eip = 0;
    finalreturn = &&TOP; TOP:

    PUSH_MACRO(10);
    int a = callASM(_fac);
    PUSH_MACRO(10);
    int b = callASM(_fib);

    printf("%d %d\n", a, b);
    return 0;


    MY_ASM((
    label _fac:                                   // @fac
        push ebp
        mov esp, ebp
        sub 24, esp
        mov 8[ebp], eax
        mov eax, (-8)[ebp]
        cmp 1, (-8)[ebp]
        jge LBB0_2
        mov 1, (-4)[ebp]
        jmp LBB0_3
    label LBB0_2:
        mov (-8)[ebp], eax
        mov (-8)[ebp], ecx
        sub 1, ecx
        mov ecx, *esp
        mov eax, (-12)[ebp]         // 4-byte Spill
        call _fac
        mov (-12)[ebp], ecx         // 4-byte Reload
        imul eax, ecx
        mov ecx, (-4)[ebp]
    label LBB0_3:
        mov (-4)[ebp], eax
        add 24, esp
        pop ebp
        ret

    label _fib:                                   // @fib
        push ebp
        mov esp, ebp
        sub 24, esp
        mov 8[ebp], eax
        mov eax, (-8)[ebp]
        cmp 2, (-8)[ebp]
        jge LBB1_2
        mov (-8)[ebp], eax
        mov eax, (-4)[ebp]
        jmp LBB1_3
    label LBB1_2:
        mov (-8)[ebp], eax
        sub 1, eax
        mov eax, *esp
        call _fib
        mov (-8)[ebp], ecx
        sub 2, ecx
        mov ecx, *esp
        mov eax, (-12)[ebp]         // 4-byte Spill
        call _fib
        mov (-12)[ebp], ecx         // 4-byte Reload
        add eax, ecx
        mov ecx, (-4)[ebp]
    label LBB1_3:
        mov (-4)[ebp], eax
        add 24, esp
        pop ebp
        ret
    ))
}

ඒ හැම දෙයක්ම බලන්න. කාස්ට්ස් කියන්නේ මම සම්පාදකයාට වඩා අලෙවිකරු ක්‍රමලේඛකයෙක් නේද?


8
+1, ඒ ... විකෘති. ;) මම callවිශේෂයෙන් කැමතියි ඔබ හැසිරවූ ආකාරය , විශේෂයෙන්.
ඉල්මාරි කරොනන්

2
වොව්. ඒක නියම වැඩක්.
ජැක් ඒඩ්ලි

මට C64 සඳහා එකලස් කරන්නෙකු සිටියේය. එය සියලු 6510 උපදෙස් සඳහා මූලික වචන එකතු කළ අතර මට මතකයි ඔබ for pass=1:3...nextඑය වටා ඔතා . BASIC පරිවර්තකය තුළ එය ක්‍රියාත්මක කිරීම එකලස් කරන ලදි.
බෙන් ජැක්සන්

5
මෙය පිරිසිදු කාව්‍යයකි.
නිකු ස්ටුර්කා

1
මෙය දැඩි මිනිසෙකි, සම්පාදකයා පුදුමයට පත් වේ.
ටෙහ් ඉන්ටර්නෙට්ස් කැට්ස්

102

සී හි ඉංග්‍රීසි

#include <stdio.h>
#define This
#define program     int main() {
#define aims
#define to
#define output      printf(
#define some
#define example
#define text(a)     #a
#define the
#define screen      "\n");
#define it          
#define also
#define will
#define calculate   ;int a = 
#define result
#define of
#define and
#define print       ; printf("%d\n", a);
#define seriously   return 0; }

This program aims to output some example text (Hello) to the screen;
it also will calculate the result of 3 + 4 and print the result; seriously

තුරන් කිරීමට අදහස් ;තිබේද?


18
ඇත්තටම, ඔයාලා.
කයිල් ස්ට්‍රෑන්ඩ්

2
theදෙවරක් නිර්වචනය කරන්නේ ඇයි ?
ජෝෂුවා ටේලර්

16
කණගාටු වීමට වඩා ආරක්ෂිතයි ;-)
urzeit කරන්න

20
දැන් එය හයිකු කරන්න.
නිකු ස්ටුර්කා

1
ඔබට පුළුවන්ද#define . ;
mbomb007

75

ජාවාස්ක්‍රිප්ට් හි මොළය

ජාවාස්ක්‍රිප්ට් යනු දුෂ්කර භාෂාවකි! වඩාත් තේරුම්ගත හැකි භාෂාවක් වන බ්‍රේන්ෆක් භාවිතා කරමු: o)

eval(

//write your easy code below

"++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."

//end of easy code

.replace(/\]/g,'}')
.replace(/\[/g,'while(a[i]){')
.replace(/\+/g,'a[i]++;')
.replace(/-/g,'a[i]--;')
.replace(/>/g,'i++;')
.replace(/</g,'i--;')
.replace(/\./g,'o+=String.fromCharCode(a[i]);')
.replace(/,/g,'a[i]=u.charCodeAt(j++);')
.replace(/^/,'var a=new Array(1000).join(\'0\').split(\'\'),i=500,o=\'\',u=prompt(\'Enter input if needed\'),j=0;')
.replace(/$/,'alert(o)')
)

මම හිතන්නේ මම ජාවාස්ක්‍රිප්ට් එකේ මොළකාරක පරිවර්තකයෙක් ලිව්වා.

ඉහත උදාහරණය හුදෙක් පිටතට Hello World!ගොස් ආදානය නොසලකා හරින්න ( ,සංකේතයක් නැත ).
නමුත් එය යෙදවුම් සමඟද ක්‍රියා කරයි! උදාහරණයක් ලෙස, උත්සාහ ,+>,+>,+>,+<<<.>.>.>.කර ටයිප් කරන්නgolf දෙබස කර . එය ASCII වගුවේ ඊළඟ අක්ෂර ඉවත් කරයි:hpmg

සංස්කරණය කරන්න : මොළය නොදන්නා අය සඳහා කෙටි පැහැදිලි කිරීමක්. සෑම තැනකම බිංදුවට ආරම්භ කරන
ලද අසීමිත නිඛිල සංඛ්‍යාවක් a, මෙම අරාවේ එක් අංගයක් පිළිබඳ දර්ශකයක් iසහ පරිශීලක ආදානයක් ගැන සිතන්න u.
බ්‍රේන්ෆක් ඉගෙන ගැනීමට පහසු නමුත් ලිවීමට අපහසුය:

  • + වත්මන් වටිනාකමට වර්ධක: a[i]++
  • - එය අඩු කරයි: a[i]--
  • > ඊළඟ මූලද්‍රව්‍යය යොමු කිරීමට යොමු කරයි: i++
  • < පෙර : i--
  • [ හා ] වත්මන් වටිනාකම ශුන්ය වන විට කැඞී වන පුඩුවක් අර්ථ:while (a[i]) { ... }
  • . වත්මන් අංගය මුද්‍රණය කරන්න: String.fromCharCode(a[i])
  • , වත්මන් අංගය පරිශීලක ආදානය සමඟ සකසයි: u.charCodeAt(...)

22
ජාවාස්ක්‍රිප්ට් වලට වඩා මොළය තේරුම් ගත හැකි බව ප්‍රකාශ කිරීමේදී හාස්‍යය සඳහා +1.
Agi Hammerthief

replaceප්‍රකාශවල ඇති බ්‍රයින්ෆක් අක්ෂර වැඩසටහනට බලපාන්නේ නැති බව ඔබට විශ්වාසද ?
ෆ්‍රැක්ටිල්

3
filefra මෙම ගොනුව මොළයේ වැඩ කරන වැඩසටහනක් නොවේ, එය ජාවාස්ක්‍රිප්ට් වැඩසටහනක් වන අතර එය ක්‍රියාකාරී වේලාවේදී ජාවාස්ක්‍රිප්ට් බවට පරිවර්තනය කරන ලද මොළයේ ක්‍රියාකාරී වැඩසටහනකි.
භූගත මොනෝරේල්

3
හොඳයි, --iවඩා වේගවත් i--? වසර ගණනාවක සිට අසත්‍ය බව පෙනේ: jsperf.com/decrementgolf .
මයිකල් එම්.

4
මෙය ඉතා නිර්මාණාත්මකව තරඟයට ඉදිරිපත් කිරීම පමණක් නොව, මොළයේ ඇති වාක්‍ය ඛණ්ඩය ඉතා පැහැදිලිව පැහැදිලි කරයි. +10 මට හැකි නම්!
සෙබස්තියන් එච්

74

මම හිතන්නේ දීප්තිමත් ලෙනාට් ඔගස්ට්සන් මේ වන විටත් දෙවරක් ජයග්‍රහණය කර ඇත.

පළමුවෙන්ම, 2009 සිට ඔහු "සති අන්ත හැක්" බේසික් හස්කල් මොනාඩික් ඩීඑස්එල් ලෙස ක්‍රියාත්මක කිරීම පිළිබඳ උදාහරණයක් මෙන්න:

import BASIC

main = runBASIC' $ do

    10 LET I =: 1
    20 LET S =: 0
    30 LET S =: S + 1/I
    40 LET I =: I + 1
    50 IF I <> 100000000 THEN 30
    60 PRINT "Almost infinity is"
    70 PRINT S
    80 END

එය ක්‍රියාත්මක වන්නේ සංඛ්‍යා වර්ගය අධික ලෙස පැටවීමෙනි. රේඛා අංක යනු සැබවින්ම තර්ක පිළිගන්නා ශ්‍රිත වේ. රේඛාවේ ඉතිරි කොටස ශ්‍රිතයට තර්ක වේ. මෙම ශ්‍රිතය මඟින් මූලික පරිවර්තකයාට වැඩ කිරීමට යාම සඳහා වියුක්ත සින්ටැක්ස් ගස නිරූපණය කරයි.

ඔගස්ට්සන් 2006 අන්තර්ජාතික අපැහැදිලි සී තරඟයට පිවිසීම පරීක්ෂා කර බැලීමට මම ඔබට නිර්දේශ කරමි.

  • C හි උප කුලකයක ලියා ඇති බයිටෙකෝඩ් පරිවර්තකය (ඔහු එය අපැහැදිලි C ලෙස හඳුන්වයි).
  • Obfuscated සී -> bytecode සිදුවීමටත්, bytecode ලියා.

බයිට් කේතය සී විවරණ තුළ තැන්පත් කර ඇති නිසා ඔවුන්ට එකම ගොනුව බෙදා ගත හැකිය.

මම ඔගස්ට්සන්ගේ කෘතිය අනුගමනය කර වසර කිහිපයක් ගත වී ඇත, එනිසා ඔහු එතැන් සිට ඉදිරිපත් කර ඇති තවත් දීප්තිමත් දේවල් තිබිය හැකිය ....


2
එය ඔගස්ට්සන් මිස ඔගස්ට්සන් නොවේ.
හාන්ස් ලුන්ඩ්මාර්ක්

@ හැන්ස්ලන්ඩ්මාර්ක් ස්තූතියි. එය සවි කර ඇත.
පිටාරූ

71

PHP සහ Javascript

මෙය බහුභාෂාවකි:

ඔබට මෙම කේතය භාෂා දෙකෙන්ම ක්‍රියාත්මක කළ හැකිය:

if("\0"=='\0')
{
    function printf(){
        $b=Array();
        $a=$b['slice']['call'](arguments);
        $a=$a['join']('');
        console.log($a);
        return $a.length;
    };

    function strtoupper($s){return $s['toUpperCase']();}

    function count($a){return $a['length'];}
}

printf('this is cool!');

$c=Array('a','b','c','d');

for($i=0,$l=count($c);$i<$l;++$i)printf("\n",strtoupper($c[$i]));

මෙහි ඇති උපක්‍රමය නම් ජාවාස්ක්‍රිප්ට් ආරම්භ වන 'සහ ආරම්භ වන නූල්වල ගැලවීමේ අනුක්‍රම භාවිතා "කිරීමයි.
අනෙක් අතට, PHP භාවිතා කරන්නේ "සහ ආරම්භ වන නූල්වල ගැලවීමේ අනුක්‍රමයන් පමණි <<<.

ඉන්පසුව, අපි ශ්‍රිතය ප්‍රකාශයට පත් කරන්නෙමු printf, එය printPHP හි ආකෘතිගත නූලකට සමාන නමුත් ප්‍රතිදානය කරයි.

PHP සඳහා vars ආරම්භ කළ යුතු $අතර Javascript සරලව ඉඩ දෙයි.


Array(…)JS හි කිසිවෙකු භාවිතා නොකරන අතර එය පැහැදිලිවම array(…)PHP හි ඇත. […]වඩා හොඳ වනු ඇත;)!
බ්ලැක්හෝල්

12
මිනිසුන් Array()JS හි භාවිතා කරන්නේද නැද්ද යන්න මට ප්‍රශ්නයක් නොවේ: මට සත්‍ය බහුඅවයවයක් ඇති බව මම සලකමි. මම, මෙම කේතය සමඟ නරකම JS අපරාධ එක් කරමින් ඉන්නේ නමුත් මට ඕන සියලුම එය අවසන් වන්නේ නැත බව ය නිශ්චිත දෙකේම එකම දෙයක්, නමුත් එම අවස්ථාවේදීම, JS හා PHP වගේ බලා.
ඉස්මයිල් මිගෙල්

සහ btw, [...]PHP <5.4.0 හි වලංගු නොවේ, එය නරකයි ....... මම මෙය PHP 4, 5 හෝ Javascript වලට විසි කළහොත්, සෑම තැනකම සින්ටැක්ස් දෝෂ ලබා දීම වෙනුවට එය ක්‍රියාත්මක වනු ඇතැයි මම අපේක්ෂා කරමි.
ඉස්මයිල් මිගෙල්

2
ඔබේ කේතය ජේඑස් මෙන් පෙනෙන්නට අවශ්‍ය නම්, ඔබ භාවිතා කළ යුතු[…] අතර එය PHP හි ප්‍රමිතියකින් යුක්ත බව පෙනේ, එබැවින් ඔබේ ඉලක්කය සඳහා එය හරි ය. මාර්ගය වන විට, PHP <5.4? යාවත්කාලීන කිරීමට කාලයයි,
මිනිහෝ

8
"පෙනුමට" වඩා අනුකූලතාව වැදගත් ය. හා Arrayයනු දකුණු අරාව වස්තුව ගේ ඉදිකිරීමටත් නම. මූලික වශයෙන්, භාවිතා []කිරීම සමාන වේ Array(). මම එහි නරක දෙයක් දකින්නේ නැහැ. නමුත් මට එක සරල ප්‍රශ්නයක් තිබේ: ක්‍රියා? (btw, මට වැඩ කිරීමේදී php 5.3.28 භාවිතා කළ යුතුය.)
ඉස්මයිල් මිගෙල්

56

ජේඑස් හි මොළය

[][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[
!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[
+!+[]]]]][([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(
![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!
![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+
[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]
]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[
]+!+[]+!+[]+!+[]]]]+([][[]]+[])[+[[+!+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(!!
[]+[])[+[[+[]]]]+(!![]+[])[+[[+!+[]]]]+([][[]]+[])[+[[+[]]]]+([][(![]+[])[+[[
+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!
![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+
[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[
[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!!
[]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]+!+[]
+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]((![]+[])[+[[+!+[]]]]+(![]+[])[+[[!+[]+!+
[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]+(!![]+[])[+[[+[]]]
]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[
+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[
+[[+!+[]]]]]+[])[+[[+!+[]]]+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+[+!+[]]+([][(![]+[]
)[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]
]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+
[])[+[[+!+[]]]+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]])()

12
මම මෙතන කිසිම මොළයක් දකින්නේ නැහැ. තනි කටු පවා නැත><,.-
මයිකල් එම්

8
Ic මයිකල්: කවුද කිව්වේ එය අසීමිත පුඩුවක් සාදන වැඩසටහනක් නොවන බව?
කොන්රාඩ් බොරොව්ස්කි

19
මේ JSF * ck ද?

8
එය පෘථිවිය මත ආකාරය කරන්නේ බව ?
nandhp

4
ඕ. කවුරුහරි අවසානයේ මෙය කළා. +! [] () අක්ෂර පමණක් භාවිතා කරමින් JS වැඩසටහනක් ලියන්නේ කෙසේදැයි සොයා බැලීමට මම කාලයක් ගත කළෙමි. මට කාලය ඇති විට මෙය විශ්ලේෂණය කිරීමට අවශ්‍යයි ...
Matti Virkkunen

54

මෙය 2005 අයිඕසීසීසී ජයග්‍රාහකයන්ගෙන් එකකි , සී වැඩසටහන, එම නිර්වචන සමූහය හැර, ජාවා වැඩසටහනක් ලෙස පෙනේ:

/*
 * Sun's Java is often touted as being "portable", even though my code won't
 * suddenly become uber-portable if it's in Java. Truth is, Java's one of
 * the most ugly, slow, and straitjacketed languages ever. It's popular
 * mainly because people hear the word "portable" and go "ewww".
 *
 * This program, then, is dedicated to bringing about the death of Java. We
 * good coders have been oppressed for too long by the lame language
 * decisions of pointy-haired bosses and academics who should know better. 
 * It's time we stand up against this junk, and bring back the fun in
 * programming! Viva La Revolution!
 */

#define aSet c
#define BufferedReader(x)1
#define byte Y[I][_^1]?do(:):_&1?do(.):do(`):8;++y;}
#define class int N=0,_,O=328,l=192,y=4,Y[80][64]={0},I;struct
#define do(c)a(#c "\b")
#define err c,c
#define getAllStrings(x));q()
#define if(x)b(#x)
#define IOException
#define line c
#define main(a)b(char*x){write(1,"\033[",2),null}main()
#define new
#define null a(x);}a(char*x){write(1,x,strlen(x));try;try;try;try;
#define out c,c
#define println(x)c
#define private int d(int
#define public short c;}c;typedef int BufferedReader;char*F="JF>:>FB;;BII";
#define return {return
#define static f(x){N=(N+x)%6,y--?f(0),f(1),f(4),f(1):++Y[(I=O+N[F]-66)
#define String
#define System c
#define this if(D):1,O=I,I/=16,l<_/32?if(B):l>_/32?if(A):2,l=_,_/=16,byte
#define throws
#define toArray(x)c
#define try for(;--c.c;)
#define void /16][(_=l+N[6+F]-66)/16]?O/=16,l/=32,O<I/16?if(C):O>I/16?this
#define while(k)if(2J),if(7;21H),f(0),f(4),f(4),if(H),/*

import java.io.*;
import java.util.*;

/**
 * A lame Java program.
 * @author  J. Random Worker
 */
class LameJavaApp
{

    /** The infamous Long-Winded Signature From Hell. */
    public static void main(String[] args)
        throws IOException
    {
        /* Don't get me started on this. */
        BufferedReader reader =
            new BufferedReader(new FileReader(args[0]));

        /* What, this long incantation just to print a string? */
        System.err.println("Hello world!");

        /* At least this is sane. */
        String line;
        while ((line = reader.readLine()) != null)
            System.out.println(line.length());
    }

    /**
     * Method with a needlessly long name.
     * @param   aSet        a set (!)
     */
    private String[] getAllStrings(Set<String> aSet)
    {
        /*
         * This dance is needed even in J2SE 5, which has type
         * templates. It was worse before that.
         */
        return aSet.toArray(new String[0]);
    }

}

3
වාචිකතාව එහි උපරිමයෙන්.
qwr

39

සී ++ සී

හරි, ඉතින් ඔබ C ++ ක්‍රමලේඛකයෙක්, නමුත් C භාවිතා කිරීමට බල කෙරේද? ගැටළුවක් නැත, ඔබට සී හි නැතිවූ අතිරේක ශීර්ෂ කිහිපයක් ලිවිය යුතුය. නිදසුනක් ලෙස, සී හි වලංගු හෙලෝ වර්ල්ඩ් වැඩසටහනක් මෙන්න:

අතිරේක ශීර්ෂ ගොනුවේ iostream, ලියන්න:

#include <stdio.h>

#define using volatile int
#define namespace message
#define std = 0
#define message(x) printf("%s\n",x)
#define cout 0
#define endl 0

ගොනුවේ string, ලියන්න

#define string

ගොනුවේ helloworld.c(ඔබේ සත්‍ය සී කේතය) ලියන්න

#include <iostream>
#include <string>

using namespace std;

int main()
{
  string message("Hello world");
  cout << message << endl;
  return 0;
}

හා සම්පාදනය විට helloworld.cසම්පාදකවරයා උපදෙස් ලබා සී සිදුවීමටත්, ද සොයා ගැනීමට සමග <...>ඔබ ගොනු ගබඩා කර ඕනෑම තැනක ශීර්ෂ ගොනු iostreamහාstring ඔබ gcc සමග සම්පාදනය කර ඇති අතර ගොනු තබා නම්, උදාහරණයක් ලෙස iostreamහා string, වර්තමාන නාමාවලියේ සමග ඇති බැදීමකට

gcc helloworld.c -o helloworld -I.

සටහන: volatileශීර්ෂකයiostream උපරිම අනතුරු ඇඟවීමේ මට්ටමින් පවා අනතුරු ඇඟවීම් රහිත සම්පාදනයක් සක්‍රීය කිරීම සඳහා ඇත (වාෂ්පශීලී විචල්‍යයකින් කියවීම බලපෑමක් ඇති කරයි).


3
මෙය ටිකක් කේත ට්‍රොලිං කිරීමකි, එසේ නොවේ.
ලිස්ටර් මහතා

හොඳයි, වැඩසටහන හරියටම පෙනෙන ආකාරයටම කරයි, එසේ නොවේ ද?
celtschk

8
C ++ හි C ට වඩා බොහෝ විනෝදජනක හා ආකර්ෂණීය මේ ආකාරයෙන්.
කයිල් ස්ට්‍රෑන්ඩ්

ඔබ volatileමෙහි භාවිතා නොකරන්නේ නම් කුමන ආකාරයේ සම්පාදකයෙකු අනතුරු අඟවයි , සහ කුමන ආකාරයේ අනතුරු ඇඟවීමක්ද?
ආර්. මාටින්හෝ ෆර්නැන්ඩස්

1
YleKyleStrand නමුත් "C ++ C ++" එක ප්‍රශ්නයේ උපුටා දැක්වීම සමඟ වඩාත් ගැලපේ. C ++ සම්පාදකයෙකු සිටියත් C හි තාත්වික ක්‍රමලේඛකයින්ගේ වැඩසටහන.
ලිස්ටර් මහතා

36

CQL - කැෆේන් කළ විමසුම් භාෂාව

(හෝ "SQL මත කැෆේන්")

මෙය තරමක් ඕනෑවට වඩා අභිලාෂකාමී වන්නට ඇත. කෝපි ස්ක්‍රිප්ට් හි SQL (ish) ප්‍රකාශන කේතය ලිවීමේ උත්සාහයක් මෙන්න . මේ සඳහා ECMAScript 6 ප්‍රොක්සි විශේෂාංගය අවශ්‍ය වේ . ඔබට එය සමඟ නෝඩ් එකකින් පරීක්ෂා කළ හැකිය --harmony-proxies.

ප්‍රොක්සි නිර්වචනය කිරීම සඳහා අච්චුවක් සකස් කරමු. ( මෙම ප්‍රශ්නය පිළිබඳ බෙන්විගේ අදහස් දැක්වීමෙන් )

forward = (->
  _slice  = Array.prototype.slice
  _bind   = Function.prototype.bind
  _apply  = Function.prototype.apply
  _hasOwn = Object.prototype.hasOwnProperty

  Forwarder = (target) ->
    @target = target
    this

  Forwarder.prototype =
    getOwnPropertyNames: -> Object.getOwnPropertyNames(@target)
    keys: -> Object.keys(@target)
    enumerate: ->
      i = 0
      keys = []
      for value of @target
        keys[i++] = value
      keys
    getPropertyDescriptor: (key) ->
      o = @target;
      while o
        desc = Object.getOwnPropertyDescriptor o, key
        if desc
          desc.configurable = true;
          return desc;

        o = Object.getPrototypeOf o
    getOwnPropertyDescriptor: (key) ->
      desc = Object.getOwnPropertyDescriptor @target, key
      if desc
        desc.configurable = true
      desc
    defineProperty: (key, desc) -> Object.defineProperty @target, key, desc
    get: (receiver, key) -> @target[key]
    set: (receiver, key, value) ->
      @target[key] = value;
      true
    has: (key) -> key of @target
    hasOwn: (key) -> _hasOwn.call @target, key
    delete: (key) ->
      delete @target[key]
      true
    apply: (receiver, args) -> _apply.call @target, receiver, args
    construct: (args) -> new (_bind.apply @target, [null].concat args);

  forward = (target, overrides) ->
    handler = new Forwarder target;
    for k of Object overrides
      handler[k] = overrides[k]

    if typeof target is 'function'
      return Proxy.createFunction handler,
                                  -> handler.apply this, _slice.call arguments,
                                  -> handler.construct _slice.call arguments
    else
      return Proxy.create handler, Object.getPrototypeOf Object target

  forward
)();

දැන් ප්‍රොක්සි වස්තුවක් සහ සැක සහිත ගෝලීය විචල්‍යයන් සහ ක්‍රියාකාරකම් නිර්වචනය කරන්න:

sql = forward {
  tables: {}

  finalize: ->
    if typeof @activeRows isnt 'function'
      @result = []
      for row in @activeRows
        @result.push (val for val, i in row when @activeTable.columns[i] in @activeColumns)
    delete @activeRows
    delete @activeColumns
    delete @activeTable

  run: (q) ->
    q.call(this)
    @finalize()
    result = @result
    delete @result
    if typeof result isnt 'function' then console.log result
    return result
}, {
  get: (o,name) ->
    if name of @target
      return @target[name];
    (args...) -> {
      name
      args
    }
}

int = Number
varchar = (l) -> String

TABLE = (x) -> x
INTO = (x) -> x
CREATE = (tableData) ->
  name = tableData.name
  table =
    columns: []
  column = tableData.args[0]
  table[column.name] = []
  table.columns.push(column.name)
  while column = column.args[1]
    table[column.name] = []
    table.columns.push(column.name)

  sql.tables[name] = table

  sql.result = "Created table '#{name}'"

INSERT = (table) -> sql.activeTable = sql.tables[table().name]
VALUES = (rows...) ->
  for row in rows
    for val, i in row
      column = sql.activeTable.columns[i]
      sql.activeTable[column].push val

  sql.result = "Inserted #{rows.length} rows"

FROM = (table) ->
  sql.activeTable = sql.tables[table().name]
SELECT = (columns...) ->
  sql.activeColumns = []
  for col in columns
    if typeof col is 'function'
      col = col()

    sql.activeColumns.push col.name

  sql.activeRows = []
  for val in sql.activeTable[sql.activeTable.columns[0]]
    sql.activeRows.push []

  for col in sql.activeTable.columns
    for val, i in sql.activeTable[col]
      sql.activeRows[i].push val

IN = (list) -> { op: 'in', list }
WHERE = (column) ->
  i = sql.activeTable.columns.indexOf(column.name)
  if column.args[0].op is 'in'
    list = column.args[0].list
    sql.activeRows = (row for row in sql.activeRows when row[i] in list)
  else
    console.log 'Not supported!'

ASC = 'asc'
DESC = 'desc'
BY = (x) -> x
ORDER = (column) ->
  i = sql.activeTable.columns.indexOf(column.name)
  order = if column.args[0] is sql.ASC then 1 else -1
  sql.activeRows.sort (a,b) ->
    if a[i] < b[i]
      return -order
    else if a[i] > b[i]
      return order
    else
      return 0

හොඳයි, එය බොහෝ සැකසුම් විය! නමුත් දැන් අපට පහත සඳහන් දෑ කළ හැකිය (ආදාන / ප්‍රතිදානය කොන්සෝල ශෛලියකින්):

> sql.run ->
    CREATE TABLE @books(
      @title varchar(255),
      @author varchar(255),
      @year int
    );

Create Table 'books'

> sql.run ->
    INSERT INTO @books
    VALUES ['The C++ Programming Language', 'Bjarne Stroustrup', 1985],
           ['Effective C++', 'Scott Meyers', 1992],
           ['Exceptional C++', 'Herb Sutter', 2000],
           ['Effective STL', 'Scott Meyers', 2001];

Inserted 4 rows

> sql.run ->
    SELECT @title, @year FROM @books
    WHERE @author IN ['Bjarne Stroustrup', 'Scott Meyers']
    ORDER BY @year DESC;

[ [ 'Effective STL', 2001 ],
  [ 'Effective C++', 1992 ],
  [ 'The C++ Programming Language', 1985 ] ]

එය සත්‍ය බහු භාෂාවක් නොවේ, නමුත් එය ඇත්ත වශයෙන්ම කාරණය නොවේ. @SQL හි විචල්‍යයන් සඳහා එය භාවිතා වන බව මම දනිමි , නමුත් මට ඒ සියල්ල අවශ්‍ය වේ@ ගෝලීය වස්තුව ප්‍රොක්සි කිරීමට ක්‍රමයක් සොයා නොගත් නිසා මට තීරු සහ වගු නම් (එය සැබවින්ම කළ නොහැකි නම් මම පුදුම නොවන්නෙමි - සහ හොඳ හේතුවක්).

මම සමහර වරහන් වරහන් බවට වෙනස් කළෙමි (විශේෂයෙන් පසුව VALUESසහ පසුව IN). අවාසනාවකට මෙන්, මට කිසිසේත් හඳුනාගත නොහැකි වූයේ සාමාන්‍ය කොන්දේසි වලට ඉඩ දිය හැකි ක්‍රමයකිyear > 2000 , මන්ද ඒවා වහාම බූලියන් වෙත තක්සේරු කරනු ඇත.

තවමත් මෙය SQL හා සමාන වන අතර අනිවාර්යයෙන්ම අත්‍යවශ්‍ය / ක්‍රියාකාරී / වස්තු-නැඹුරු වලට වඩා ප්‍රකාශිත වේ, එබැවින් එය ප්‍රශ්නයට හොඳින් සුදුසුකම් ලැබිය යුතුය. මම ඇත්ත වශයෙන්ම සිතන්නේ මම කේතය ටිකක් ඔප දමා තවත් විශේෂාංග කිහිපයකට සහය දුන්නොත් මෙය ප්‍රයෝජනවත් කෝපි ස්ක්‍රිප්ට් මොඩියුලයක් විය හැකි බවයි.

කෙසේ වෙතත්, මෙය විනෝදජනක විය! :)

කෝපි ස්ක්‍රිප්ට් ගැන එතරම් හුරු නැති අය සඳහා, SQL විමසුම් පහත ජාවාස්ක්‍රිප්ට් සමඟ සම්පාදනය කරයි:

sql.run(function() {
  return CREATE(
    TABLE(
      this.books(
        this.title(varchar(255), 
        this.author(varchar(255), 
        this.year(int)))
      )
    )
  );
});

sql.run(function() {
  INSERT(INTO(this.books));
  return VALUES([...], ['Effective C++', 'Scott Meyers', 1992], [...], [...]);
});

sql.run(function() {
  SELECT(this.title, this.year(FROM(this.books)));
  WHERE(this.author(IN(['Bjarne Stroustrup', 'Scott Meyers'])));
  return ORDER(BY(this.year(thisESC)));
});

එය සෑහෙන තරම් සැකසුමකි, නමුත් හොඳ පෙනුමක්. මම කෝපි ස්ක්‍රිප්ට් ක්‍රමලේඛකයෙක් නොවෙමි, නමුත් එය විශිෂ්ටයි. මෙම @සැසිය විචල්යයන් සඳහා SQL භාවිතා වේ.
ඉස්මයිල් මිගෙල්

මූලික වචන ගෝලීය කිරීමට මම තීරණය කළෙමි. දැන් ඇත්තේ @තීරු සහ වගු නම් සඳහා පමණි .
මාටින් එන්ඩර්

දැන් එය SQL මෙන් පෙනේ! ඔබ මේ සමඟ හොඳ වැඩක් කළා!
ඉස්මයිල් මිගෙල්

1
මම කෝපි ගැන එතරම් තැකීමක් නොකරමි, නමුත් මෙය නියමයි.
KRyan

2
ස්තූතියි, නමුත් නැහැ, මම මේ අභියෝගය සඳහා එය එකට හැක් කළා. හාස්‍යජනක අහඹු සිදුවීම: මෙය පිරිසිදු ආකාරයකින් නැවත සිදු කිරීම සහ එය GitHub මත තැබීම මම අද උදෑසන එය ඉවත් කරන තෙක් මගේ විභව / දිගු කාලීන කේතීකරණ ව්‍යාපෘති ලැයිස්තුවේ සිටියෙමි.
මාටින් එන්ඩර්

27

දෘශ්‍ය මූලික 6 (ජාවාස්ක්‍රිප්ට් හි)

'; Main sub-routine \
'; function Main() { ' \
Sub Main() '
    ' Do not throw any errors... \
    On Error Resume Next '; MsgBox = alert

    ' Show a message box... \
    MsgBox(1 / 0) '

    ' Show errors again... \
    On Error GoTo 0 '

    ' Show another message box... '
    MsgBox("Hello")
    ' ' } ' \
End Sub '

Main()

එය VBScript හි ද ක්‍රියාත්මක වේ.


1
දක්ෂයි. ඔබට බොහෝ අර්ධ සළකුණු පවා අවශ්‍ය නොවේ.
js1568

@ js1568 ස්තූතියි! මම දැන් අවශ්‍ය නොවන අර්ධ කොලන් ඉවත් කර ඇත.
දත් බුරුසු

20

C ++ හි F #

පූර්ව සකසනය සිතාගත නොහැකි හා නපුරු ලෙස අපයෝජනය කිරීම. ජාවා හෝ පීඑච්පී මෙන් පෙනෙන්නට අන්වර්ථ නාම කිහිපයක් භාවිතා කරනවා වෙනුවට සී ++ සම්පූර්ණයෙන්ම වෙනස් භාෂාවක් ලෙස වෙනස් කිරීම විනෝදජනක යැයි මම සිතුවෙමි. මම මෙය සැබවින්ම බලාපොරොත්තු නොවන්නේ ටොන් ගණනක් ඉහළ නැංවීමයි, එය විනෝදය සඳහා වූ ප්‍රවේශයකි.

#define let int
#define args ( int __, char* args[] ) { int ___ 
#define println printf(
#define exit "\n" ); return 0; }
#include <stdio.h>

let main args =
    println "F# is better than C++"
    exit

එය මෙහි උත්සාහ කරන්න .

කනගාටුවට කරුණක් නම් STDOUT වෙත යමක් ලිවීම එය කළ හැකි සියල්ල ගැන ය, නමුත් මට විශ්වාසයි යමෙකු ඒ සඳහා ප්‍රමාණවත් මායා කර්මයක් විසි කළහොත් ඔවුන්ට එය තවත් කළ හැකිය.


2
එෆ් # වැඩ කරන අන්තිම මාර්ගය සඳහා, එය එක්කෝ විය යුතු විය exit 0හුදෙක් හෝ 0.
ජ්වොස්ටි

20

පයිතන් සහ ... කිසිවෙකු අනුමාන නොකරනු ඇත (සංස්කරණය: dc)

මෙන්න වලංගු පයිතන් කේත කිහිපයක් ඇත, නමුත් ඇත්ත වශයෙන්ම වැඩසටහන ලියා ඇත්තේ වෙනස් භාෂාවෙනි:

# Initialize systems 1 and 2
# frame 1, divergency speed and divergency latency
f1ds, f1dl, z1 = [2,2,0]
# frame 2, divergency speed and divergency latency
f2ds, f2dl, z2 = [4,4,1]

# Set the most relevant value of ax (detected by low-energy collision)
ax = 42.424242

# Initialize list of successive energy states
s = [17.98167, 21.1621, 34.1217218, 57.917182]

# Most common value for nz parameter
# TODO: check if value from the article of A. Einstein is better
nz = 10

if z2>nz or ax in s:
  ax += 6
  f1ds = 8
  f2ds = 16
  z1 = 4
  z2 = 9

f1dl += z1
f2dl += z2

# main loop, iterate over all energy states
# Warning: hit Ctrl-C if nuclear explosion occurs and adjust either z or nz
for k in s:
  z = nz + k
  f1dl = f1ds + f2dl * z - z1 + 3.14
  f2dl = f2ds + f1dl * z - z2 + 10
  if k > 10 or z-2 in s:
    nz += 0xac  # hexadecimal coefficient found in famous article by E. Fermi

කේතය කිසිදු දෝෂයකින් තොරව භාෂා දෙකෙන්ම ක්‍රියාත්මක වේ.

සංයෝජනය ඉතා පිස්සු ය; අනෙක් භාෂාව කීමට පෙර එක් දිනක් හෝ දෙකක් බලා සිටීමට මම සතුටු වෙමි. අනුමාන කිරීම සඳහා කරුණාකර අදහස් දක්වන්න.

සංස්කරණය කරන්න: භාෂාව dc වෙතින් තොග පදනම් කරගත් භාෂාව විය. ඔබ වැනි මෙහි ප්රකට ප්රධාන වචන දැක ගත හැක for, if, or, in, නමුත් අකුරු පමණක් ප්රශ්නයක්! මෙම ,ඩීසී කිසිදු තේරුමක් ඇති ලේඛනය දෙසට හැරී ඇත, එය පිළිබඳ ප්රථම වරට ලිපිය පසු නිසා s(සඳහා එම :).


1
කේතය භාෂා දෙකෙහිම එකම දේ නොකරන්නේ නම්, බෙෆුන්ජ් වැනි භාෂාවකට උපක්‍රමය කළ හැකි යැයි මම සිතමි.
තෝමස් එඩිං

හරි, මම ඇත්ත වශයෙන්ම තෝරාගත් භාෂාව තැබීම සඳහා කේතය සංස්කරණය කරමි.
තෝමස් බාරුචෙල්

18

ඉන්ටෙලිබ් පුස්තකාලය සමඟ ලිප්ස් වැනි කේත ලිවීමට සී ++ ඔබට ඉඩ දෙයි:

(L|DEFUN, ISOMORPHIC, (L|TREE1, TREE2),
   (L|COND, 
     (L|(L|ATOM, TREE1), (L|ATOM, TREE2)),
     (L|(L|ATOM, TREE2), NIL),
     (L|T, (L|AND,
       (L|ISOMORPHIC, (L|CAR, TREE1), 
                      (L|CAR, TREE2)),
       (L|ISOMORPHIC, (L|CDR, TREE1), 
                      (L|CDR, TREE2))
 )))).Evaluate();

cf. http://www.informatimago.com/articles/life-saver.html


4
සාදරයෙන් පිළිගනිමු! පිළිතුර ඔවුන්ගේම කාර්යයක් නොවන විට ඔවුන්ගේ සටහන් ප්‍රජා විකියක් ලෙස සලකුණු කරන ලෙස අපි පරිශීලකයින්ගෙන් ඉල්ලා සිටිමු. (නිසි ආරෝපණය දෙන්න, නමුත් ඔබ දැනටමත් එය කර ඇති නිසා ඔබට ස්තූතියි!)
ජොනතන් වැන් මැට්රේ

මුල් හෝ නැත, ඔබට මගේ ඡන්දය ලැබුණි :)
itsjeyd

15

වයිට්ස්පේස් හි සී #

හරි, පළමුව මේවායින් එකක් උත්සාහ කරන්න, එබැවින් එය සිදුවන ආකාරය බලමු.

using System; //very important  

namespace ConsoleApplication1  //namespace: name whatever you want      
{ 
 //start    
 class  Program  //class name:  also anything    
    {
    //main function 
    static void Main(string[] args) {
        for(int i=0;i<10;i++)   writeOutput(i); 
    } //end main    
    static void writeOutput(int i) { Console.WriteLine(i); }    //display output    


    } //class ends here         

}  //close namespace:   also very important     





//yay!

එක් එක් පේළියේ ඉදිරිපස අවකාශ හතරක් තැබීමෙන් ආකෘතිකරණය ඉස්කුරුප්පු ඇරියේ නම්, මෙන්න එය නැවතත්. අවකාශය සඳහා සහ # ටැබ් සඳහා:

using.System;.//very.important#

namespace.ConsoleApplication1..//namespace:#name.whatever.you.want##
{.
.//start#
.class#Program..//class.name:#also.anything#.
#{
....//main.function#
#static.void.Main(string[].args).{
....#for(int.i=0;i<10;i++)#writeOutput(i);#
#}.//end.main#
#static.void.writeOutput(int#i).{.Console.WriteLine(i);.}#//display.output#

.
.#}.//class.ends.here.##

}..//close.namespace:#also.very.important#.#
.




//yay!

12

HTML සහ CSS

ක්‍රමලේඛන භාෂා නොවේ, නමුත්… මෙම ලේඛනය වලංගු HTML සහ CSS වේ:

<!-- p{color:red} /* -->
<!Doctype html>
<title>This is HTML and CSS</title>
<p>Hi!</p>
<!-- */ -->
<!-- p{color:red} /* -->
<!Doctype html>
<title>This is HTML and CSS</title>
<p>Hi!</p>
<!-- */ -->

මෙය ක්‍රියාත්මක වන්නේ historical තිහාසික හේතූන් මත ස්ටයිල් ෂීට් වල HTML අදහස් දැක්වීමට ඉඩ දී ඇති බැවිනි. ඔහ්, සහ සෑම වලංගු HTML ලේඛනයක්ම වලංගු PHP වැඩසටහනකි, එබැවින් මෙයද PHP වේ. :)




2
HTML සහ CSS ක්‍රමලේඛන භාෂා නොවේ :)
ජෙට්

9

ස්කලා හි සී

පාලම් තට්ටුව වඩාත් ආදර යුගයක් අනුකරණය කරන්නේ නූල් තවමත් අහෝසි වී ඇති බයිට් අරා වලිනි.

// Scala is a dynamic language
import scala.language.{ dynamics, postfixOps }

val self = this

val argc = args.length
val argv = args.map(_.getBytes)

type char = Array[Byte]
object char extends Dynamic {
  // This program uses expanded memory
  val buffers = new scala.collection.mutable.LinkedHashMap[String, char]

  // Malloc char buffer
  def applyDynamic(name: String)(length: Int) =
    buffers(name) = new Array(length)

  def **(argv: Array[Array[Byte]]) = argv
}

object & extends Dynamic {
  // dereference char pointer
  def selectDynamic(name: String) = char.buffers(name)
}

def printf(format: String, buffers: char*) =
  println(
    (format /: buffers){ case (msg, buffer) =>
      // Read string until \0 terminator
      val value = new String(buffer.takeWhile(0 !=))
      // Replace next %s token
      msg.replaceFirst("%s", value)
    }
  )

def scanf(format: String, buffers: char*) =
  buffers foreach { buffer =>
    val line = Console.readLine()
    // Write string to char* buffer
    line.getBytes(0, line.length, buffer, 0)
    // Remember to always null terminate your strings!
    buffer(line.length) = 0
  }

val PATH_MAX = 4096

implicit class Argumenter(args: Pair[_, _]) {
  def apply[T](f: => T) = f
}

object int {
  // Passthrough
  def main[T](f: => T) = f
  def argc = self.argc
}

// terminates the string after the first character
// investigate switching to "xor eax, eax" instead of having a hardcoded 0
// might save 3 bytes and valuable CPU time with this trick
val initialize = (_: char)(1) = 0

def exit(value: Int) = sys.exit(value)
// ---HOMEWORK-ASSIGNMENT-START---

int main(int argc, char **argv) {
  if (argc != 0) {
    printf("This program does not take parameters!");
    exit(1);
  }

  // I've copy pasted this code from somewhere
  // Code reuse is essential if we want to be DRY
  char first(PATH_MAX + 1);
  char last(PATH_MAX + 1);

  printf("Enter your first and last name:\n");
  scanf("%s%s", &first, &last);

  // Still learning references, do I need these here?
  // I've performed benchmarks on printf and I think it's faster this way
  printf("Your full name is %s %s", &first, &last);

  initialize(&first);
  printf("Your signature is %s. %s", &first, &last);

  exit(0);
}

"This program does not take parameters!"
fooled

8

sed සහ APL

මගේ ලොක්කාට අවශ්‍ය වන්නේ මම සෙඩ් ස්ක්‍රිප්ට් ලිවීමටයි, නමුත් මම කැමතියි දවස පුරාම ඒපීඑල් ලිවීමට. එසේ වුවද, ඔහු මගේ රැකියාව ගැන බෙහෙවින් සතුටු වන්නේ එවැනි පිටපත් ඔහුගේ සෙඩ් අනුවාදය සමඟ හොඳින් ක්‍රියාත්මක වන බැවිනි:

i ← g ← 42
a ← d ← 10
s/s←2⊤42/s←2⊤43/g
s/s[01]*1/s⊣1/g
g

ඔබට මෙම පර්මාලින්ක් සමඟ මගේ නව වෙබ් අඩවියෙන් එය උත්සාහ කළ හැකිය . එය GNU APL හි javascript අනුවාදයට සම්පාදනය කරන ලද්දකි. අවසාන නිකුතුව පසුව GNU APL, v. 1.3 නිල වශයෙන් නිකුත් කිරීමත් සමඟ සිදු වේ.


7

හස්කල්හි සී

import Foreign.C.String
import Foreign.C.Types
import Foreign.Marshal.Array
import Foreign.Ptr
import System.Environment
import System.Exit

-- The meat of the program

cmain :: (CInt, Ptr (Ptr CChar)) -> IO CInt
cmain(argc, argv) = do {
    putStr("hello, world\n");
    return 0;
}

-- Of course, the above function doesn't do anything unless we write a wrapper
-- around it.  This could have been done more simply, using higher-level library
-- functions, but where's the fun in that?

main :: IO ()
main = do {
    args <- getArgs;
    argPtrs <- sequence [do {
        argPtr <- mallocArray0(length(arg)) :: IO (Ptr CChar);
        pokeArray0(0)(argPtr)(map(castCharToCChar)(arg));
        return argPtr;
    } | arg <- args ];
    argv <- mallocArray(length(argPtrs)) :: IO (Ptr (Ptr CChar));
    pokeArray(argv)(argPtrs);

    exitCode <- cmain(fromIntegral(length(args)),argv);

    if (exitCode == 0) then do {
        exitWith(ExitSuccess);
    } else do {
        exitWith(ExitFailure(fromIntegral(exitCode)));
    };
}

ඇත්ත වශයෙන්ම, cmainකිසිවක් සමඟ argcහෝ නොකරන බැවින් argv, තර්ක-මාෂල් කේතයට කිසිදු බලපෑමක් නැතcmain සෑම විටම 0 නැවත, මෙම ප්රකාශය මැරිලා "නම්" වන "වෙන" ශාඛා. නමුත් "if" ප්රකාශය කෙසේ හෝ කිසිවක් නොකරයි.

වරහන් සහ සමහර doමූල පද මෙන් බොහෝ වරහන් සහ අර්ධ සළකුණු අනවශ්‍යය . “නම්” ප්‍රකාශය මෙසේ ලිවිය හැකිය if exitCode == 0 then exitWith ExitSuccess else exitWith (ExitFailure (fromIntegral exitCode)).


7

ෆෝර්ත් හි සී ++

: #include ; : <iostream> ; : { ; : } ; : int ; : using ;
: namespace ; : std; ; : main() ; : cout ; : << ;
: "Hello,  ; : world!\n"; S" Hello, world!" type ; : return ; : 0; ;

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, world!\n";
}

වඩාත්ම නම්යශීලී විසඳුම නොවේ, නමුත් එය හරියටම පෙන්වා ඇති ආකාරයට ලියා ඇත්නම් එය ක්රියා කරයි.


7

ජාවා හි හස්කල්

("වැනිලා" ජාවා 7, ජාවා 8 නොවේ) (ඔව්, බොක්සිං ක්‍රීඩාව කාර්ය සාධනය විනාශ කරන බව මම දනිමි. තවද ඉහළ පෙළේ කාර්යයන් භාවිතා කිරීමට උත්සාහ කිරීමෙන් පවා පිස්සු වාචික වේ: D)

ජාවා ඉතා දෘඩ සින්ටැක්ස් ඇත, එබැවින් සින්ටැක්ස් වෙනස් කරනවා වෙනුවට කේතය අර්ථවත් ලෙස හැස්කල් ශෛලියට සමාන කිරීමට මම උත්සාහ කළෙමි.

සංස්කරණය කරන්න - අර්ධ ක්‍රියාකාරී යෙදුම එකතු කරන ලදි.

import java.util.Iterator;

interface Function1<A, B> {
    A call(B arg);
}

interface Function2<A, B, C> {
    A call(B arg1, C arg2);
}

class Reduce<A> implements Function2<A, Function2<A, A, A>, Iterable<A>> {

    @Override
    public A call(Function2<A, A, A> arg1, Iterable<A> arg2) {
        final Iterator<A> i = arg2.iterator();
        A r = i.next();
        while (i.hasNext())
            r = arg1.call(r, i.next());
        return r;
    }
}

class Range implements Iterable<Integer> {

    private final int min;
    private final int max;

    public Range(int min, int max) {
        this.min = min;
        this.max = max;
    }

    @Override
    public Iterator<Integer> iterator() {
        return new Iterator<Integer>() {
            int i = min;

            @Override
            public boolean hasNext() {
                return i <= max;
            }

            @Override
            public Integer next() {
                return i++;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
}

public class Main {

    public static <A, B, C> Function1<A, C> applyPartial(final Function2<A, B, C> f, final B arg2) {
        return new Function1<A, C>() {
            @Override
            public A call(C arg) {
                return f.call(arg2, arg);
            }
        };
    }

    public static void main(String[] args) {

        final Function1<Integer, Iterable<Integer>> product = applyPartial(new Reduce<Integer>(), new Function2<Integer, Integer, Integer>() {
            @Override
            public Integer call(Integer arg1, Integer arg2) {
                return arg1 * arg2;
            }
        });

        final Function1<Integer, Integer> fact = new Function1<Integer, Integer>() {

            @Override
            public Integer call(Integer arg) {
                return product.call(new Range(1, arg));
            }
        };

        final Integer x = fact.call(6);

        System.out.println(x.toString());
    }
}

(ඔව්, මේ පිස්සුව කරන සියල්ල ගණනය කිරීමකි 6!)


6

AWK හි COBOL

උපුටා දැක්වීමේ ආත්මයෙන්. පිරිසිදු, අමිහිරි AWK, එය COBOL ක්‍රමලේඛකයෙකු විසින් ලිවිය හැකිය.

කර්තව්යය වන්නේ ගොනුවක වාර්තා ගණනය කිරීමයි. මෙම මුල් සංවර්ධන අනුවාදය පරීක්ෂා කිරීම සඳහා ගණනය කෙරේ. ඒකක පරීක්ෂණයෙන් මුදා හරින විට නිවැරදි ගොනුව පසුව දෘඩ කේත කරනු ලැබේ ...

කළු පැහැයෙන් පොස්පරස්-කොළ කිරීම සඳහා මට සින්ටැක්ස් ඉස්මතු කර දැක්විය හැකි නම්, එය විශිෂ්ටයි ...

මෙම පේළියේ තීරු අංක පවා නිවැරදිව ලබාගෙන ඇත, එය එක් එක් පේළියේ ආරම්භයේ හිස් හතකි (මීට පෙර කිසි විටෙකත් එය සිදු නොවීය) සහ 72 තීරුවේ දිගු මුද්‍රණ ප්‍රකාශ බිඳ දැමීම.

   BEGIN { 
       PERFORM_000_INITIALISATION() 
       PERFORM_100_OPEN_FILES() 
       PERFORM_200_PROCESS_FILE() 
       PERFORM_300_CLOSE_FILES() 
       PERFORM_400_SHOW_THE_COUNTS() 
       exit 
   } 
   function PERFORM_000_INITIALISATION() { 
       INPUT_FILE_NAME = "COBOL.AWK" 
       RECORD_COUNT = 0 
   } 
   function PERFORM_100_OPEN_FILES() { 
   } 
   function PERFORM_200_PROCESS_FILE() { 
       PERFORM_210_PRIMING_READ() 
       PERFORM_220_PROCESS_INPUT_UNTIL_END() 
   } 
   function PERFORM_300_CLOSE_FILES() { 
   } 
   function PERFORM_400_SHOW_THE_COUNTS() { 
       print "COBOL.AWK: NUMBER OF RECORDS READ IS " RECORD_COUNT        
   } 
   function PERFORM_210_PRIMING_READ() { 
       PERFORM_900_READ_THE_FILE() 
       if ( FILE_STATUS < 0 ) { 
           print "COBOL.AWK ERR0001: INVALID FILE, HALTING, FILE N" \
                 "AME IS: " INPUT_FILE_NAME 
           exit 
           } 
       if ( FILE_STATUS == 0 ) { 
           print "COBOL.AWK ERR0002: NO RECORDS ON INPUT, HALTING," \
                 "FILE NAME IS: " INPUT_FILE_NAME 
           exit 
           } 
   } 
   function PERFORM_220_PROCESS_INPUT_UNTIL_END() {
       while ( FILE_STATUS != 0 ) { 
           INPUT_RECORD = $0 
           RECORD_COUNT = RECORD_COUNT + 1 
           PERFORM_900_READ_THE_FILE() 
           } 
   } 
   function PERFORM_900_READ_THE_FILE() { 
       FILE_STATUS = getline < INPUT_FILE_NAME 
   }        

6

රාකට් හි මොළය (හෝ වෙනත් දෙයක්)

ඩොමේන්-විශේෂිත සහ පොදු අරමුණු යන දෙකටම මුළුමනින්ම නව භාෂාවන් සඳහා මොඩියුල සහාය ක්‍රියාත්මක කිරීමට රාකට්ගේ නම්‍යශීලී මොඩියුලය සහ සාර්ව පද්ධතිය ඉඩ දෙයි. ඩේටාලොග් සහ ඇල්ගොල් 60 යන දෙකටම සහය නොදක්වයි , එබැවින් පහත දැක්වෙන්නේ වලංගු රාකට් වැඩසටහන් වේ:

#lang datalog
edge(a, b). edge(b, c). edge(c, d). edge(d, a).
path(X, Y) :- edge(X, Y).
path(X, Y) :- edge(X, Z), path(Z, Y).
path(X, Y)?

#lang algol60
begin
  integer procedure SIGMA(x, i, n);
    value n;
    integer x, i, n;
  begin
    integer sum;
    sum := 0;
    for i := 1 step 1 until n do
      sum := sum + x;
    SIGMA := sum;
  end;
  integer q;
  printnln(SIGMA(q*2-1, q, 7));
end

ඔබට වෙනත් භාෂා සඳහා සහයද එක් කළ හැකිය: උදා: බ්‍රැන්ෆක් සඳහා සහය ක්‍රියාත්මක කරන්නේ කෙසේද යන්න පිළිබඳ ඩැනී යූගේ විස්තරය බලන්න , එය රාකට් වැඩසටහන් සඳහා අවසර දෙයි:

#lang planet dyoo/bf
++++++[>++++++++++++<-]>.
>++++++++++[>++++++++++<-]>+.
+++++++..+++.>++++[>+++++++++++<-]>.
<+++[>----<-]>.<<<<<+++[>+++++<-]>.
>>.+++.------.--------.>>+.

සම්පාදනය කරන ලද මොඩියුල මට්ටමින් සහය එක් කරන බැවින්, විවිධ භාෂාවලින් ලියා ඇති මොඩියුල සම්බන්ධ කිරීමට හෝ වෙනත් භාෂාවක ලියා ඇති මොඩියුලයක් තුළ එක් භාෂාවක කුඩා කොටසක් ඇතුළත් කිරීමට හැකිය.


5

ජාවා හි එස්එම්එල්

මම ජාවා ඉගෙනීමට පටන් ගෙන එය ක්‍රියාකාරී ශෛලියකින් භාවිතා කිරීමට උත්සාහ කළ අවස්ථාවේ සිට තවමත් පැරණි කේත කිහිපයක් මා සතුව ඇත. තරමක් පිරිසිදු කර ඇත:

/**
 * Genericised ML-style list.
 */
public class FunctionalList<T> 
{
    private final T head;
    private final FunctionalList<T> tail;

    public FunctionalList(T x, FunctionalList<T> xs) {
        this.head = x;
        this.tail = xs;
    }

    public static <T> FunctionalList<T> cons(T x, FunctionalList<T> xs) {
        return new FunctionalList<T>(x, xs);
    }

    public static <T> T hd(FunctionalList<T> l) {
        return l.head;
    }

    public static <T> FunctionalList<T> tl(FunctionalList<T> l) {
        return l.tail;
    }

    public static int length(FunctionalList<?> l) {
        return len(l, 0);
    }

    private static int len(FunctionalList<?> l, int n) {
        return l == null ? n : len(tl(l), n + 1);
    }

    public static <T> FunctionalList<T> rev(FunctionalList<T> l) {
        return rev(l, null);
    }

    private static <T> FunctionalList<T> rev(FunctionalList<T> a, FunctionalList<T> b) {
        return a == null ? b : rev(tl(a), cons(hd(a), b));
    }

    public static <T> FunctionalList<T> append(FunctionalList<T> a, FunctionalList<T> b) {
        return a == null ? b : cons(hd(a), append(tl(a), b));
    }
}

5

පර්ල් හි ජාවා

නීති කඩ කිරීමක් ලෙස ගණන් ගත හැකි නමුත් මම එය ගණන් ගන්නේ නැත. නිසැකවම, එය ජාවා වැඩසටහනක් ලෙස පෙනෙන්නට අදහස් කරයි. එය පැහැදිලිව නොපෙනේ නම් එය ෆිබොනාච්චි අංක 20 මුද්‍රණය කරයි.

Inline :: Java මොඩියුලය ස්ථාපනය කිරීම අවශ්‍ය වේ .

use Inline Java => <<'JAVA';
/**
 * @author  Konrad Borowski <x.fix@o2.pl>
 * @version 0.1.0
 */
class Fibonacci
{
    /**
     * Responsible for storing the number before last generated number.
     */
    private long beforeLastNumber = 0;

    /**
     * Responsible for storing the last generated number.
     */
    private long lastNumber = 1;

    /**
     * Receives the next Fibonacci number.
     * 
     * @return long integer that is the next Fibonacci number
      */
    public long next()
    {
        long temponaryLastNumber = lastNumber;
        lastNumber = beforeLastNumber + lastNumber;
        beforeLastNumber = temponaryLastNumber;
        return temponaryLastNumber;
    }

    /**
     * Outputs the Fibonacci number to standard output.
     */
    public void printFibonacci()
    {
        System.out.println(next());
    }

    /**
     * Outputs the Fibonacci number to standard output given number of
     * times.
     * 
     * @param times number of times to print fibonacci number
     */
    public void printFibonacciTimes(int times)
    {
        int i;
        for (i = 0; i < times; i++) {
            printFibonacci();
        }
    }

    /**
     * Constructor for Fibonacci object. Does nothing.
     */
    public Fibonacci()
    {
        // Do nothing.
    }
}
JAVA

###
 # The executable class that shows 20 Fibonacci numbers.
 ##
package OutputFibonacci
{
    ###
     # Shows 20 Fibonacci numbers. This method is public,
     # static, and returns void.
     ##
    sub main()
    {
        # In Perl, -> is object method separator, not a dot. This is stupid.
        new Fibonacci()->printFibonacciTimes(20);
    }
}

# Perl doesn't automatically call main method.
OutputFibonacci::main();

4

ජේ සහ ... කිසිවෙකු අනුමාන නොකරනු ඇත (සංස්කරණය: dc)

මෙය මගේ දෙවන පිවිසුමයි; මෙහි වලංගු J කේතයක් ඇත, එය 1 ලබා දෙයි:

10 o. 1 r. 2 i. 4 [ ( 0:`1: @. (2&|)) ] 8 #: *:@+: 42

කිසිදු දෝෂයක් නොමැතිව එකම කේත කැබැල්ලක් ධාවනය කරන අනෙක් භාෂාව කුමක්දැයි පැවසීමට පෙර මම දිනක් හෝ දෙකක් බලා සිටිමි. අනුමාන කිරීමට උත්සාහ කිරීම සඳහා අදහස් දක්වන්න.

සංස්කරණය කරන්න: අනෙක් භාෂාව ඉතා පැරණි යුනික්ස් කැල්කියුලේටරයේ සිට තොග පදනම් කරගත් භාෂාවයි.


3
එය ගොල්ෆ් ස්ක්‍රිප්ට්, බීඑෆ්, එච්කියු 9 +, ...
පීටර් ටේලර්

හරි, එවැනි බොහෝ භාෂාවන්ට එය කළ හැකි බව මා දැන සිටියේ නැත. මම කේතය සංස්කරණය කරන්නේ මා තෝරාගත් භාෂාව තැබීම සඳහා ය.
තෝමස් බාරුචෙල්

Languages ​​ברוכאל එය එම භාෂාවල දෝෂ නොමැතිව ක්‍රියාත්මක වන්නේ එම භාෂාවන්ට දෝෂ නොමැති නිසා හෝ මෙම කේතයට අදාළ දෝෂ නොමැති නිසාය. උදා. බ්‍රේන්ෆක් නොමැති සියලුම අක්ෂර නොසලකා හරින .,+-<>[]බැවින් ඔබේ වැඩසටහන ...[.]+වලංගු නමුත් අර්ථ විරහිත වැඩසටහනක් වන මොළයේ ක්‍රියාකාරිත්වයට සමාන වේ . AFAIK මොළය අවලංගු කිරීමේ වැඩසටහනක් අවලංගු කළ හැක්කේ නොගැලපීමෙන් පමණි [].
user253751

ඉමිබිස්. මෙය අසත්‍යයකි. dc යනු පැරණි කැල්කියුලේටරයක් ​​වන අතර මගේ කේතවල එක් දෙයක් වෙනස් කිරීම දෝෂයක් ඇති කරන බවට මට සහතික විය හැකිය. අක්ෂර නිවැරදි පිළිවෙලට තැබීමේ යම් උපක්‍රමශීලී ක්‍රමයක් සොයා ගැනීමට මම කේතයේ සමහර කොටස් සඳහා වැඩි කාලයක් ගත කළෙමි. මගේ කේත කැබැල්ල තැපැල් පිටපත / ඩීසී තරමක් ආන්තික ය: දෝෂයක් නැත නමුත් කිසිවක් වෙනස් කිරීම වැරදිය. dc ට “එම භාෂා” සමඟ කිසිදු සම්බන්ධයක් නැත; dc “එම භාෂාවන්ට” වඩා අවුරුදු 20 ක් හෝ 30 ක් පමණ පැරණි ය; එය සාමාන්‍යයෙන් ඕනෑම ලිනක්ස් බෙදාහැරීමක ස්ථාපනය කර ඇත. කරුණාකර, ඔබ ඒ ගැන අසා නොමැති නම් ටිකක් පිරික්සන්න.
තෝමස් බාරුචෙල්

1
Mis ברוכאל ඔබ වරදවා වටහාගෙන ඇත - මම කතා කළේ මොළය, HQ9 +, ගොල්ෆ් පිටපත යනාදිය ගැන ය - dc නොවේ.
user253751

4

dc PostScript ගොනුවක් ධාවනය කරයි

dc හට පහත දැක්වෙන කේතය කිසිදු දෝෂයක් නොමැතිව ධාවනය කළ හැකිය:

10 10 10 10 10 42 32 10 10
stop % first send a stop
0 0 srand rand
le pop pop 3.14 sin
lt 2 3 lt and pop
le 2 10 le xor
pop pop pop 1 0 0
<< /sox 2 >> [ exch begin sox end ] aload
3.14 floor

3

ජාවා හි එම්එල් / (දැඩි) හස්කල්

මෙය සත්‍ය ව්‍යාපෘතියකින්. එය නිරන්තරයෙන් වෙනස් කළ නොහැකි දත්ත ව්‍යුහයන් භාවිතා කරන අතර අවශ්‍ය නොවන අවස්ථාවලදී පවා පුනරාවර්තනය භාවිතා කරයි. ඇත්ත වශයෙන්ම, එය ජාවා හි කෝරේ (ව්‍යාපෘතිය ක්‍රියාත්මක කරන භාෂාව) වැනි ය, නමුත් ශෛලිය මූලික වශයෙන් එම්එල් හා සමාන ය. නමුත් කෝරේගේ දර්ශනය නම් කතුවරයා ඔහුගේ කේතය සංයුති නොකළ යුතු බැවින් ජාවා කේත කිසිවක් ආකෘතිකරණය නොකිරීමයි (එය සූර්යග්‍රහණයෙන් ස්වයංක්‍රීයව හැඩගස්වා ඇත).

ලැයිස්තුවකින් මූලද්‍රව්‍ය n අතහරින්න :

  public static <T> List<T> drop(List<T> l, Integer n) {
    return n == 0 ? l : drop(l.cons().tail, n - 1);
  }

හිස සහ වලිගය උකහා ගැනීම සඳහා රටාව ගැලපෙන ML / Haskell හි, මෙහි ඔබ කියන්නේ list.cons().xසහ list.cons().tail.

ලැයිස්තුවක් තුළ අංගයක් ඇතුළු කරන්න :

  public static <T> List<T> insert(List<T> l, Integer i, T x) {
    if (i == 0)
      return cons(x, l);
    return cons(l.cons().x, insert(l.cons().tail, i - 1, x));
  }

ලැයිස්තුව වීජීය දත්ත සමුදාය නිර්වචනය කරන්නේ කෙසේද යන්න වචනාර්ථයෙන් අර්ථ දක්වා ඇත. සූර්යග්‍රහණයෙන් ජනනය කරන ලද බොයිලේරු ඉවත් කළ අනුවාදය මෙන්න:

public final class List<T> {

  public static final class Nil<T> {
  }

  public static final class Cons<T> {
    public final T x;
    public final List<T> tail;

    public Cons(T x, List<T> tail) {
      if (x == null)
        throw new RuntimeException("null head");
      if (tail == null)
        throw new RuntimeException("null tail");
      this.x = x;
      this.tail = tail;
    }
  }

  private final Nil<T> nil;
  private final Cons<T> cons;

  private List(Nil<T> nil, Cons<T> cons) {
    this.nil = nil;
    this.cons = cons;
  }

  public boolean isEmpty() {
    return nil != null;
  }

  public Nil<T> nil() {
    if (nil == null)
      throw new RuntimeException("not nil");
    return nil;
  }

  public Cons<T> cons() {
    if (cons == null)
      throw new RuntimeException("not cons");
    return cons;
  }

  public static <T> List<T> cons(Cons<T> cons) {
    if (cons == null)
      throw new RuntimeException("constructor received null");
    return new List<T>(null, cons);
  }

  public static <T> List<T> nil(Nil<T> nil) {
    if (nil == null)
      throw new RuntimeException("constructor received null");
    return new List<T>(nil, null);
  }
}

මෙහිත්‍රිත්වයක් අනුව ක්‍රියාත්මක කරන ලද සිතියම් දත්ත ව්‍යුහයක් :

public final class Map<K, V> {
  private final Tree<Character, Optional<Pair<K, V>>> tree;
  // keys are sorted in reverse order so entrySet can use cons instead of append
  private final Comparer<Pair<Character, Tree<Character, Optional<Pair<K, V>>>>> comparer =
      new PairLeftComparer<Character, Tree<Character, Optional<Pair<K, V>>>>(
          new ReverseComparer<Character>(new CharacterComparer()));

  private Map(Tree<Character, Optional<Pair<K, V>>> tree) {
    this.tree = tree;
  }

  public static <K, V> Map<K, V> empty() {
    return new Map<K, V>(new Tree<Character, Optional<Pair<K, V>>>(
        OptionalUtils.<Pair<K, V>> nothing(),
        ListUtils
            .<Pair<Character, Tree<Character, Optional<Pair<K, V>>>>> nil()));
  }

  public Optional<V> get(K k) {
    Tree<Character, Optional<Pair<K, V>>> t = tree;
    for (char c : k.toString().toCharArray()) {
      Tree<Character, Optional<Pair<K, V>>> t2 = getEdge(t, c);
      if (t2 == null)
        return nothing();
      t = t2;
    }
    if (t.v.isNothing())
      return nothing();
    return some(t.v.some().x.y);
  }

  public Map<K, V> put(K k, V v) {
    return new Map<K, V>(put(tree, k.toString(), v, k));
  }

  private Tree<Character, Optional<Pair<K, V>>> put(
      Tree<Character, Optional<Pair<K, V>>> t, String s, V v, K k) {
    if (s.equals(""))
      return new Tree<Character, Optional<Pair<K, V>>>(some(Pair.pair(k, v)),
          t.edges);
    char c = s.charAt(0);
    Tree<Character, Optional<Pair<K, V>>> t2 = getEdge(t, c);
    if (t2 == null)
      return new Tree<Character, Optional<Pair<K, V>>>(
          t.v,
          sort(
              cons(
                  pair(
                      c,
                      put(new Tree<Character, Optional<Pair<K, V>>>(
                          OptionalUtils.<Pair<K, V>> nothing(),
                          ListUtils
                              .<Pair<Character, Tree<Character, Optional<Pair<K, V>>>>> nil()),
                          s.substring(1), v, k)), t.edges), comparer));
    return new Tree<Character, Optional<Pair<K, V>>>(t.v, sort(
        replace(pair(c, put(t2, s.substring(1), v, k)), t.edges), comparer));
  }

  private List<Pair<Character, Tree<Character, Optional<Pair<K, V>>>>> replace(
      Pair<Character, Tree<Character, Optional<Pair<K, V>>>> edge,
      List<Pair<Character, Tree<Character, Optional<Pair<K, V>>>>> edges) {
    if (edges.cons().x.x.equals(edge.x))
      return cons(edge, edges.cons().tail);
    return cons(edges.cons().x, replace(edge, edges.cons().tail));
  }

  // I consider this O(1). There are a constant of 2^16 values of
  // char. Either way it's unusual to have a large amount of
  // edges since only ASCII chars are typically used.
  private Tree<Character, Optional<Pair<K, V>>> getEdge(
      Tree<Character, Optional<Pair<K, V>>> t, char c) {
    for (Pair<Character, Tree<Character, Optional<Pair<K, V>>>> p : iter(t.edges))
      if (p.x.equals(c))
        return p.y;
    return null;
  }

  public Map<K, V> delete(K k) {
    return new Map<K, V>(delete(tree, k.toString()).x);
  }

  private Pair<Tree<Character, Optional<Pair<K, V>>>, Boolean> delete(
      Tree<Character, Optional<Pair<K, V>>> t, String k) {
    if (k.equals(""))
      return pair(
          new Tree<Character, Optional<Pair<K, V>>>(
              OptionalUtils.<Pair<K, V>> nothing(), t.edges), t.edges.isEmpty());
    char c = k.charAt(0);
    Tree<Character, Optional<Pair<K, V>>> t2 = getEdge(t, c);
    if (t2 == null)
      return pair(t, false);
    Pair<Tree<Character, Optional<Pair<K, V>>>, Boolean> p =
        delete(t2, k.substring(1));
    List<Pair<Character, Tree<Character, Optional<Pair<K, V>>>>> edges = nil();
    for (Pair<Character, Tree<Character, Optional<Pair<K, V>>>> e : iter(t.edges))
      if (!e.x.equals(c))
        edges = cons(e, edges);
    if (!p.y)
      return pair(
          new Tree<Character, Optional<Pair<K, V>>>(t.v, cons(pair(c, p.x),
              edges)), false);
    boolean oneEdge = t.edges.cons().tail.isEmpty();
    return pair(new Tree<Character, Optional<Pair<K, V>>>(t.v, edges), oneEdge
        && t.v.isNothing());

  }

  public static class Entry<K, V> {
    public Entry(K k, V v) {
      this.k = k;
      this.v = v;
    }

    public final K k;
    public final V v;

  }

  public List<Entry<K, V>> entrySet() {
    return entrySet(ListUtils.<Entry<K, V>> nil(), tree);
  }

  private List<Entry<K, V>> entrySet(List<Entry<K, V>> l,
      Tree<Character, Optional<Pair<K, V>>> t) {
    if (!t.v.isNothing()) {
      Pair<K, V> p = t.v.some().x;
      l = cons(new Entry<K, V>(p.x, p.y), l);
    }
    for (Pair<Character, Tree<Character, Optional<Pair<K, V>>>> e : iter(t.edges))
      l = entrySet(l, e.y);
    return l;
  }
}

වර්ග කේතය තරම් ඉඩ ප්‍රමාණයක් ගැනීමට පටන් ගනී. උදාහරණයක් ලෙස, පුරවන්නේ , මෙම ක්රමය වර්ග චරිත 302 සහ කේත අක්ෂර 343 (අවකාශය / හිස් පේලි ගැන ගණන් නැත) ඇත.


2

රූබි හි බේසික්

මෙය බොහෝ කලකට පෙර ක්‍රියාත්මක කරන ලදි. මෙම මූලාශ්ර GitHub මත ය . දේවානුභාවයෙන් aScala හි සමාන දෙයක්

පිහිටුවීම

#!/usr/bin/env ruby

if caller.empty? && ARGV.length > 0
  $file = ARGV[0]
else
  $file = caller.last.split(':').first
end

require 'pp'

class String
  def %(other)
    self + other.to_s
  end
end

class RBaysick
  @@variables = {}
  @@code = []
  @@line = 0

  def initialize(contents)
    $DONT_RUN = true # To avoid endless loops.

    contents.gsub!(/( |\()'([^\W]+)/, '\1:\2 ')

    contents.gsub!(/(^| |\()(:[^\W]+)/, '\1GET(\2)')

    contents.gsub!(/ IF (.*) THEN (.*)/, ' IF { \1 }.THEN { GOTO \2 }')
    contents.gsub!(/LET *\(([^ ]+) *:= *(.*)\)/, 'LET(\1) { \2 }')
    contents.gsub!(/(LET|INPUT)(\(| )GET\(/, '\1\2(')
    contents.gsub!(/ \(/, '(')

    contents.gsub!(/^(\d+) (.*)$/, 'line(\1) { \2 }')

#    contents.gsub!(/(\)|\}|[A-Z]) ([A-Z]+)/, '\1.\2')

    contents.gsub!(/ END /, ' __END ')
    contents.gsub!(/^RUN/, '__RUN')

    puts contents if $DEBUG
    eval contents
  end

  def __RUN
    while @@line > -1
      puts "#{@@line}: #{@@code[@@line].inspect}" if $DEBUG
      unless @@code[@@line].nil?
        @@increment = true
        @@code[@@line].call
        next unless @@increment
      end
      @@line += 1
    end
  end

  class If < Struct.new(:value)
    def THEN
      yield if value
    end
  end

  def method_missing(name, *args)
    puts "Missing: #{name.to_s}(#{args.map(&:inspect).join(', ')})" if $DEBUG
  end

  def variables
    @@variables
  end

  def line(line, &block)
    @@code[line] = block
  end

  def add(line, cmd, *args)
    puts "DEBUG2: #{cmd.to_s}(#{args.map(&:inspect).join(', ')})" if $DEBUG
    @@code[line] = send(cmd, *args)
  end

  def IF
    ::RBaysick::If.new(yield)
  end

  def PRINT(str)
    puts "PRINT(#{str.inspect})" if $DEBUG
    puts str
    true
  end

  def LET(name, &block)
    puts "LET(#{name.inspect}, #{block.inspect})" if $DEBUG
    @@variables[name] = block.call
  end

  def GET(name)
    puts "GET(#{name.inspect}) #=> #{@@variables[name].inspect}" if $DEBUG
    @@variables[name]
  end

  def INPUT(name)
    puts "INPUT(#{name.inspect})" if $DEBUG
    LET(name) { $stdin.gets.chomp.to_i }
  end

  def ABS(val)
    puts "ABS(#{val.inspect}) #=> #{val.abs.inspect}" if $DEBUG
    val.abs
  end

  def GOTO(line)
    @@increment = false
    @@line = line
  end

  def __END
    exit
  end
end

RBaysick.new(open($file).read) unless $DONT_RUN || ($0 != __FILE__)

මූලික කේතය

#!./rbaysick.rb

10 PRINT "Welcome to Baysick Lunar Lander v0.0.1"
20 LET ('dist := 100)
30 LET ('v := 1)
40 LET ('fuel := 1000)
50 LET ('mass := 1000)

60 PRINT "You are a in control of a lunar lander."
70 PRINT "You are drifting towards the surface of the moon."
80 PRINT "Each turn you must decide how much fuel to burn."
90 PRINT "To accelerate enter a positive number, to decelerate a negative"

100 PRINT "Distance " % 'dist % "km, " % "Velocity " % 'v % "km/s, " % "Fuel " % 'fuel
110 INPUT 'burn
120 IF ABS('burn) <= 'fuel THEN 150
130 PRINT "You don't have that much fuel"
140 GOTO 100
150 LET ('v := 'v + 'burn * 10 / ('fuel + 'mass))
160 LET ('fuel := 'fuel - ABS('burn))
170 LET ('dist := 'dist - 'v)
180 IF 'dist > 0 THEN 100
190 PRINT "You have hit the surface"
200 IF 'v < 3 THEN 240
210 PRINT "Hit surface too fast (" % 'v % ")km/s"
220 PRINT "You Crashed!"
230 GOTO 250
240 PRINT "Well done"

250 END

RUN

2

C ++ සැකිලි වල හස්කල්

මම මීට මාස කිහිපයකට පෙර C ++ සැකිලි වල මෙම FizzBuzz එක ලාර්ක් එකක හැදුවා. එය C ++ සැකිලි වල පහත දැක්වෙන හැස්කල් කේතය ක්‍රියාත්මක කිරීමකි. ඇත්ත වශයෙන්ම, පූර්ණ සංඛ්‍යා අංක ගණිතය පවා වර්ග මට්ටමින් නැවත ක්‍රියාත්මක වේ --- සැකිලි කිසිවක් int පරාමිතීන් භාවිතා නොකරන බව සලකන්න!

හැස්කල් කේතය:

import Control.Monad

m `divides` n = (n `mod` m == 0)

toFizzBuzz n
    | 15 `divides` n = "FizzBuzz"
    |  5 `divides` n = "Buzz"
    |  3 `divides` n = "Fizz"
    |      otherwise = show n

main = mapM_ putStrLn $ take 100 $ map toFizzBuzz [1..]

සහ C ++ අච්චු පරිවෘත්තීය අනුවාදය:

//  
//  Lazy compile-time fizzbuzz computed by C++ templates,
//  without conditionals or the use of machine arithmetic.
//
//         -- Matt Noonan (mnoonan@grammatech.com)

#include <iostream>

using namespace std;

//
//  The natural numbers: Nat = Zero | Succ Nat
//

template <typename n>
struct Succ
{
  typedef Succ eval;
  static const unsigned int toInt = 1 + n::toInt;
  static void print(ostream & o) { o << toInt; }
};

struct Zero
{
  typedef Zero eval;
  static const unsigned int toInt = 0;
  static void print(ostream & o) { o << toInt; }
};

//
//  Arithmetic operators
//    Plus Zero n = n
//    Plus Succ(n) m = Plus n Succ(m)
//    Times Zero n = Zero
//    Times Succ(n) m = Plus m (Times n m)
//

template <typename a, typename b>
struct Plus
{
  typedef typename Plus<typename a::eval,
                        typename b::eval>::eval eval;
};

template <typename M>
struct Plus <Zero, M>
{ typedef typename M::eval eval; };

template <typename N, typename M>
struct Plus <Succ<N>, M>
{ typedef typename Plus<N, Succ<M> >::eval eval; };

template <typename a, typename b>
struct Times
{
  typedef typename Times<typename a::eval,
                         typename b::eval>::eval eval;
};

template <typename M>
struct Times <Zero, M>
{ typedef Zero::eval eval; };

template <typename N, typename M>
struct Times <Succ<N>, M>
{ typedef typename Plus<M,
                        typename Times<N,M>::eval
                        >::eval eval; };

//
//  Lists
//

struct Nil
{
  typedef Nil eval;
  static void print(ostream & o) { }
};

template <typename x, typename xs>
struct Cons
{
  typedef Cons eval;
  static void print(ostream & o) {
    x::eval::print(o); o << endl; xs::eval::print(o);
  }
};

//
//  Take the first n elements of a list
//

template <typename, typename> struct Take;

template <typename _> struct Take<Zero,_>
{ typedef Nil eval; };

template <typename n, typename x, typename xs>
struct Take<Succ<n>, Cons<x,xs> >
{
  typedef Cons<x, Take<n, xs> > eval;
};

template <typename a, typename b>
struct Take
{
  typedef typename Take<typename a::eval,
                        typename b::eval>::eval eval;
};

//
//  Iterate f x0 makes the infinite list
//  x0, f(x0), f(f(x0)), ...
//

template <template<typename> class f, typename x0> struct Iterate
{
  typedef Cons<x0, Iterate<f, f<x0> > > eval;
};

//
//  Map a function over a list
//

template <template<typename> class a, typename b> struct Map
{ typedef typename Map<a,
                       typename b::eval>::eval eval;
};

template <template<typename> class f>
struct Map<f, Nil>
{ typedef Nil eval; };

template <template<typename> class f, typename x, typename xs>
struct Map<f, Cons<x,xs> >
{
  typedef Cons<f<x>, Map<f,xs> > eval;
};

//
//  Some useful things for making fizzes and buzzes
//

struct Fizz
{ static void print(ostream & o) { o << "Fizz"; } };

struct Buzz
{ static void print(ostream & o) { o << "Buzz"; } };

struct FizzBuzz
{ static void print(ostream & o) { o << "FizzBuzz"; } };

//
//  Some useful numbers
//

typedef Succ<Zero> One;
typedef Succ<One> Two;
typedef Succ<Two> Three;
typedef Plus<Two, Three> Five;
typedef Times<Two, Five> Ten;
typedef Times<Three, Five> Fifteen;
typedef Times<Ten, Ten> OneHundred;

//
//  Booleans
//

struct True {};
struct False {};

//
//  If/then/else
//

template <typename p, typename t, typename f>
struct If
{
  typedef typename If<typename p::eval, t, f>::eval eval;
  static void print(ostream & o) { eval::print(o); }
};

template <typename t, typename _>
struct If<True, t, _>
{
  typedef t eval;
};

template <typename _, typename f>
struct If<False, _, f>
{ typedef f eval; };

//
//  Testing if x divides y
//

template <typename a, typename b, typename c>
struct _Divides
{
  typedef typename _Divides<typename a::eval,
                            typename b::eval,
                            typename c::eval>::eval eval;
};

template <typename _, typename __>
struct _Divides<_, __, Zero> { typedef False eval; };

template <typename a>
struct _Divides<a, Zero, Zero> { typedef True eval; };

template <typename a, typename b>
struct _Divides<a, Zero, b>
{
  typedef typename _Divides<a, a, b>::eval eval;
};

template <typename _, typename n, typename m>
struct _Divides<_, Succ<n>, Succ<m> >
{
  typedef typename _Divides<_, n, m>::eval eval;
};

template <typename a, typename b>
struct Divides
{
  typedef typename _Divides<a, a, b>::eval eval;
};

//
//  "Otherwise" sugar
//

template <typename a>
struct Otherwise
{
  typedef typename a::eval eval;
  static void print(ostream & o) { a::eval::print(o); }
};

//
//  Convert a number to fizzes, buzzes as appropriate
//

template <typename n>
struct toFizzBuzz
{
  typedef typename
    If< Divides<Fifteen, n>, FizzBuzz,
    If< Divides<   Five, n>,     Buzz,
    If< Divides<  Three, n>,     Fizz,
    Otherwise<                   n
    > > > >::eval eval;
};

int main(void)
{
  // Make all of the natural numbers
  typedef Iterate<Succ, One> Naturals;

  // Apply fizzbuzz rules to every natural number
  typedef Map<toFizzBuzz, Naturals> FizzBuzzedNaturals;

  // Print out the first hundred fizzbuzzed numbers
  Take<OneHundred, FizzBuzzedNaturals>::eval::print(cout);

  return 0;
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.