For instance A =1, B = 2 ... Z = 26 The name is auto generated and must equal lets say 200 with the sum of the letters. eg
A = 1
AB = 3 etc
What steps would be taken in creating a function to create an array of auto generated strings that has a value of 200?
How would this be done in Python?
You want to generate a string under some constraints. And this is kind of optimisation problem. However we don't need to hire any machine learning here.
One possible solution might look like this (sorry, no python, just pseudo code)
name = ""
#initialize name variable place = selectPlaceWhereToInsertNextCharacter(name)
char = selectNextRandomCharacter()
name
putting char
in place
Comments:
selectNextRandomCharacter
must select next character which value is less than remaining space in built so far name. Let's say your current name is "zzz"
so the value of it is 174
. Next letter you select can not be greater than 200 - 174
. Othewise you will overflow. To do this - just select next integer within appropriate range and map it to char.selectPlaceWhereToInsertNextCharacter(name)
it just selects where you will put next character. For example if name is "pawel"
there are 6 plces where you could mix in new letter. This is because I assumed that name must be quite random.sum(map(lambda x: ord(x)-64, name))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.