Java 为什么我的项目会产生一个;“代码太大”;编译时出错?

Java 为什么我的项目会产生一个;“代码太大”;编译时出错?,java,performance,sudoku,Java,Performance,Sudoku,我有,当我试图编译它时,它返回: E:\temp\JavaApplication12\src\javaapplication12\JavaApplication12.java:15: error: code too large public static void main(String[] args) { 1 error 我的代码是一个数独解算器。首先,我需要加载所有数字,然后处理行和列中已经存在的数字,以决定我可以解决什么问题。但是它没有编译代码!我花了数周的时间来研究这个 我的数

我有,当我试图编译它时,它返回:

E:\temp\JavaApplication12\src\javaapplication12\JavaApplication12.java:15: error: code too large
    public static void main(String[] args) {
1 error
我的代码是一个数独解算器。首先,我需要加载所有数字,然后处理行和列中已经存在的数字,以决定我可以解决什么问题。但是它没有编译代码!我花了数周的时间来研究这个


我的数独解算器在恒定时间内解决问题的方法。因此,我不使用循环或数组,因为这会使问题
O(n)
。我想要
O(k)
其中
k
是常数。

即使编译代码,也无法解决数独游戏。实际上,如果81个变量
aPQ
中的任何一个等于
N
,它所做的就是将9个变量
bN
设置为true

它甚至不能有效地做到这一点。有1458(=18*81)个条件将每个
bN
变量设置为true。(简单检查:每个条件为3行;1458检查9个变量中的每个:3*1458*9=39366,文件的近似长度)

bN
的所有setter都是独立的,并且是幂等的,因此它们可以任意重新排列,并且可以删除对条件的17次重复检查

此代码的等效(且充分有效)版本(使用数组)为:

// Using 10 as array size, as OP's code is one-based;
// first element is unused.
int a[][] = new int[10][10];
// Initialize the elements of a.
boolean b[] = new boolean[10];
for (int i = 1; i <= 9; i++) {
  for (int j = 1; j <= 9; j++) {
    if (a[i][j] >= 1 && a[i][j] <= 9) {
      b[a[i][j]] = true;
    }
  }
}
script.py

import sys
import re

with open('/dev/stdin') as fh:
  lines = fh.readlines()

bequals = re.compile(r'^b\d\s*= true;$')

i = 0

bvariablesetters = {}

while i < len(lines):
  if lines[i].strip().startswith('if (') and lines[i].strip().endswith('{'):
    # Match the conditionals setting one of the b variables.
    if lines[i+2].strip() == '}' and bequals.search(lines[i+1].strip()):
      newline = ' '.join(map(str.strip, lines[i:i+3]))

      spl = newline.split()

      # This is the "b=" variable
      bvar = spl[5]
      bvariablesetters.setdefault(bvar, []).append(' '.join(newline))
      i += 3
      continue
  else:
    # Print out lines which don't match the conditional-set-b pattern, so you
    # can see that there's nothing else going on.
    sys.stdout.write(lines[i])
    i += 1

# Print the number of conditionals setting each of the b variables.
print {(k, len(v)) for k, v in bvariablesetters.iteritems()}
# Print the number of unique conditionals setting each of the b variables.
print {(k, len(set(v))) for k, v in bvariablesetters.iteritems()}

# Print one of the lists of conditions to set a b variable.
print bvariablesetters['b1=']

# Print one of the sets of conditions to set a b variable.
print sorted(set(bvariablesetters['b1=']))
导入系统 进口稀土 以open('/dev/stdin')作为fh: 行=fh.readlines() bequals=re.compile(r'^b\d\s*=true;$) i=0 bvariablesetters={} 而i
  • [performance]相关文章推荐