如何对以下数字表示进行编码
嗯,这是我在作业中遇到的一个问题..我没有任何线索继续
问题是这样的
一名男子希望与外星人沟通,通过提供将他安全降落在地球站
坐标,但外星人使用略有不同的数字表示形式(不是十进制)
外星人表示包含字符集(ofa)
现在对于输入 (9,5) 人给出以下 (foo,fa)
你能给我提示或代码吗,以便我可以尝试自己编写代码
well its a question i got in an assignment..and i am getting no clue to proceed
the question is like this
A man want to communicate with alien to land him safely on earth station by providing
co-ordinates but alien use somewhat different representation of numbers(not decimal)
Alien representation contain the character set(o f a)
now for input (9,5) man gives him the following (foo,fa)
can you please give me hint or code so that i can try to write code myself
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
提示:
共有三个符号。在十进制 (base-10) 中,有 10 位数字: 0 1 2 3 4 5 6 7 8 9。在二进制 (base-2) 中,有两个数字,0 和 1。在 base-16 中,有 16 位数字。既然外星系统中有三个符号,我们可以猜测一下它的组织吗?
5base10 = 12base3。 9base10 = 100base3。所以十进制的 (9,5) 与三进制的 (100, 12) 相同。我们能否猜测哪些外星符号代表哪些人类数字?
Hints:
There are three symbols. In decimal (base-10), there are 10 digits: 0 1 2 3 4 5 6 7 8 9. In binary (base-2) there are two digits, 0 and 1. In base-16 there are 16 digits. Since there are three symbols in the alien system, could we make a guess about its organization?
5base10 = 12base3. 9base10 = 100base3. So (9,5) in decimal is the same as (100, 12) in trinary. Can we make a guess about which alien symbols represent which human digits?
提示:外星人和我们一样使用位置数字系统。 (换句话说,它可能不是罗马数字或拼写数字名称之类的东西。)
第二个提示:考虑外星人的数字系统中有多少个字符。
Hint: The alien is using a positional number system like we do. (In other words, it's probably not something like Roman numerals or spelling out the names of the numbers.)
Second hint: Consider how many characters are in the alien's number system.
看起来它们是三元的。
您想要将十进制(以 10 为基数)转换为三进制(以 3 为基数)。
您会注意到,外星人使用的是
o
、f<,而不是
0
、1
和2
。 /code> 和a
。它们基本上映射到相同的数字。因此,要得到答案,请将十进制转换为三进制,然后用数字替换外来字符。
PHP 代码示例
这在任何语言中都是可行的,尽管 PHP 很幸运有一个本地
base_convert()
函数。Looks like they are ternary.
You want to convert decimal (base 10) to ternary (base 3).
You will notice instead of using
0
,1
and2
, the alien useso
,f
anda
. They basically map to the same numbers.So to get the answer, convert from decimal to ternary, and then substitute the numbers for the alien characters.
Example PHP code
This is doable in any language, though PHP is fortunate enough to have a native
base_convert()
function.