简单的暴力破解

发布于 2024-12-26 04:31:55 字数 993 浏览 0 评论 0原文

我需要帮助修复对一组数字 1=9 的非常简单的暴力攻击。我的目标是解决一个数独棋盘,其中一行充满 8 个数字,以便该行只能留下一个数字。 我想到找到这个的唯一方法是为丢失的单元格分配一个数字,然后将其与该行中的每个其他数字进行检查。我非常接近解决方案,但返回值始终为 1。这是我遇到问题的代码片段: 我更新了代码,以便它现在添加所有数字并从 45 中减去它们找到正确的号码。它仍然没有返回正确的数字。它返回 423(其中缺少数字 6)。

int radd1=deduct[0][0]+deduct[0][1]+deduct[0][2]+deduct[0][3]+deduct[0][4]+deduct[0] int test=0;
if (radd1==8) {
    for (int control=0; control<9; control++) {
        if (dash[0][control]=='_') {
            empty=control;
        }
    }
    for (int control2=0; control2<9; control2++) {
        if (control2!=empty) {
            test=test+dash[0][control2];
        }
    }
    cout << test << endl;
}

更多信息:
整个解决方案基于一个 9x9 字符,其中填充了数字,并将其放置在适当的位置。该字符称为 dash[9][9]
deduct[9][9] 字符与 dash[9][9] 重复,只不过那里不是实际的数字,而是一个 1。这样我就可以将整行相加,如果它等于8,则执行简单的暴力破解(如果这是正确的术语)来找到最后的第九个数字。 empty 是一个 int。它存储(在本例中)没有编号的列号。
发现任何问题吗?

I need help fixing a very simple brute force attack on a set of numbers 1=9. My goal is to solve a sudoko board where a row is filled with 8 numbers so that there can only be one number left on the row. The only way that I thought of to find this was to assign a number to the missing cell and then check it against every other number on the row. I'm really close to the solution but the return is always a 1. Here's the snippet of code that I'm having problems with: I updated the code so that it now adds all the numbers and subtracts them from 45 to find the right number. It still doesn't return the right number. It returns 423 (With 6 as the missing number).

int radd1=deduct[0][0]+deduct[0][1]+deduct[0][2]+deduct[0][3]+deduct[0][4]+deduct[0] int test=0;
if (radd1==8) {
    for (int control=0; control<9; control++) {
        if (dash[0][control]=='_') {
            empty=control;
        }
    }
    for (int control2=0; control2<9; control2++) {
        if (control2!=empty) {
            test=test+dash[0][control2];
        }
    }
    cout << test << endl;
}

Some more info:
The entire solve is based off of one 9x9 char filled with numbers to go in their appropriate spots. This char is called dash[9][9].
The deduct[9][9] char is a duplicate of dash[9][9] except that instead of the actual number that goes there, there is a 1. This is so I can add up a whole row and if it is equal to 8 perform my simple brute force (if that's the right term) to find the final ninth number. empty is an int. It stores (in this case) the column number that has no number.
Spot any problems?

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

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

发布评论

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

评论(1

绮筵 2025-01-02 04:31:55
  1. 在 radd1 的加法中使用 deduct[0][9] 是错误的,对吧?
  2. dash[0][control3] 的比较在循环内进行,因此 test 的值始终依赖于循环的最后一次迭代。 (在本例中 control2+1dash[0][8]。我想如果存在相等性,您就必须打破循环。
  3. 您分配 control2+'1'dash[0][empty] 但后来使用 control+1 (不是同一件事)
  4. 里面的整个赋值和比较 。条件if (test==1)感觉不对,但我们无法仅从包含的代码中确定它是否正确。

有一种更好的方法可以找到尚未使用的数字。我们知道 1+2+.. +9 = 45,因此您只需将出现的数字相加,然后从 45 中减去即可获得缺少的数字。

  1. It's a mistake to be using deduct[0][9] in the addition of radd1, right?
  2. The comparison with dash[0][control3] is inside a cycle so that the value of test is always dependant in the last iteration of the cycle. (In this case control2+1 vs dash[0][8]. I suppose you'd have to break the cycle if there is an equality.
  3. You assign control2+'1' to dash[0][empty] but later use control+1. (Not the same thing)
  4. The whole assignment and comparison inside the condition if (test==1) doesn't feel right but we can't be sure if it's correct just from the included code.

There is a better way of finding the number that has not been used. We know the sum of 1+2+..+9 = 45, so you'd only have to sum the appearing numbers and substract from 45 to obtain the number that's missing.

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