DogChallenges | Join And Retrieve Number! - Challenge N°1

Everything else that doesn't fall into one of the other PB categories.

Are you in the challenge?

Yes, Let's try!
7
58%
No, seems like too hard!!
5
42%
 
Total votes: 12

dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

DogChallenges | Join And Retrieve Number! - Challenge N°1

Post by dagcrack »

Well yes, indeed. My challenges begins.

This first one is easy (in my opinion).


What to accomplish:

You must be able to join a 3 char number into a 5 char number
And later be able to retrieve this 3 char number from the 5 one with OUT knowing how big the 3 char number is (that is the point of the entire challenge).


Rules:

You can't use string operations
You can't make the 5 char number bigger than 5 chars
You can't use floats (as final output)
You can't use longs (as final output)

As for a starting point:

The big number is as big as a word goes
The small number is as big as a byte goes

The numbers (both) would be random and your "algorithm" should return the correct numbers after processed. Its easy obviously if you use 2 fixed numbers.. However the point of the challenge is to make an algo that works with any number within the said limits.


So, in process number 1 we join our small number which let's say is 240 to let's say 43200. We get 43440 as an obvious output if we just add the 240 to the big number..

Now on process number 2 you should be able to take the small number out of the big one with OUT knowing the small number. thats the point.

You can't make the 5 char number bigger than it is, so this for example is not a good idea:

Code: Select all

  num = 32767 ; original number  
  Debug num
  shifted = (num << 8) | 235 ; the small number to add
  Debug shifted 
  thenum = shifted & $FF ; shifted with the number
  Debug thenum
  retrieved = (shifted >> 8) ; we get the original number now
  Debug retrieved
However it does the job, indeed.


Another stupid useless method you shouldnt try:
sqrt(65280 +256 )

obviously it WILL return 256 (the small number you first put), but sure you shouldnt forget that both numbers would be random and the output should be the correct, so SQRT busted I'm afraid ;)


Curious note:

4 programmers tried this with out any good results, they all failed

And 1 provided a string solution (hence I had to add that you cant perform string operations to accomplish this)


I will let this challenge run for long, if no one could accomplish it, I might post a solution. I have other challenges as well, however they are harder so let's start with something easy!.


Notice: You CAN add the number as you want and retrieve it as you want as well, there are no rules for this. The only rules were stated above.

The resulting codes will be benchmarked later to see not only if it does the job but also which one is the fastest method!.

I would say that Arithmetic and Bitwise operations are a must-know for this little challenge.


Whos up to the task?, I could send you a beer as price :lol:
Please post your questions, don't start if you didnt get one of the points yet (I don't want you to waste your time, that's why).

Have fun!!
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

You can't use string operations
You can't make the 5 char number bigger than 5 chars
You can't use floats (as final output)
You can't use longs (as final output)
What should you use if you don't use floats, longs or strings? Quads?

In your example, you use a long as final output?
The big number is as big as a word goes
The small number is as big as a byte goes

So, in process number 1 we join our small number which let's say is 240 to let's say 43200. We get 43440 as an obvious output if we just add the 240 to the big number..
Hmm. How come you got a word over 37267?

Edit:
This was probably not what you thought, but it doesn't appear to me like it vialotes any of the rules written in your post.

Code: Select all

fivecharnumber = AllocateMemory(5)
PokeL(fivecharnumber, Random(32768))
PokeB(fivecharnumber+4, Random(256))
;Voila, stored the three char number into the five char number!

Debug PeekL(fivecharnumber)
Debug PeekB(fivecharnumber+4)
;Voila, they're back!
Sure, it works. And let's check the rules:
You must be able to join a 3 char number into a 5 char number (passed)
And later be able to retrieve this 3 char number from the 5 one with OUT knowing how big the 3 char number is (that is the point of the entire challenge). (passed, but I do know that the 3 char number is not higher than a byte.)
You can't use string operations. (Passed)
You can't make the 5 char number bigger than 5 chars. (I know two kinds of chars, ascii and unicode. To make it harder I chose the ascii variant, which occupies one byte. Therefore I am allowed to use 5 bytes, since 5 is not bigger than 5. I'd say passed)
You can't use floats (as final output) (Passed)
You can't use longs (as final output) (I don't understand what we should output if not longs. Anyway, I use them minimally)
The big number is as big as a word goes (Passed, if we're talking about signed word. It _should_ work with unsigned, too, but that's not tested.)
The small number is as big as a byte goes (It is, passed)
The numbers (both) would be random and your "algorithm" should return the correct numbers after processed. (Passed)

:?:
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

:lol:

But I did mention "2 separate proccesses" I think I also said "you don't know the small number, you just have the big one and need to extract the small one SOMEHOW"

And emh. thats not "into" thats just in a memory location. So it violates the rules.

You should be able to retrieve the small value out of the big value with out losing any data and of course, you cant store them separetly as you did, think about storing it in a file and then you read it. You cant use your method with out having to store both separetly. Which violates the rules. Strictly says " one into the other " but it MEANS that, not that you'll store inside a memory location.. (not that you cant use memory functions though, you just cant do it that way, don't you think it'd too be easy and pointless then??)

Heh just as funny as the string solution one subbmited to me before opening the challenge in here :D

The problem is that people thinks its too easy and so they take it to the least clever solution. which is wrong as it doesnt pass the rules.

Sorry! - Good try!


By the way: Indeed my example outputs a LONG as I said "this is how you would do it, however its not valid for the challenge since you get a -big- value as output" - Indeed a long.

So: Process 1 ) you store both values inside 1, how? thats the big part of the challenge. Later on you store this value be it in memory or a file, or just work from the output into process 2. Process 2 ) you must retrieve the small value out of the big value with out losing any data, you can load the big value that contains the small one from a file or memory, or simply by calling the output value of the proccess number 1.

Hope its more clear.

Bye guys..
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

So: Process 1 ) you store both values inside 1, how? thats the big part of the challenge. Later on you store this value be it in memory or a file, or just work from the output into process 2.
You didn't tell me how large memory area I could use when storing number 1. I used 5 bytes. How many can I use?

Actually, it seems to me as my submission still doesn't violate the rules.

If you're trying to get us to store a byte and a word inside a word, that is impossible, but I guess you knew that.

Edit: Or do you mean: Store one number from and including 0 to and including 32767 and one number from and including 0 to and including 255 inside two bytes?

Edit 2: No, that's impossible, too.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

It's not impossible, Nothing is impossible. You just need to think about it.
That is the challenge about. If you can do it, Respect. If you can't, I thought so.

Your algorithm can use any memory you like, if you're able to retrieve both numbers from those 2 bytes, then it'd be worth it. Once you're able to do that, then other aspects of the method will be judged.

Your "method" is no said method since its not a method at all.. But what you dont see is that how can you store that within 2 bytes (word)? You cant.

Can you blend a byte inside a word and later on retrieve both numbers from the blended word? yes you can. HOW? that IS the Challenge about.

And think that this is the first challenge, next ones will be hard. That if anyone can solve this one :)
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

dagcrack wrote:Your algorithm can use any memory you like, if you're able to retrieve both numbers from those 2 bytes, then it'd be worth it. Once you're able to do that, then other aspects of the method will be judged.

Can you blend a byte inside a word and later on retrieve both numbers from the blended word? yes you can. HOW? that IS the Challenge about.
No, it's impossible to store both a word and a byte in two bytes. Even if the word should always be positively signed.

Two bytes, which we should use, is 16 bits. These bits can have the value of either 0 or 1.

This gives us a total of 2^16 = 65536 combinations.
Then for the two numbers. We must be able to store both an arbitary number [0 .. 32767] and another arbitary number [0 .. 255]. This means that we can get the lowest number of combinations required by multiplying 32767 by 255. We then get 8355585. That's WAY over the number of combinations you can get while using only 16 bits. No matter how good you are with bitwise operators you can't make 8355585 combinations from 16 bits which can have the value 1 or 0.

You must be a politician to say otherwise.

Edit: Even though the above should convince any sane person, I'll explain it again in a less formal way:

32767 has all but one bit set: 0111111111111111
The last bit can only be set or unset, you won't be able to store a byte in it. :wink:
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

i agree with trond. Its not possible..
uhmm.. Well he did say that if no one could solve it, he had the answer. I think its quite on time to tell that :)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

thefool wrote:i agree with trond. Its not possible..
uhmm.. Well he did say that if no one could solve it, he had the answer. I think its quite on time to tell that :)
Yes, we're waiting.

And if this was easy, I wonder what the next challenge would be? Fit 23 bits into 16 bits?

No, that wasn't the next challenge, that was the current one! :roll:
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

These two numbers - you create them (random) and store them.

On retrieval, you still have the two numbers?

If you do (or at least one of them) then perhaps Xor-ing is a way of storing, implied, the two in one. But that sounds too easy.

And, to be honest, I don't really get the gist of this - or the rules. In other words, I am not quite sure what we are trying to do.

Are we working in a two byte space in memory or are we working with a 5 digit number (with some limits) and this has nothing to do with words or storage requirements?


Edit:

One way (if 4 bytes is the "store") is to take the least significant bits of each digit and store in a nibble.

So: "12345" and "123"
Hex: 31 32 33 34 35 and 31 32 33
LSB hex is 12 34 51 23
First 5 nibbles is the biggie and last 5 is the little-ie

But we can't use strings or longs?

Please re-explain the rules. Thanks!
@}--`--,-- A rose by any other name ..
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Dare2 wrote:Please re-explain the rules. Thanks!
Store any random 23 bits into 16 bits (use no other hidden storage place). Then you should restore the 23 bits from the 16 bits. Get it? :roll:
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Heya Trond,

But for the reasons you explained (full house of bits for 32767) that can't be the challenge! There must be something in the way the rules are laid out that confuses the issue.

The challenge for me is to understand the challenge. :)



Edit: I cannot believe I wasted my 2000th post talking about nibbles!

Mind you, I wasted the previous 1,999 talking about zip, so ..
@}--`--,-- A rose by any other name ..
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Dare2 wrote:But for the reasons you explained (full house of bits for 32767) that can't be the challenge! There must be something in the way the rules are laid out that confuses the issue.
I think he was simply trying to see how long he could keep some idiots busy. :wink:

But I don't think we'll see him here in a while because I gave him the challenge to place some air in the corner of a sphere and he said that should be easy and I haven't seen him since. :twisted:
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

lol. :D You can pack the zingers in - multiple birds with one stone!

This challenge should be PySeZ for you. ;)
@}--`--,-- A rose by any other name ..
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

If we don't get a comment on this we will add you here: viewtopic.php?t=17818 :twisted:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

How is this?

Code: Select all

Global i

;Show progress
Procedure Progress(void)
  Repeat
    ConsoleLocate(0, 9)
    PrintN("Brute forcing the byte out of 'nothing'...")
    Print("Estimated progress (worst case scenario): " + StrF(i*100/2147483647) + "%")
    Sleep_(1000)
  ForEver
EndProcedure

OpenConsole()
byte.b = Random(255)
word.w = Random(32767)

PrintN("Random numbers:")
PrintN("    byte: " + Str(byte))
PrintN("    word: " + Str(word))

;Remove byte!
byte.b = 0

PrintN("The byte is now set to 0:")
PrintN("    byte: " + Str(byte))
PrintN("    word: " + Str(word))

;Recover both!
id = CreateThread(@Progress(), 0)
i = 0
sec = Random(32767)
Repeat
  RandomSeed(i)
  byte.b = Random(255)
  _word.w = Random(32767)
  _sec = Random(32767)
  If _word = Word
    If _sec = sec
      Break
    EndIf
  EndIf
  i + 1
ForEver
KillThread(id)
ConsoleLocate(0, 10)
PrintN("Estimated progress: finished!                                ")
PrintN("")

PrintN("The byte is 'magically' recovered!")
PrintN("    byte: " + Str(byte))
PrintN("    word: " + Str(word))

Input()
When are you going to post your solution? :)
Post Reply