简体   繁体   English

我需要什么样的算法来计算一个等于数字的名字?

[英]What kind of algorithm would I need to compute a name that equals a number?

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.例如 A =1, B = 2 ... Z = 26 该名称是自动生成的,并且必须等于 200 加上字母的总和。 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?在创建一个函数来创建一个值为 200 的自动生成的字符串数组时,将采取哪些步骤?

How would this be done in Python?这将如何在 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)一种可能的解决方案可能如下所示(抱歉,没有 python,只有伪代码)

  1. name = "" #initialize name variable name = "" #初始化名称变量
  2. place = selectPlaceWhereToInsertNextCharacter(name)
  3. char = selectNextRandomCharacter()
  4. update name putting char in place更新namecharplace
  5. If value of ```name`` is < 200, goto 2如果 ```name` 的值 < 200,转到 2

Comments:注释:

  • Function selectNextRandomCharacter must select next character which value is less than remaining space in built so far name.函数selectNextRandomCharacter必须选择下一个字符,该字符的值小于构建的到目前为止名称中的剩余空间。 Let's say your current name is "zzz" so the value of it is 174 .假设您当前的名称是"zzz"因此它的值为174 Next letter you select can not be greater than 200 - 174 .您选择的下一个字母不能大于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. selectPlaceWhereToInsertNextCharacter(name)它只是选择您将放置下一个字符的位置。 For example if name is "pawel" there are 6 plces where you could mix in new letter.例如,如果名称是"pawel"则有 6 个可以混合新字母的位置。 This is because I assumed that name must be quite random.这是因为我认为该名称必须非常随机。
  • value of name can be checked using such python sum(map(lambda x: ord(x)-64, name))可以使用这样的 python sum(map(lambda x: ord(x)-64, name))检查 name 的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我会使用什么样的正则表达来匹配它? - What kind of regex would I use to match this? 在遗传算法中找到目标数的良好选择功能是什么? - What would be a good Selection function in a genetic algorithm to find a target number? 我需要什么样的参数才能发送此功能才能正常工作 - what kind of parameters do i need to send this function for it to work 这将命名为什么排序算法? - What sorting algorithm would this be named? 我将使用哪种数据库模式来存储用户的交易历史记录? - What kind of database schema would I use to store users' transaction histories? 我需要哪一行代码来找到 monthTotal、monthAverage 和 numDays? - What line of code would I need to find the monthTotal, monthAverage, and numDays? 我需要哪种对象才能使用fix_multiple_files的options参数? - What kind of object do I need to use the options parameter of fix_multiple_files? 如何使用我的数字语言对算法进行排序? - What Can I do for sorting algorithm with my number language? 这种物体的好名字是什么? - What's a good name for this kind of object? 该算法的复杂性是什么(在数组中搜索两次等于整数的整数) - What is the complexity of this algorithm (search twice integer equals in an array)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM