 |
ekhart Novice
Joined: 28 Aug 2008 Posts: 31
|
Posted: 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! |
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
 |
ekhart Novice
Joined: 28 Aug 2008 Posts: 31
|
Posted: 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. |
|
|
 |
ekhart Novice
Joined: 28 Aug 2008 Posts: 31
|
Posted: Wed Feb 15, 2012 11:49 pm Still Stick |
I am still stuck on this, anyone have any other suggestions?
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: 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:
to see what the correct answer is.
Hope this helps. |
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: 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. |
|
|
 |
|
|