I know I’m late, but I just stumbled on this thread and found it very interesting.
I’m not very good at it, but I got most challenges down to a decent size…
I had a VERY hard time with the hex one… I dont know bitwise operators very well, so if some of you could please explain your logic with the hex challenge, I would be grateful for the lesson!
here’s my solutions:
- Capitalizer (71 bytes)
int a=0,b=0;
while ((b=in.read())>=0) {
out.write((a<33&&b>96)?b-32:b);
a=b;
}
- Reverse (93 bytes)
int b[]=new int[4<<6],l=0,x;
while ((x=in.read())>=0)b[l++]=x;
for (x=l-1;x>=0;x--)out.write(b[x]);
- Hex (231 bytes)
(note: for those who are curious about the 4<<6, that’s just a cheap way to get a 4-digit-sized buffer (at the time I didn’t know the scenarios were not dynamic…)
int b[] = new int[4<<6];
int x,l = 0,y = 0;
while ((x = in.read()) >= 0) b[l++] = x;
for (x = 0;x < l;x++) {
if (b[x] >= 48 && b[x] <= 57) {
if ((x+1)%2 == 0) y+=b[x]-48;
else y = b[x]-48<<4;
}
else {
if ((x+1)%2 == 0) y+=b[x]-87;
else y+=b[x]-87<<4;
}
if ((x+1)%2 == 0) {
out.write(y);
y = 0;
}
}
- ByteSwap (63 bytes)
int x;
while ((x=in.read())>0) {
out.write(in.read());
out.write(x);
}
- BarcodeReader (90 bytes)
int c = 48,x = 0;
while (x > -2) {
x = in.read();
if (x == 32 ^ x < 0) {
out.write(c);
c = 48;
}
else c++;
if (x < 0) x = -2;
}
- BinaryShrink (112 bytes)
int x,y,z;
while ((x = in.read()) >= 0) {
y = 7;
z = 0;
do {
z+=(1<<(y--))*(x-48);
if (y >= 0) x = in.read();
} while (y >= 0);
out.write(z);
}
- BitEncoder (62 bytes)
int a = 0,x;
while ((x = in.read()) > 0) {
if (x > 48) a^=1;
out.write(a+48);
}