Skip to main content
Reduced b(i) by one byte
Source Link
Foogod
  • 171
  • 3

C (math), 32  /27 27 26 bytes (45 for bonus challenge)

Several people have posted various table-lookup solutions, but that seemed to me like taking the easy way out.. I wanted to see how well I could do with purely mathematical operations:

p(i){return~i&1|i*2^i*!(i%5-1);}
b(i){return( i/5)*5+1^p5*5+1^p(i);}

It wasn't clear whether one function calling the other was acceptable or not; if not, one can use this alternate definition of b(i) (33 bytes) instead:

b(i){return(i&1|i*2)+i/5-!(i/2);}

Bonus Challenge (45 bytes):

f(i,t){return(i&1|i*2)+i/5-!(i/2)^t+i/5*5*t;}

(pass t=0 for buttons, t=1 for LEDs)

C (math), 32/27 bytes (45 for bonus challenge)

Several people have posted various table-lookup solutions, but that seemed to me like taking the easy way out.. I wanted to see how well I could do with purely mathematical operations:

p(i){return~i&1|i*2^i*!(i%5-1);}
b(i){return(i/5)*5+1^p(i);}

It wasn't clear whether one function calling the other was acceptable or not; if not, one can use this alternate definition of b(i) (33 bytes) instead:

b(i){return(i&1|i*2)+i/5-!(i/2);}

Bonus Challenge (45 bytes):

f(i,t){return(i&1|i*2)+i/5-!(i/2)^t+i/5*5*t;}

(pass t=0 for buttons, t=1 for LEDs)

C (math), 32  / 27 26 bytes (45 for bonus challenge)

Several people have posted various table-lookup solutions, but that seemed to me like taking the easy way out.. I wanted to see how well I could do with purely mathematical operations:

p(i){return~i&1|i*2^i*!(i%5-1);}
b(i){return i/5*5+1^p(i);}

It wasn't clear whether one function calling the other was acceptable or not; if not, one can use this alternate definition of b(i) (33 bytes) instead:

b(i){return(i&1|i*2)+i/5-!(i/2);}

Bonus Challenge (45 bytes):

f(i,t){return(i&1|i*2)+i/5-!(i/2)^t+i/5*5*t;}

(pass t=0 for buttons, t=1 for LEDs)

Source Link
Foogod
  • 171
  • 3

C (math), 32/27 bytes (45 for bonus challenge)

Several people have posted various table-lookup solutions, but that seemed to me like taking the easy way out.. I wanted to see how well I could do with purely mathematical operations:

p(i){return~i&1|i*2^i*!(i%5-1);}
b(i){return(i/5)*5+1^p(i);}

It wasn't clear whether one function calling the other was acceptable or not; if not, one can use this alternate definition of b(i) (33 bytes) instead:

b(i){return(i&1|i*2)+i/5-!(i/2);}

Bonus Challenge (45 bytes):

f(i,t){return(i&1|i*2)+i/5-!(i/2)^t+i/5*5*t;}

(pass t=0 for buttons, t=1 for LEDs)