Guessing game on uipath

Hi everyone!
I want to build a guessing game that requires an input to enter a valid 4-digit to guess the random number generated by a workflow.

For each attempt, I want to show how close the entered number is to the random number generated . So if the randomly generated number is 1234 and an user enters 1110, I want to prompt a message box to show “1P” and “0N” respectively. “1P” signifies one correct number and in the correct position (in this case number 1)while “0N” signifies no other correct number contained within the randomly generated number.

Any inputs will be appreciated!


How about the following sample? (2.4 KB)



Hi Yoichi!

Thanks for your inputs! It worked! Also, may I ask the meaning behind the different formulas you have used? Is it similar to a lambda usage?


Yes, it’s LINQ lambda expression.

data.Select(Function(x,i) x=(rnd.ToString)(i)).Count(Function(x) x)

Select method returns collection of boolean which is evaluated as x=rnd.ToString(i).
x means each character of data and i means its index, so this expression means compare i-th character of data with i-th character of rnd.
Count method returns number of true in the collection.
Then, we can get number of correct characters.

data.Distinct.sum(Function(x) Math.Min(data.Where(Function(y) y=x).Count,rnd.ToString.Where(Function(y) y=x).Count()))-p

First of all, we need to think about algorithm rather than lambda expression.
What we need to get is sum of whichever smaller number of each character in data and rnd, minus p : the above number of correct characters.
This expression means the above algorithm.


Hi, thank you for your detailed explanation! However, I’m still having difficulty understanding the second formula. Is it possible to use a numerical example? I’m not too sure the what does the different functions i.e. function(x),function(y) and the distinct.sum do.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.