1. Список говнокодов пользователя Abbath

    Всего: 51

  2. C++ / Говнокод #13190

    +18

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    std::tuple<std::vector<long double> , std::vector<std::vector<long double> > , std::vector<long double> >
    inline
    training(const std::size_t hidden_neurons,
             const long double hlr,
             const std::size_t epochs,
             const std::vector< long double > train_ou,
             const std::vector< std::vector< long double > >& train_in,
             volatile bool * reset)
    {
    
    
        auto train_inp = train_in;
        auto train_out = train_ou;
    //    std::cerr << "hidden_neurons: " << hidden_neurons << std::endl;
    //    std::cerr << "hlr: " << hlr << std::endl;
    //    std::cerr << "epochs: " << epochs << std::endl;
    //    std::cerr << "train_inp: " << train_inp << std::endl;
    //    std::cerr << "train_out: " << train_out << std::endl;
    
        const auto mu_inp = mean( train_inp );
        const auto sigma_inp = stand( train_inp );
        train_inp = ( train_inp - mu_inp[ 0 ] ) / sigma_inp[ 0 ];
        const auto mu_out = mean( train_out );
        const auto sigma_out = stand( train_out );
        train_out = ( train_out - mu_out ) / sigma_out;
        const auto patterns = size( train_inp ).first;
    
        std::cout << "patterns: " << patterns << std::endl;
        auto bias = ones( patterns );
        train_inp = merge( train_inp, bias );
        const auto inputs = size( train_inp ).second;
    
        std::vector< long double > err( epochs );
    
        auto weight_input_hidden = ( randn( inputs, hidden_neurons) - 0.5l ) / 10.0l;
        auto weight_hidden_output = ( randn( hidden_neurons ) - 0.5l ) / 10.0l;
    
        for( std::size_t i = 0; i < epochs; ++i ) {
            if ( *reset ) {
                break;
            }
            const auto alr = hlr;
            const auto blr = alr / 10.0;
            for( std::size_t j = 0; j < patterns; ++j ){
                const auto patnum = ( static_cast<std::size_t>( round( randd() * patterns + 0.5 ) ) - 1 ) % patterns;
                const auto this_pat = train_inp[ patnum ];
                const auto act = train_out[ patnum ];
                const auto hval = feval( []( const long double & v ){ return std::tanh( v ); }, this_pat * weight_input_hidden );
                const auto pred = hval * weight_hidden_output;
                const auto error = pred - act;
                const auto delta_HO = hval * error * blr;
                weight_hidden_output = weight_hidden_output - delta_HO;
                const auto m1 = weight_hidden_output * alr * error;
                const auto m2 = 1.0l - (hval^2);
                const auto m3 = dot_operator( m1, m2, std::multiplies< long double >());
                const auto m4 = vec_to_vecvec( m3 );
                const auto delta_IH = m4 * this_pat;
                weight_input_hidden = weight_input_hidden - trans( delta_IH );
            }
            const auto p1 = feval( []( const long double& v ){ return std::tanh( v ); }, train_inp * weight_input_hidden );
            const auto pred = weight_hidden_output * trans( p1 );
            const auto error = pred - train_out;
            const auto error_sq = error ^ 2;
            err[ i ] = std::sqrt( std::accumulate( error_sq.cbegin(), error_sq.cend(), 0.0, std::plus<long double> () ) );
            std::cerr << "err[ i ]: " << err[ i ] << ' ' << i <<  std::endl;
        }
        return std::move(std::make_tuple(weight_hidden_output, weight_input_hidden, err));
    }

    Велосипедостроение

    Abbath, 19 Июня 2013

    Комментарии (31)
  3. Haskell / Говнокод #12976

    −95

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    module Main where
    
    import Control.Monad
    --import Data.Monoid
    
    data State s a = State (s -> (a, s))
    
    runState :: State s a -> s -> (a, s)
    runState (State f) = f
    
    instance Monad (State s) where
    			return a = State $ \s -> (a, s)
    			ma >>= mf = State $ \s0 -> let (b, s1) = runState ma s0 
    				in runState (mf b) s1
    
    type FSM s = State s s 
    
    fsm :: (ev -> s -> s) -> (ev -> FSM s)
    fsm transition = \e -> State $ \s -> (s, transition e s)
    
    data PN = NONZ | PONZ | POPZ | NOPZ deriving (Eq,Show)
    
    parse :: Int -> FSM PN
    parse = fsm $ trans 
    	where trans 1 NONZ= PONZ
    	      trans 1 NOPZ= POPZ
    	      trans 1 POPZ= NOPZ
    	      trans 1 PONZ= NONZ
    	      trans 0 POPZ= PONZ
    	      trans 0 PONZ= POPZ
    	      trans 0 NONZ= NOPZ
    	      trans 0 NOPZ= NONZ
    	      
    conv [] = []
    conv ('1':xs) = 1:(conv xs)
    conv ('0':xs) = 0:(conv xs)
    conv (_:xs) = error "parse error"
    
    main =do
    	x <- getLine
    	print $ (snd $ runState (mapM parse (conv x)) POPZ) == POPZ
    	print $ runState (mapM parse (conv x)) POPZ

    Конечный автомат на Haskell

    Abbath, 08 Мая 2013

    Комментарии (1)
  4. C++ / Говнокод #12911

    +13

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    void CMainWindow::OnTimer(UINT_PTR id){
    	switch(id){
    	case IDT_TIMER1:
    		CClientDC dc(this);
    		dc.SetMapMode(MM_ISOTROPIC);
    		GetClientRect(&rcClient);
    		dc.SetWindowExt(CONSTANT,CONSTANT);
    		dc.SetViewportExt(rcClient.right,rcClient.bottom);
    		dc.SelectObject(GetStockObject(NULL_BRUSH));
    		dc.SetROP2(R2_NOTXORPEN);
    		wsprintf(buff,L"Score: %d       ", score);
    		dc.TextOut(5,5,buff,15);
    		if(!won || resized)dc.Ellipse(ptsBegin0.x-RAD,ptsBegin0.y-RAD,ptsBegin0.x+RAD,ptsBegin0.y+RAD);
    		ptsBegin0.x = rand() % (CONSTANT-RAD) + RAD;
    		ptsBegin0.y = rand() % (CONSTANT -RAD)+ RAD;
    		dc.DPtoLP(&ptsBegin0,1);
    		dc.Ellipse(ptsBegin0.x-RAD,ptsBegin0.y-RAD,ptsBegin0.x+RAD,ptsBegin0.y+RAD);
    		if(!won || resized)dc.Ellipse(ptsEnd0.x-RAD,ptsEnd0.y-RAD,ptsEnd0.x+RAD,ptsEnd0.y+RAD);
    		ptsEnd0.x = rand() % (CONSTANT - RAD) + RAD;
    		ptsEnd0.y = rand() % (CONSTANT - RAD) + RAD;
    		dc.DPtoLP(&ptsEnd0,1);
    		dc.Ellipse(ptsEnd0.x-RAD,ptsEnd0.y-RAD,ptsEnd0.x+RAD,ptsEnd0.y+RAD);
    		won = resized = false;
    	}
    }

    Abbath, 18 Апреля 2013

    Комментарии (0)
  5. C++ / Говнокод #12592

    +16

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    char tab1[22][8]={"program","var","begin","end","int","float","bool","if","then","else","for","to","do","while","readln","writeln","as","||","!","&&","true","false"};
    char tab2[18][3]={"==","<",">","+","-","*","/","(",")",".",",",";"," ","!=","<=",">=",10};
    
    //Много кода
    
    if(!strcmp("program",st.top())&&!strcmp("program",&mas[j][0]))
    	{
    		st.pop();
    		j++;
    	}
    	else
    		if(!strcmp("var",st.top())&&!strcmp("var",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    		else
    			if(!strcmp("begin",st.top())&&!strcmp("begin",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    		else
    			if(!strcmp("end",st.top())&&!strcmp("end",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    		else
    			if(!strcmp("int",st.top())&&!strcmp("int",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    		else
    			if(!strcmp("float",st.top())&&!strcmp("float",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    
    //Еще строк 200 такого

    Abbath, 14 Февраля 2013

    Комментарии (53)
  6. C++ / Говнокод #12591

    +14

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    int main(int argc, char* argv[])
    {
    
         SetConsoleCP(1251);// установка кодовой страницы win-cp 1251 в поток ввода
       SetConsoleOutputCP(1251); // установка кодовой страницы win-cp 1251 в поток вывода
        setlocale(LC_ALL,"Ukrainian");
    
        if(argc<2)
        {
            argv[1] = (char*)malloc(500*sizeof(char));
            //printf("Vvedit' imya vxidnogo failu: \n");
            //scanf("%s",argv[1]);
            argv[1]="1.txt";
    
        }

    Abbath, 14 Февраля 2013

    Комментарии (9)
  7. C++ / Говнокод #12585

    +9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    y=fopen(lex,"w+");
    fclose(y);
    FILE *r=fopen(result,"w+");
    fclose(r);
    FILE *k=fopen("pryklad.obj","w+");
    fclose(k);

    Abbath, 13 Февраля 2013

    Комментарии (11)
  8. C++ / Говнокод #10162

    −20

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    void MainWindow::justDoIt(){
    ui->textEdit->clear();
    bool b[16];
    for (int i = 0; i < 16; ++i) {
        b[i] = false;
    }
        ui->textEdit->append("$$ \n \\begin{cases}");
        QString a;
        a += (ui->lineEdit->text().toDouble() == 0 ? "": (b[0] = true, ui->lineEdit->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_1" :ui->lineEdit->text().remove("+") + "x_1"));
        a += (ui->lineEdit_2->text().toDouble() == 0 ? "" : (b[1] = true,ui->lineEdit_2->text().toDouble() < 0 || (!b[0])? "":"+") +(ui->lineEdit_2->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_2" : ui->lineEdit_2->text().remove("+")+"x_2"));
        a += (ui->lineEdit_3->text().toDouble() == 0 ? "" : (b[2] = true,ui->lineEdit_3->text().toDouble() < 0 || (!b[0] && !b[1]) ? "":"+") +(ui->lineEdit_3->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_3" :ui->lineEdit_3->text().remove("+")+"x_3"));
        a += (ui->lineEdit_4->text().toDouble() == 0 ? "" : (b[3] = true,ui->lineEdit_4->text().toDouble() < 0 || (!b[0] && !b[1] && !b[2])? "":"+") +(ui->lineEdit_4->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_4" :ui->lineEdit_4->text().remove("+")+"x_4"));
        if(b[0] || b[1] || b[2] || b[3]){
            a += "=";
            a += ui->lineEdit_5->text();
            a += "\\\\\n";
        }
    /*еще такой же код*/ 
        a += (ui->lineEdit_24->text().toDouble() == 0 ? "" : (b[12] = true,ui->lineEdit_24->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_1" :ui->lineEdit_24->text()+"x_1"));
        a += (ui->lineEdit_21->text().toDouble() == 0 ? "" : (b[13] = true,ui->lineEdit_21->text().toDouble() < 0 || (!b[13])? "":"+") +(ui->lineEdit_21->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_2" :ui->lineEdit_21->text().remove("+")+"x_2"));
        a += (ui->lineEdit_23->text().toDouble() == 0 ? "" : (b[14] = true,ui->lineEdit_23->text().toDouble() < 0 || (!b[13]&&!b[14])? "":"+") +(ui->lineEdit_23->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_3" :ui->lineEdit_23->text().remove("+")+"x_3"));
        a += (ui->lineEdit_22->text().toDouble() == 0 ? "" : (b[15] = true,ui->lineEdit_22->text().toDouble() < 0 || (!b[13]&&!b[14]&&!b[15])? "":"+") +(ui->lineEdit_22->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_4" :ui->lineEdit_22->text().remove("+")+"x_4"));
        if(b[12] || b[13] || b[14] || b[15]){
            a += "=";
            a += ui->lineEdit_25->text();
        }
    
    ui->textEdit->append(a);
    ui->textEdit->append("\\end{cases} \n$$");
    }

    Превращает матрицу 4х5 в СЛАР на LaTeX

    Abbath, 01 Мая 2012

    Комментарии (10)
  9. Си / Говнокод #10016

    +130

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for(int j =0;j<d[i]/2;++j){
        char e[2] = {0,'\0'};
        const char* g = &e[0];
        e[0] = dict[i];
        s0.append(g);           
    }

    Нужен был const char*

    Abbath, 22 Апреля 2012

    Комментарии (4)
  10. Си / Говнокод #9112

    +131

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    #include <stdio.h>
    #include <math.h>
    void out_bin (unsigned short c){
    	for (int i = 11; i>=0; i--) {
    		if ((c & (unsigned short)(1<<i))/(1<<i)==1) printf("1");
    		else printf("0");
    	}
    	printf("\n");
    }
    int main (){
    	int a[8]={2,4,5,6,8,9,10,11};
    	int b[4]={0,1,3,7};
    	int d=0;
    	unsigned short int c=0,c1[4]={0,0,0,0};
    	unsigned char data=165,tdata=176;
    	for(int i=7;i>=0;i--)
    	{ 
    		if (tdata & 128){
    			c+=(unsigned short )(1<<a[i]);
    		}
    		tdata<<=1;
    	}
    	for (int i=0;i<8;i++){
    		unsigned short b = (unsigned short)((c & (unsigned short)(1<<a[i]))/(1<<a[i])) ;
    		if(a[i] & 1) c1[0]^=b;
    		else
    			if(a[i] & 2) c1[1]^=b ;
    			else
    				if(a[i] & 4) c1[2]^=b ;
    				else
    					if(a[i] & 8) c1[3]^=b ;
    	}
    	for (int i = 0; i < 4; i++) {
    		if (!c1[i]) {
    			c|=(unsigned short)(1<<((1<<i)-1));
    		}
    	}
    	printf("Data=      ");
    	out_bin(c);
    	c ^= 256 ;
    	if ((((c & 1024)/1024) ^ ((c & 256)/256) ^ ((c & 64)/64) ^ ((c & 16)/16) ^ ((c & 4)/4) ^ ((c & 1)/1) ) !=1 ){
    		d += 1;
    	}
    	if ((((c & 1024)/1024) ^ ((c & 512)/512) ^ ((c & 64)/64) ^ ((c & 32)/32) ^ ((c & 4)/4) ^ ((c & 2)/2) )  !=1 ){
    		d +=2;
    	}  
    	if ((((c & 2048)/2048) ^ ((c & 64)/64) ^ ((c & 32)/32) ^ ((c & 16)/16) ^ ((c & 8)/8) ) !=1 ){
    		d +=4;
    	}
    	if ((((c & 2048)/2048) ^ ((c & 1024)/1024) ^ ((c & 512)/512) ^ ((c & 256)/256) ^ ((c & 128)/128) )!=1 ){
    		d+=8;
    	}
    	printf("Spoiled=   ");
    	out_bin(c);
    	printf("%d",d);
    	if (d){
    			c ^=(1<<(d-1));
    	}
    	printf("Corrected= ");
    	out_bin(c);
    	return 0;
    }

    Код Хэмминга

    Abbath, 13 Января 2012

    Комментарии (9)
  11. Си / Говнокод #9105

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <time.h>
    char a[150],c[150];
    int main(int argc, char **argv) {	
    	FILE * tmp;
    	while(1) {
    		int b=0,b1=0;
    		bool A=0;
    		tmp=fopen(".tmp.txt","r");
    		fgets(c,150,tmp);
    		fclose(tmp);
    		system("rm .tmp.txt");
    		system("xwininfo -tree -root | grep -i '\\- deadbeef-0.5.1' > .tmp.txt");
    		tmp=fopen(".tmp.txt","r");
    		fgets(a,150,tmp);
    		fclose(tmp);
    		for(int i=16;i<149;i++) {
    
    			c[i-16]=c[i];
    			a[i-16]=a[i];
    			if(a[i-16]=='-')
    				b++;
    			if(c[i-16]=='-')
    				b1++;
    			if(b==2)
    				a[i-16]=0;
    			if(b1==2)
    				c[i-16]=0;
    		}
    		for(int j=0;j<(int)strlen(c);j++) {
    			if (a[j]!=c[j])	A=true;
    		}
    		if (A) {
    			char lamp[]="/usr/bin/purple-remote \"setstatus?status=available&message=";
    			strcat(lamp,a);
    			strcat(lamp,"\"");
    			system(lamp);
    		}
    		sleep(5);
    	}
    	return 0;
    }

    Реализация аналога pidgin-musictracker для deadbeef

    Abbath, 13 Января 2012

    Комментарии (13)