恢复并完成数组“循环”在 obj-C 中

发布于 2025-01-05 04:52:55 字数 761 浏览 1 评论 0原文

我正在编写一个应用程序,一群人必须互相标记。所以我有一个像这样的“用户”数组:

0: paul
1: sally
2: james
3: bananaman

第一个项目 Paul 由其他三个项目标记(共十个),然后第二个项目 Sally 由其他三个项目标记(索引 2, 3, 0),依此类推,创建一个像这样的“结果”数组:

0: paul, sally, 5
1: paul, james, 7
2: paul, bananaman, 9
3: sally, james, 4

我在添加新分数时跟踪当前的“scorer”和“being_scored”整数,如下所示:

scorer = 1, being_scored = 0
scorer = 2, being_scored = 0
scorer = 3, being_scored = 0
scorer = 0, being_scored = 1
scorer = 2, being_scored = 1

但是,该组可以在任何时候停止评分,和一个不同的可以加载小组会话,这也是部分评分的。

我的问题是如何仅根据结果 [数组计数] 生成“scorer”和“being_scored”值。

大概是[结果数]除以[用户数] - 1,得到的整数是“being_scored”,余数是“评分者”。

但经过漫长的一周后,我的大脑完全崩溃了,这似乎不起作用。

任何帮助都非常感谢

迈克。

I'm writing an app where a group of people must mark each other. So I have a "Users" array like this:

0: paul
1: sally
2: james
3: bananaman

The first item Paul is marked (out of ten) by the other three, and then the second item Sally is marked by the other three (index 2, 3, 0) and so on, to create a "Results" array like this one:

0: paul, sally, 5
1: paul, james, 7
2: paul, bananaman, 9
3: sally, james, 4

I'm keeping track of the current 'scorer' and 'being_scored' integers as a new score gets added, which looks like this:

scorer = 1, being_scored = 0
scorer = 2, being_scored = 0
scorer = 3, being_scored = 0
scorer = 0, being_scored = 1
scorer = 2, being_scored = 1

However the group can stop scoring at any point, and a different group session could be loaded, which was also partially scored.

My question is how can I generate the 'scorer' and 'being_scored' values based only on the results [array count].

Presumably it's the [results count] divided by [users count] - 1, with the resulting whole number 'being_scored' and the remainder is the 'scorer'.

But my brain is utterly fried after a long week and this doesn't seem to be working.

Any help much appreciated

Mike.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生不灭 2025-01-12 04:52:55

忽略您添加的评论,即“结果”数组是多维的,仅包含具有三个字段/属性的结构/对象:得分、得分者、得分;那么您肯定只需转到“结果”的最后一个元素(位于索引 [结果计数]-1 处),选择得分和记分员,然后转到序列中的下一个元素 - 您可能已经拥有已经在循环没有中断的情况下的逻辑(类似于“如果最后一个记分器先于being_scored [通过使用模算术将数组视为循环缓冲区],则高级being_scored 和初始化记分器,否则高级记分器”)。

但这听起来相当明显,但你确实说你的大脑被炸了......

不忽略你添加的评论意味着你有一个二维数组的分数,你正在以某种模式填充?如果这是某种数字类型的预分配数组,那么如果您使用无效分数(可能是负数?)来初始化它,您将按照您的模式扫描该数组,查找第一个无效分数并从那里重新启动。如果它是单维数组的动态单维数组,则外部数组的 count 告诉您being_scored,最后一个内部数组的count 告诉您记分器...

但这听起来也相当明显...

也许睡一会儿?如果您仍然陷入困境,请重新思考问题?或者也许这只小脑袋完全没有抓住要点,其他人会帮你解决你的问题。

[这更像是一条评论,而不是一个答案,但对于评论来说太长了,抱歉。]

Ignoring your added comment that the "Results" array is multi-dimensional and simply contains structs/objects with three fields/properties: scored, scorer, score; then surely you just go to the last element of "Results" (at index [Results count]-1), select the scored and scorer and move on to the next in your sequence - which you presumably have logic for already in the case the loop was not interrupted (something like "if last scorer precedes being_scored [treating the array as a circular buffer by using modulo arithmetic] then advanced being_scored and init scorer else advance scorer").

But then that sounds rather obvious, but you did say you brain was fried...

Not Ignoring your added comment implies you have a two-dimensional array of scores which you are filling up in some pattern? If this is a pre-allocated array of some number type then if you init it with an invalid score (negative maybe?) you scan the array following your pattern looking for the first invalid score and restart from there. If it is a dynamic single dimensional array of single dimensional arrays then the count of the outer one tells you the being_scored, and the count of the last inner one tells you the scorer...

But that sounds rather obvious as well...

Maybe some sleep? Then reframe the question if you're still stuck? Or maybe this bear of little brain missed the point entirely and somebody else will figure out your question for you.

[This is more a comment than an answer, but its too long for a comment, sorry.]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文