For the numbers 1-100 print out "true" if the 2nd most least significant bit is set to 1 for that number. If not print out "false".
For the numbers 1-100 print out "true" if the 2nd most least significant bit is set to 1 for that number. If not print out "false".
Permalink: http://problemotd.com/problem/bit-counter/
Content curated by @MaxBurstein
Comments:
Anonymous - 10 years, 4 months ago
if (n Mod 4 >= 2) true
else false
reply permalink
Cha0z97 - 10 years, 4 months ago
#include <stdio.h>
int main() { int i; for (i=1;i<=100;i++) { i&2? printf("true\n") : printf("false\n"); } }
reply permalink
Johnathan - 10 years, 4 months ago
reply permalink
Johnathan - 10 years, 4 months ago
I guess format(i, '08b')[6:-1] would have made more sense. I really need to read over my programs more before I submit them. Oh well.
reply permalink
Nick Krichevsky - 10 years, 4 months ago
reply permalink
(Bernardo Botelho)[http://github.com/bzxbot] - 10 years, 4 months ago
Ruby:
(1..100).each {|n| puts n[1] == 1}
reply permalink
bzxbot - 10 years, 4 months ago
Ruby:
(1..100).each {|n| puts n[1] == 1}
reply permalink
Anonymous - 10 years, 3 months ago
Don’t overcomplicate things, just do a bitwise and
reply permalink