To write such an expressive code D

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 10 03:25:50 PST 2015


Please help.

import std.stdio;
import std.stdio;

void main()
{
	/* return (a xor b xor c) */
	int nobitxor(int a, int b, int c) {
		return (a + b + c == 2 || a + b + c == 0) ? 0 : 1;
	}
	
	int a, b, c;
	
	a = b = c = 0;
	
	foreach (i; 0 .. 8) {
		if (i > 3)
			a = 1;
		if (i == 2 || i == 3 || i == 6 || i == 7)
			b = 1;
		if (i % 2)
			c = 1;
		writeln(a, b, c, ' ', nobitxor(a, b, c));
		a = b = c = 0;
	}
}

Output:

000 0
001 1
010 1
011 0
100 1
101 0
110 0
111 1

You need to function nobitxor(int a, int b, int c) not used 
bitwise/logical and mathematical operations.


More information about the Digitalmars-d-learn mailing list