Click here to Skip to main content
15,867,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello:

This code is in FreeBasic...

How do you undo it , to reveal v1 , v2 , v3 ???

BASIC
screen 19

do
    
    dim as ubyte v1 = int( rnd * 4 ) + 1
    dim as ubyte v2 = int( rnd * 4 ) + 1
    dim as ubyte v3 = int( rnd * 4 ) + 1
    
    dim as string n2 = hex( ( v1 * v2 ) - 1 ) + hex(  ( v2 * v3 ) - 1 )
    
    print v1 , v2 , v3 , n2
    sleep
    
    if inkey = chr( 27 ) then end
    
loop

end


What I have tried:

Stuck on it..

v1 * v2 and v2 * v3 : you should be able to identify all 3 original values..
Posted
Updated 8-Sep-21 11:49am
v2
Comments
Member 15329613 8-Sep-21 13:35pm    
What is your question? You want to know what the original values were of v1, v2, and v3? They never change after you set them, right?
Patrice T 8-Sep-21 13:55pm    
"How to find v1 , v2 , v3 ?"
describe your question with detail.
"print v1 , v2 , v3 , n2"
should already give you answer on screen.

Quote:
v1 * v2 and v2 * v3 : you should be able to identify all 3 original values..

As far as I understand your code, the answer is NO.
Because:
V1=1, V2=2, V3=1 gives N="22"
and
V1=2, V2=1, V3=2 gives N="22"
 
Share this answer
 
You can't "undo" it: there are too many ways to generate a number and you require a singe solution.
Think about it: how many different sets of values values could give you a result of 141?
If there are two or more, you are stuffed!
 
Share this answer
 
It makes it possible with the following code added

map+= bin( v2 mod 2 )


so ((v1*v2)-1) and ((v2*v3)-1)

if you know that v2 is even or odd , since the values are all 1 to 4.

if v2 is odd then it has to be a 1 or 3 else its a 2 or 4
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900