Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Elegant solutions

Name: Anonymous 2007-06-28 15:16 ID:lcs47ZU6

Im bored, show me some good code (any language whatsoever)
Post a problem, then a great solution.

1) Transpose a matrix
(apply #'mapcar #'list '(( 1  2  3  4)
                         ( 5  6  7  8)
                         ( 9 10 11 12)
                         (13 14 15 16)))
(( 1  5  9 13)
 ( 2  6 10 14)
 ( 3  7 11 15)
 ( 4  8 12 16))

Name: Anonymous 2007-07-03 9:27 ID:fkP3dR0i

>>64

#define bigger(x, z) ((x>z)?(x):(z))

Name: Anonymous 2007-07-03 9:46 ID:ANmcquwZ

template <class T> T bigger (T t1, T t2){ return t1>t2 ? t1 : t2; }

(defun bigger (x y) (if (> x y) x y) )

Name: Anonymous 2007-07-03 11:05 ID:Heaven

>>33
'uniq' the unix command assumes the input is sorted and so should all functions named uniq

Name: Anonymous 2007-07-03 11:12 ID:f8ckGWbD

>>64
tuck - dup abs + 2/ +

or you could just use math::max (http://factorcode.org/responder/browser/browse?apropos=&word=max&vocab=math), which basically does this:
2dup > [ drop ] [ nip ] if

>>65
#define bigger(x,z) (x>z?x:z)

Name: Anonymous 2007-07-03 11:23 ID:/LWDyi+e

>>68
#define bigger(x,z) ([b]([/b]x[b])[/b]>[b]([/b]z[b])[/b]?[b]([/b]x[b])[/b]:[b]([/b]z[b])[/b])

Name: Anonymous 2007-07-03 11:30 ID:Heaven

I AM NOT AN EXPERT BBCODE PROGRAMMER :(
#define bigger(x,z) ((x)>(z)?(x):(z))

Name: Anonymous 2007-07-03 11:44 ID:ANmcquwZ

>>68 It is still fail.

#define bigger(x,z) (x>z?x:z)
bool condition=true;
std::cout << bigger(condition ? 1 : 3, 37) << std::endl;

Yes ladies and gentlemen, the output is 1.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List