

I was never happier than when the universities moved from Pascal to C, and then to C++. The move to Java is a bit more iffy, as it primarily addresses all the web programmers...
The fact that you can write such code in C does not mean C is at fault. On the contrary, it points out the power of the C language. The output is as follows:lauriet wrote:#include <stdio.h>
main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#\
;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \
){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \
}'+}##(!!/")
:t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
:0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}
Code: Select all
On the first day of Christmas my true love gave to me
a partridge in a pear tree.
On the second day of Christmas my true love gave to me
two turtle doves
and a partridge in a pear tree.
On the third day of Christmas my true love gave to me
three french hens, two turtle doves
and a partridge in a pear tree.
On the fourth day of Christmas my true love gave to me
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the fifth day of Christmas my true love gave to me
five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the sixth day of Christmas my true love gave to me
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the seventh day of Christmas my true love gave to me
seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the eigth day of Christmas my true love gave to me
eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the ninth day of Christmas my true love gave to me
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the tenth day of Christmas my true love gave to me
ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the eleventh day of Christmas my true love gave to me
eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the twelfth day of Christmas my true love gave to me
twelve drummers drumming, eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
Code: Select all
void calc_attack_info(const struct board *b, struct attack_info *ai)
{
memset(ai, 0, sizeof(struct attack_info));
for (int color = 0; color < NB_COLOR; color++) {
bitboard_t *total = &ai->attacks[color];
bitboard_t fss;
// King
*total |= ai->kattacks[color] = kattacks(b->king_pos[color]);
// Knight
fss = get_pieces(b, color, KNIGHT);
while (fss)
*total |= ai->nattacks[color] |= nattacks(pop_lsb(&fss));
// Diagonal
fss = get_BQ(b, color);
while (fss)
*total |= ai->battacks[color] |= battacks(pop_lsb(&fss), b->occ);
// Orthogonal
fss = get_RQ(b, color);
while (fss)
*total |= ai->rattacks[color] |= rattacks(pop_lsb(&fss), b->occ);
// Pawn
fss = get_pieces(b, color, PAWN);
ai->pattacks[color] = shift_bit(fss & ~file_bb(FILE_A), lc_inc(color));
ai->pattacks[color] |= shift_bit(fss & ~file_bb(FILE_H), rc_inc(color));
*total |= ai->pattacks[color];
}
// Checkers
const int us = b->turn, them = opp_color(us);
const int ksq = b->king_pos[us];
if (test_bit(ai->attacks[them], ksq)) {
ai->checkers = nattacks(ksq) & get_pieces(b, them, KNIGHT);
ai->checkers |= pattacks(us, ksq) & get_pieces(b, them, PAWN);
ai->checkers |= battacks(ksq, b->occ) & get_BQ(b, them);
ai->checkers |= rattacks(ksq, b->occ) & get_RQ(b, them);
} else
ai->checkers = 0;
}
Back when I was an undergrad, one of my friends figured out enough of the code to fix this typo.On the eigth day
Note that growing by constant amount is a VERY BAD idea (I won't say it's lame as I did the same mistake many years ago), always grow by twice the previous capacity (of course with the exception of zero).lucasart wrote:Code: Select all
s->begin = realloc(s->begin, sizeof(int) * (s->end - s->begin + ALLOC_BY));
Please spare us your C++ hatred, it starts to get annoying, in fact if I'd remove the hatred crap from all your posts (that would reduce the real content to maybe less than 50%), they may be actually interesting to read.If only we could have only the good stuff in C++ without all the crap.