- 1
}:;(1,5#3)<@}."_1'--T:: ',.~":,.10000+<.6!:0''
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 51
+122
}:;(1,5#3)<@}."_1'--T:: ',.~":,.10000+<.6!:0''
Даты. Теперь на J.
+137
ascdec proc near
mov di,0
mov si,0
xor dx,dx
mov bx,offset buf
add bx,10
mov cx,11
lo0:
dec bx
dec cx
jcxz ex0
mov al,[bx]
cmp al,255
je lo0
lo1:
sub al,30h
push bx
push cx
mov bx,offset deci
xor dx,dx
mov cx,word ptr[bx+2]
mov bx,word ptr[bx]
mov ah,0
call mult32
add di,ax
adc si,dx
mov bx,offset deci
mov ax,[bx]
mov dx,[bx+2]
call multen
mov bx,offset deci
mov [bx],ax
mov [bx+2],dx
pop cx
pop bx
dec bx
dec cx
jcxz ex0
mov al,[bx]
jmp lo1
ex0:
mov ax,di
mov dx,si
test dx,8000h
jz enda
jmp error
enda:
cmp minus,2dh
jne pl1
call ccc
pl1:
ret
ascdec endp
multen proc near
push bx
push cx
mov bx,10
mov cx,0
call mult32
pop cx
pop bx
ret
multen endp
mult32 proc near
push si
push di
push dx
push ax
test dx,8000h
jz ml
call ucc
push dx
push ax
ml:
mov dx,cx
mov ax,bx
test dx,8000h
jz ml0
call ucc
mov bx,ax
mov cx,dx
ml0:
pop ax
pop dx
mov si,0
mov di,0
mul bx ;AX*BX
mov di,ax
mov si,dx
pop ax
mul cx ;AX*CX
add si,ax
pop dx
ucc proc near
dec ax
sbb dx,0
not ax
not dx
ret
ucc endp
Превращение строки в число.
+126
check =: 3 : 0
a=.>;:y
b=.|:(6,#y) $,'(){}[]'=/a
b=.(-1 3 5{"(1)b) (1 3 5)}"(1) b
c=.|:(3 2$i.6)([:+/[{[:|:])"(1 _) b
no=._1
n=.#c
p=. 13 : 'I.*./"(1)(1 _1)="(1)(2+\(x{y))'
while. n~:no do.
no=.n
cc =. |:c
d=.~.(0 p cc),(1 p cc),(2 p cc)
c=.((i.#c)-.(d,>:d)){c
n=.#c
end.
n=0
)
samples =: '({[{}]{}[]})';'({}}{[{}]{}[]})';'({[{}]{}[]}';'({[{}]{}]})';'({[{}{}[]})';'';'{}'
test =: 13 : 'check >y{samples'
test"(0) i.7
По мотивам http://govnokod.ru/15363
+86
load 'regex'
f=: 13 : '((+./-.(1 2 3 4{y))+.(0{y))*.(5{y)'
a =: #:i.2^6
b =: f"(1) a
cc =: ":|:(|:a),(|:b)
cc1 =: (32+i.32){cc
cc2 =: (i.32){cc
ccc=:|:(|:cc2),(1 32$'*'),(|:cc1)
ccc=:('\*';'&&') rxrplc"1 (ccc)
(,&'\\ \hline')"1 (' ';' & ')rxrplc"1 (ccc)
Вот он, первый говнокод на J
+134
load 'regex'
f=: 13 : '((+./-.(1 2 3 4{y))+.(0{y))*.(5{y)'
a =: #:i.2^6
b =: f"(1) a
cc =: ":|:(|:a),(|:b)
cc1 =: (32+i.32){cc
cc2 =: (i.32){cc
ccc=:|:(|:cc2),(1 32$'*'),(|:cc1)
ccc=:('\*';'&&') rxrplc"1 (ccc)
(,&'\\ \hline')"1 (' ';' & ')rxrplc"1 (ccc)
Вот он, первый говнокод на J
+46
//В хедере
QVector<double> stateStack;
//Сохраняем
stateStack.push_back((double)renderInclusionsAs3DMeshSpheres);
stateStack.push_back((double)transparencyForClosestSidePolies);
stateStack.push_back((double)renderFEMGrid);
stateStack.push_back((double)NEST_results_detail_per_unit);
stateStack.push_back((double)sourceLineActive);
stateStack.push_back((double)renderScale);
stateStack.push_back((double)c2DZoom1To1);
stateStack.push_back((double)render2DInclusions);
stateStack.push_back((double)render3DInclusions);
stateStack.push_back((double)renderNESTResults);
stateStack.push_back((double)renderFEAResults);
stateStack.push_back((double)NEST_anumTime);
stateStack.push_back((double)isAnimRun);
stateStack.push_back((double)NEST_timeIterToRender);
stateStack.push_back((double)NEST_RenderResultsIn3D);
stateStack.push_back((double)NEST_renderTestPoints);
stateStack.push_back((double)nestNewResults);
stateStack.push_back((double)fibers_renderFormedRegions);
stateStack.push_back((double)sourceLineStarted);
stateStack.push_back((double)renderSourceLine);
stateStack.push_back((double)heatQuadsModifyMode);
stateStack.push_back((double)renderTopHeats);
stateStack.push_back((double)sliceModifyMode);
stateStack.push_back((double)useSlicePlane);
stateStack.push_back((double)showSlicedPart);
stateStack.push_back((double)cRenderMenuOpended);
stateStack.push_back((double)cForbidRenderResultsOverLayers);
stateStack.push_back((double)renderCoordLines);
stateStack.push_back((double)renderDimensions);
stateStack.push_back((double)renderLimits);
stateStack.push_back((double)cResTransparency);
stateStack.push_back((double)cRenderResultsOverLayers);
stateStack.push_back((double)cActiveLayer);
stateStack.push_back((double)renderMiniMapAtTop);
stateStack.push_back((double)subCompositeMode);
stateStack.push_back((double)subCompositeMapRendering);
stateStack.push_back((double)fibersRenderable);
stateStack.push_back((double)renderFibersAsMesh);
stateStack.push_back((double)droplets_detailedSpheres);
stateStack.push_back((double)cViewType);
//Загружаем
renderInclusionsAs3DMeshSpheres =(bool)stateStack[0];
transparencyForClosestSidePolies= stateStack[1];
renderFEMGrid=(bool) stateStack[2];
NEST_results_detail_per_unit= stateStack[3];
sourceLineActive=(bool) stateStack[4];
renderScale=(bool) stateStack[5];
c2DZoom1To1=(bool) stateStack[6];
render2DInclusions=(bool) stateStack[7];
render3DInclusions=(bool) stateStack[8];
renderNESTResults=(bool) stateStack[9];
renderFEAResults=(bool) stateStack[10];
NEST_anumTime= stateStack[11];
isAnimRun=(bool) stateStack[12];
NEST_timeIterToRender= stateStack[13];
NEST_RenderResultsIn3D=(bool) stateStack[14];
NEST_renderTestPoints=(bool) stateStack[15];
nestNewResults=(bool) stateStack[16];
fibers_renderFormedRegions=(bool) stateStack[17];
sourceLineStarted=(bool) stateStack[18];
renderSourceLine=(bool) stateStack[19];
heatQuadsModifyMode=(bool) stateStack[20];
renderTopHeats=(bool) stateStack[21];
sliceModifyMode=(bool) stateStack[22];
useSlicePlane=(bool) stateStack[23];
showSlicedPart=(bool) stateStack[24];
cRenderMenuOpended=(bool) stateStack[25];
cForbidRenderResultsOverLayers=(bool) stateStack[26];
renderCoordLines= stateStack[27];
renderDimensions=(bool) stateStack[28];
renderLimits= stateStack[29];
cResTransparency= stateStack[30];
cRenderResultsOverLayers=(bool) stateStack[31];
cActiveLayer= stateStack[32];
renderMiniMapAtTop =(bool) stateStack[33];
subCompositeMode =(bool) stateStack[34];
subCompositeMapRendering =(bool) stateStack[35];
fibersRenderable=(bool) stateStack[36];
renderFibersAsMesh=(bool) stateStack[37];
droplets_detailedSpheres= stateStack[38];
cViewType= stateStack[39];
Структуры для педиков.
+37
long* Service::qByteToLongArray(QByteArray qba, long r)
{
long* larr = new long[r];
char *carr;
carr = (char*)larr;
int len = r * sizeof(long);//length in bytes
for(int i=0; i < len; i++)
carr[i] = qba.at(i);
return larr;
}
QByteArray Service::longToQByteArray(long **larr2, long r, long c)
{
QByteArray qba;// = new QByteArray();
char **carr2;
carr2 = (char**)larr2;
int rlen = c * sizeof(long);//length of row in bytes
for(int i=0; i < r; i++){
qba.append(carr2[i], rlen);//add next row of matrix to the QByteArray
}
return qba;
}
Нашли это, только когда собрали под x64.
+55
#include <iostream>
#include <thread>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <future>
constexpr std::size_t array_size = 1e7;
constexpr std::size_t chunks_number = 1e3;
double local_pi(const std::size_t array_length)
{
std::vector<std::pair<double, double>> array_xy;
array_xy.reserve(array_length);
std::generate_n(std::back_inserter(array_xy), array_length, [](){
return std::make_pair(rand()/static_cast<double>(RAND_MAX),
rand()/static_cast<double>(RAND_MAX));
});
std::vector<bool> bool_z;
bool_z.reserve(array_length);
auto bool_z_insterter = std::back_inserter(bool_z);
std::for_each(array_xy.cbegin(), array_xy.cend(), [&](const std::pair<double, double>& ref){
const auto func = [](const std::pair<double, double>& ref){
return sqrt(pow(ref.first, 2) + pow(ref.second, 2)) <= 1.0;
};
bool_z_insterter = func(ref);
});
const auto sum = 4.0 * (std::accumulate(bool_z.cbegin(), bool_z.cend(), 0.0)/array_length);
return sum;
}
int main(){
const auto concurrency_level = std::thread::hardware_concurrency();
std::vector< double > chunks_vector;
chunks_vector.reserve(chunks_number);
for (std::size_t j = 0; j < chunks_number; ++j) {
std::vector<std::future<double>> futures;
futures.reserve(concurrency_level-1);
for (std::size_t i = 0; i < concurrency_level-1; ++i){
auto f = std::async(std::launch::async, local_pi, array_size/concurrency_level);
futures.push_back(std::move(f));
}
auto pi = local_pi(array_size/concurrency_level);
for (auto&& x : futures ){
pi += x.get();
}
pi /= concurrency_level;
chunks_vector.push_back(pi);
}
const auto total_pi = std::accumulate(chunks_vector.cbegin(), chunks_vector.cend(), 0.0)/chunks_vector.size();
std::cout << "Pi equals = " << std::scientific << total_pi << std::endl;
return 0;
}
Вычисляем pi методом Монте-Карло
+11
#define EDGE_EDGE_TEST(V0,U0,U1) \
Bx=U0[i0]-U1[i0]; \
By=U0[i1]-U1[i1]; \
Cx=V0[i0]-U0[i0]; \
Cy=V0[i1]-U0[i1]; \
f=Ay*Bx-Ax*By; \
d=By*Cx-Bx*Cy; \
if((f>0 && d>=0 && d<=f) || (f<0 && d<=0 && d>=f)) \
{ \
e=Ax*Cy-Ay*Cx; \
if(f>0) \
{ \
if(e>=0 && e<=f) return 1; \
} \
else \
{ \
if(e<=0 && e>=f) return 1; \
} \
}
#define POINT_IN_TRI(V0,U0,U1,U2) \
{ \
double a,b,c,d0,d1,d2; \
/* is T1 completly inside T2? */ \
/* check if V0 is inside tri(U0,U1,U2) */ \
a=U1[i1]-U0[i1]; \
b=-(U1[i0]-U0[i0]); \
c=-a*U0[i0]-b*U0[i1]; \
d0=a*V0[i0]+b*V0[i1]+c; \
\
a=U2[i1]-U1[i1]; \
b=-(U2[i0]-U1[i0]); \
c=-a*U1[i0]-b*U1[i1]; \
d1=a*V0[i0]+b*V0[i1]+c; \
\
a=U0[i1]-U2[i1]; \
b=-(U0[i0]-U2[i0]); \
c=-a*U2[i0]-b*U2[i1]; \
d2=a*V0[i0]+b*V0[i1]+c; \
if(d0*d1>0.0) \
{ \
if(d0*d2>0.0) return 1; \
} \
}
#define NEWCOMPUTE_INTERVALS(VV0,VV1,VV2,D0,D1,D2,D0D1,D0D2,A,B,C,X0,X1) \
{ \
if(D0D1>0.0f) \
{ \
/* here we know that D0D2<=0.0 */ \
/* that is D0, D1 are on the same side, D2 on the other or on the plane */ \
A=VV2; B=(VV0-VV2)*D2; C=(VV1-VV2)*D2; X0=D2-D0; X1=D2-D1; \
} \
else if(D0D2>0.0f)\
{ \
/* here we know that d0d1<=0.0 */ \
A=VV1; B=(VV0-VV1)*D1; C=(VV2-VV1)*D1; X0=D1-D0; X1=D1-D2; \
} \
else if(D1*D2>0.0f || D0!=0.0f) \
{ \
/* here we know that d0d1<=0.0 or that D0!=0.0 */ \
A=VV0; B=(VV1-VV0)*D0; C=(VV2-VV0)*D0; X0=D0-D1; X1=D0-D2; \
} \
else if(D1!=0.0f) \
{ \
A=VV1; B=(VV0-VV1)*D1; C=(VV2-VV1)*D1; X0=D1-D0; X1=D1-D2; \
} \
else if(D2!=0.0f) \
{ \
A=VV2; B=(VV0-VV2)*D2; C=(VV1-VV2)*D2; X0=D2-D0; X1=D2-D1; \
} \
else \
{ \
/* triangles are coplanar */ \
return coplanar_tri_tri(N1,V0,V1,V2,U0,U1,U2); \
} \
}
Макросы макросики. Inline? Нет, не слышал.
+16
QVector<Line> Converter::convert(QImage &image, Modes mode/*, int left, int top, int right, int bottom*/){
QVector<Line> result;
/* if(left < 0) left = 0;
if(top < 0) top = 0;
//if(right > image.width()) right = image.width();
//if(bottom > image.height()) bottom = image.height();
//points.clear();
//pix.fill(Qt::black);
if(left > right){
left ^= right;
right ^= left;
left ^= right;
}
if(top > bottom){
top ^= bottom;
bottom ^= top;
top ^= bottom;
}*/
int left = 0,top = 0,right = image.width(),bottom = image.height();
for( int i = left; i < right; ++i){
for( int j = top; j < bottom; ++j){
Line p;
p.x1 = p.x2 = i;
p.y1 = p.y2 = j;
p.z1 = qGray(image.pixel(i,j));
p.c = p.z1;
QVector<int> v;
if(i!=left) v.push_back(qGray(image.pixel(i-1,j)));
if(i < right-1) v.push_back(qGray(image.pixel(i+1,j)));
if(j!=top) v.push_back(qGray(image.pixel(i,j-1)));
if(j < bottom-1) v.push_back(qGray(image.pixel(i,j+1)));
if(i!=left && j!= top) v.push_back(qGray(image.pixel(i-1,j-1)));
if(i < right-1 && j!=top) v.push_back(qGray(image.pixel(i+1,j-1)));
if(j < bottom-1 && i!=left) v.push_back(qGray(image.pixel(i-1,j+1)));
if(i < right-1 && j < bottom-1) v.push_back(qGray(image.pixel(i+1,j+1)));
int min = *(std::min_element(v.begin(),v.end()));
if(min < qGray(image.pixel(i,j))){
/* for( unsigned k = 0; k < p.c-min; ++k){
Point p0;
p0.x = i;
p0.y = j;
p0.z = qGray(image.pixel(i,j))-(k+1);
p0.c = qGray(image.pixel(i,j));
points.push_back(p0);
}*/
p.z2 = p.z1 - min;
}else{
p.z2 = p.z1;
}
result.push_back(p);
}
}
/*origin.x = 0;
origin.y = 0;
origin.z = 0.0;*/
switch (mode) {
case ISO:
rotate(result, 3.1415/180*35.2,3.1415/4,-3.1415/4);
//rotate(result, 0,,0);
//rotate(result, 0,0,-3.1415/4);
break;
case BOTTOM:
rotate(result, 3.1415/180*90,0,0);
break;
case LEFT:
rotate(result, 3.1415/180*90,0,0);
rotate(result, 0, 3.1415/180*90,0);
break;
case RIGHT:
rotate(result, 3.1415/180*90,0,0);
rotate(result, 0, -3.1415/180*90,0);
break;
default:
break;
}
return result;
}
Картинка превращается, превращается...