Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
ekhart
Novice


Joined: 28 Aug 2008
Posts: 31

PostPosted: Sat Dec 24, 2011 7:34 am   

Making a random number out of known numbers
 
I am trying to figure out if there is a way to make Cmud create different 7-digit combinations of 7 specific numbers.

The numbers are 1, 2, 2, 5, 8, 8, and 9.

Basically I am trying to answer what has been deemed as an impossible riddle using these 7 numbers that go together in some fashion.

Example:
input 1225889
'That number is incorrect'

Any suggestions would be greatly appreciated!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Dec 24, 2011 4:55 pm   
 
#function Scramble($value) {
#local $positions $p_selected $result
//set up the $positions stringlist (1|2|3|...|N, where N is the length of the $value supplied)
#loop 1,%len($value) {
#additem $positions %i
}
//loop again to pick out digits in $value to use based on $positions selections
#loop 1,%len($value) {
$p_selected = %random(1,%numitems($positions))
$result = %copy($value,$p_selected,1)
#delnitem $positions $p_selected
}
#return $result
}

The above will not exclude prior results, so if 1952828 is incorrect it could very well try that same number next time. You will want to have some code elsewhere that checks for this (probably an oninput trigger or alias):

$result = @Scramble($value)
#until !%ismember($result,@IncorrectResults) {
$result = @Scramble($value)
}
#send "input "$result

If you are doing this via oninput trigger, you need to also use the #NOINPUT command to prevent what you typed from being sent to the game.
_________________
EDIT: I didn't like my old signature
Reply with quote
ekhart
Novice


Joined: 28 Aug 2008
Posts: 31

PostPosted: Sun Dec 25, 2011 3:12 am   Looks ok but...
 
I got this all input but I am not sure how to really run it?

Let me show what I wish to have happen...

Start trigger with some command, or just enable it:
Trigger sends 'input 1234567' for example. This number is wrong so mud sends back 'Input incorrect'.
Off of that the trigger sends another attempt, say 2345671.

This until it finds the right combination, obviously I don't know what it will send to me when the right combo is entered however.
Reply with quote
ekhart
Novice


Joined: 28 Aug 2008
Posts: 31

PostPosted: Wed Feb 15, 2012 11:49 pm   Still Stick
 
I am still stuck on this, anyone have any other suggestions?
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Feb 16, 2012 12:31 am   
 
For your convenience, I've generated the list and uploaded it at http://pastebin.com/7uJPQzjq -- Just copy all 5040 lines and paste into CMUD. It'll create a variable called 'inputlist'.

Then paste the following on your command line:
Code:
#TRIGGER {^That number is incorrect.} {inputtry=%pop(inputlist);#SEND {input @inputtry}}
inputtry=%pop(inputlist)
#SEND {input @inputtry}


This will continue to input a different number until it finds the right one. Even though we don't know what the correct answer output will be, the trigger will stop since obviously the MUD will not send "That answer is incorrect." Then all you need to do is type:
Code:
#SHOW @inputtry

to see what the correct answer is.

Hope this helps.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Feb 16, 2012 2:53 am   
 
To answer your earlier question, how do you use it...
Matt gave you two pieces of code. The first one would create a function called @scramble(). To use it, you would do something like:
Code:
$result = @scramble({1|2|2|5|8|8|9})

This would generate a random combination of those digits and return the result. You could use the second piece of code to execute that function and tell you (with a #SHOW statement) the value to try. Or you could alter that code to directly use the result however you wanted. As Matt noted, the @scramble function would not keep track of the previous results; it just generates a new random order each time, and could send the same combination again.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net