this one is a bit tricky. you will find lots of answers online, but try and figure this one out on your own.
you are to write a function that takes one argument, of type string. which will have a domain of {0,1}
thus a binary representation ex. char *data = "101101010001010101000101010110010101001010001000101101"
of any length. your function will return a boolean value. true if the binary string is divisible by 3, false if not.
note: you are not allowed to convert the binary string to a number. you are only allowed to work with 1's and 0's
I'm looking forward to seeing solutions, because I don't have the slightest clue how to even begin doing any of these challenges. I guess I'm not as good at programming as I thought I was.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
dandymcgee wrote:I'm looking forward to seeing solutions, because I don't have the slightest clue how to even begin doing any of these challenges. I guess I'm not as good at programming as I thought I was.
dont be so hard on yourself. im sure you can do it.
here is a FSM that i whipped together that is for binary numbers that are divisible by 2
not that when you are done with proccessing the string you have to be in state 3 inorder for the sequence to be divisible by 2. if it is in any other state its false.
implimenting it in code is fairly easy.
dandymcgee wrote:I'm looking forward to seeing solutions, because I don't have the slightest clue how to even begin doing any of these challenges. I guess I'm not as good at programming as I thought I was.
Well that's why they are "challenges" just think on them a bit and you'll think of something. I think these challenges are great. It gets creative juices flowing to do things you normally might not even think to try. Funny thing about this challenge, I was just thinking of doing something with binary numbers, and thought about your challenges, then I got on and you had a binary challenge xD
Yeah, lots and lots of homework assignments in this end as well. I glanced at the challenge: I'm curious though, when you say that you can't convert the string to numbers, that means that something like this is not valid, correct?:
sparda wrote:Yeah, lots and lots of homework assignments in this end as well. I glanced at the challenge: I'm curious though, when you say that you can't convert the string to numbers, that means that something like this is not valid, correct?:
no thats not valid, and even if it was it wouldent help. thats 101 decimal, 101 bin = 5 dec.
here is a funtion that tells you if it is divisible by 2. this should give you a very clear idea behind the concept, and making it divisible by 3 wont be that had.
PS: jot a couple of scenarios down on paper, that helps.
i could post a solution for numbers divisible by 3, then change the challenge to divisible by 5.
note: making it divisible by 5 takes a bit more brainpower to keep track of thinks, but you can get there if you follow what divisible by 3 does.
also, drawing a finite state machine helps alot. having a picture is a lot easier than trying to code it all in your head.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Aw, fuck. This is the second competition I missed...>.<
Usually I don't have time to enter these as I read them. However, these challenges are pretty freaking great.
I'm confident I can solve this one, though I confess I haven't looked too closely at the specifics and/or hints...Though the competition is over, I still refuse to check out the solution--I'll write my own sometime. ;P
Again, keep up the challenges. May I recommend giving them more time? Though I do know that leaves room for outside sources and/or other means of cheating...Aw, well. Regardless of winner, I like the fuckers. ;P
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt