计算0到8之间的数字的公式? [英] Formula to calculate a number between 0 and 8?

查看:148
本文介绍了计算0到8之间的数字的公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Codeproject,



假设我有一行如下:



0 1 2

3 4 5

6 7 8



数字从4开始,但我只能添加或删除一个,所以说;



-1和-1等于0.

-1和0等于3 。



有什么想法吗?

Hello Codeproject,

Assuming I have a row that follows like so:

0 1 2
3 4 5
6 7 8

And the number starts at 4, but I can only add or remove one, so saying;

-1 and -1 would equal to 0.
-1 and 0 would equal to 3.

Any ideas?

推荐答案

我想我知道你在这里想说的是什么,所以这是一个尝试解决这个问题(如果我离开让我知道,你的描述有点模糊):



你可以使用二维数组,代表你的网格,然后使用你的-1 / 0 / + 1作为索引的变化,但这比你真正需要的更多。



看看它这样,这些数字真正导致了哪些变化?第一个向左或向右移动,无论你在哪里,结果都是相同的数字(例如,你从4开始,第一个数字是+1,你移动到5,这是4 + 1)。所以只需将第一个数字添加到4.第二个数字可以向上或向下移动。这些都导致3 * [第二个数字]的变化(例如你;重新定义为3,第二个数字为-1,你将-1 * 3加到3并获得:3 +( - 1 * 3)= 0) 。



所以最简单的方法是:



4 + [第一个数字] + [第二个数字] * 3
I think I know what you're trying to say here, so here's an attempt at solving this (if I'm way off let me know, your description is a little vague):

Well you could use a 2-dimensional array, representing your grid, then use your -1/0/+1 as a change in the indexes, but that's more than you really need.

Look at it this way, what changes do those numbers really result in? The first moves you left or right, no matter where you are, the results in adding the same to the number (e.g. you start at 4, the first number is +1, you move to 5, which is 4 + 1). So just add the first number to 4. The second number moves you up or down. These all result in a change of 3*[second number] (e.g. you;re at 3, the second number is -1, you add -1*3 to 3 and get: 3 + (-1 * 3) = 0).

So the simplest way is:

4 + [first number] + [second number] * 3


这篇关于计算0到8之间的数字的公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆