'Bit Test' challenge... the strange coding.. please help me.

Masti6
Posts: 55
Joined: Sat May 15, 2010 12:04 pm
Location: Finland, Nurmes

Post by Masti6 »

Along with some other Challenges, I've been stuck with this one for a couple of days now, too.
I don't know the least bit of C or C++ and I ain't interested in studying them after getting more into PHP and starting to study Python (Goin' good btw xD).
So anyways, I think this test if something is true or not, because when I give X a value, it returns either True or False, and the value of X in addition because of an additional "print x" value.
But as for the answer, I have no idea how could "something of something" be formed from "True or False", if that is the case.
If it's not even close to the answer, I've no idea.
Any C -Xpert out there, please help a little bit.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

For this challenge you should test what the logic is true for (i.e. print them), that make the answer obvious.
Masti6
Posts: 55
Joined: Sat May 15, 2010 12:04 pm
Location: Finland, Nurmes

Post by Masti6 »

So I need to to test what the logic is true for, okay.
But I printed the value
"True" when != 0
"False" when 0
But I still don't get the logic for testing is X true or false.
Maybe for an age counter of some game website (i.e. battlefieldbadcompany2.com?)
age = input
if age < 18
print "Sorry, too young"
if age > 18
print "You're old enough. Enjoy!"
.... Or ?
And if even it did have the exact same purpose, I wouldn't guess the answer is "age of user".
But something of that format.
Any more hints or even the first word (as pm?) because I don't see even the slightest bit of light shining at the end of this alleyway.
At least I think so.
Could someone please remove my sunglasses?
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

it's certainly not an age counter, also the example of

Code: Select all

if age < 18
print "Sorry, too young"
if age > 18
print "You're old enough. Enjoy!"
doesn't do the job as if your 18 it prints nothing, anyway the python equivalent of the C function

Code: Select all

bool testIt(int x) {
  return (x & (x − 1)) == 0;
}
is funnily enough

Code: Select all

def testIt(x): return (x & (x − 1)) == 0
test it and you'll see what it does
Masti6
Posts: 55
Joined: Sat May 15, 2010 12:04 pm
Location: Finland, Nurmes

Post by Masti6 »

CodeX wrote:it's certainly not an age counter, also the example of

Code: Select all

if age < 18
print "Sorry, too young"
if age > 18
print "You're old enough. Enjoy!"
doesn't do the job as if your 18 it prints nothing, anyway the python equivalent of the C function

Code: Select all

bool testIt(int x) {
  return (x & (x − 1)) == 0;
}
is funnily enough

Code: Select all

def testIt(x): return (x & (x − 1)) == 0
test it and you'll see what it does
0 if 0
1 if != 0
It still isn't clear what it actually does - there are countless options.
If value = 0 return false
If value =! 0 return true
What use could such a program possibly have :?
*Sigh* Might as well give up for now and continue trying when I get all the other ones done >.<
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

Whatever your doing, your doing it wrong if you've got 0->false + 43 posts in two days? take it easy
User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

Try going through from 1 to 100 and printing out the output of that program for each number, in format like:
1 - TRUE
2 - FALSE
3 - TRUE
4 - TRUE
(random True/False from a pseudorandom number generator)

You should see a pattern emerging!
There is no spoon.
Masti6
Posts: 55
Joined: Sat May 15, 2010 12:04 pm
Location: Finland, Nurmes

Post by Masti6 »

Thanks lazor, that was the kind of answer I was expecting. Something that made sense xD
I've got a certain pattern of True and False from numbers all the way to 100.
I've listed all True numbers, and now I've just got to figure what the list of numbers means... Right?
If so, thanks for help!

As for CodeX's message; Isn't it better to be active on forums? Any other forums I've visited give you stars or points for posting and replying. And this one gives me the profit of hearing the other user's opinions.
Last edited by Masti6 on Mon May 17, 2010 5:39 pm, edited 1 time in total.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

Activity is good but asking 1000001 questions in short succession isn't as good as a bit of perseverance to get it sorted yourself, or last resort ask on a forum. Putting your nose to the grindstone is in my opinion a pretty good way to learn, it's the way I did which is probably why I'm not a fan of the non-stop question thing - I've got friends who do the same and it hasn't helped them, but maybe I'm being too harsh. Another thing is this forum doesn't have things allong the lines of +ve, -ve, rep and all sorts of other things at all so people don't post on here to chase tags.
SecurityCrawler
Posts: 4
Joined: Tue Feb 09, 2010 10:42 pm

don't find correct words

Post by SecurityCrawler »

hi there,

i'm sure i know the answer but cannot find the correct words (i'm no native english speaker).

here is my soluten (i hope i do not spoil too much with that... :? )

this function just masks out all bit but one special bit and checks if this special bit is set. if it is set it returns true.

some of my tries so far:
only the .... bit is set
checks if the ... bit is set
just the ... bit is set

if i'm on the correct way, could someone please PM me the correct words?

Thanks!
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

If I recall the challenge asks for the answer in the form something of something, i.e. the answer fits in the sentence
ghandi wrote:The provided function checks that the parameter x is determiner something of something.
hopefully that will help you to get the correct answer.
determiner := a | the
DamaTeq
Posts: 8
Joined: Tue Feb 01, 2011 7:40 pm

Post by DamaTeq »

i struggled at this challenge quite a while because english is not my native language. But i can give you a little hint: think of a mathematical funtion which is implemented in most programming languages.
Nquit
Posts: 5
Joined: Fri Jul 15, 2011 11:02 pm

Post by Nquit »

Hello there,
i have been looking at this challange for houres.. not days yet.. i quite fast got the program running showing me the pattern.. now im at the part where i have to give the answer.. but i really don't know how to write the answer in the form of "something of something" because my native language is differnt from english.. if anyone can help me out a little.. with a hint in a PM.. please do then :)
User avatar
bodjo
Posts: 37
Joined: Sat Feb 26, 2011 9:27 am
Location: tunisia

Post by bodjo »

the word you are looking for was already given in a previous challenge not as an answer so i suggest you read the challenges attentively and you will find it
zAsus
Posts: 1
Joined: Tue Jun 12, 2012 3:38 pm

Post by zAsus »

My native language is also not English...

but I think it's a great idea to execute the code
and then compare the numbers wich returns true,
they have something in common
i'ts a math term...
...u'll get it :wink:

sry for my bad english
Post Reply