小编ter*_*x00的帖子

可以优化或使用并行计算

我有这个问题,我需要找到等于一个数字的权力总和.例如:

输入 100 2将产生3因为输出,100 = 10^2 = 6^2 + 8^2 = 1^2 + 3^2 + 4^2 + 5^2 + 7^2并且输入100 3将产生1的输出,因为100 = 1^3 + 2^3 + 3^3 + 4^3

所以我解决这个问题的功能是:

findNums :: Int -> Int -> Int
findNums a b = length [xs | xs <- (drop 1 .) subsequences [pow x b | x <- [1..c]], foldr (+) (head xs) (tail xs) == a] where c = root a b 0 …
Run Code Online (Sandbox Code Playgroud)

parallel-processing haskell set

1
推荐指数
1
解决办法
123
查看次数

Three.js 未在现有画布上渲染

我创建了一个 ID 为“canvas”的画布,并将其作为参数提供给 Three.js 的 WebGLRenderer。然而,画布上什么也没有显示。如果我将 domElement 附加到文档中,画布将显示在底部,但我想在现有的画布上绘图。我需要更改额外的设置吗?

我使用这个示例代码开始:

  ctx = $('canvas').getContext('2d');
  var canvasElm = $('canvas');
  canvasWidth = parseInt(canvasElm.width);
  canvasHeight = parseInt(canvasElm.height);
  canvasTop = parseInt(canvasElm.style.top);
  canvasLeft = parseInt(canvasElm.style.left);

  var scene = new THREE.Scene(); // Create a Three.js scene object.
  var camera = new THREE.PerspectiveCamera(75, canvasWidth / canvasHeight, 0.1, 1000); // Define the perspective camera's attributes.

  var renderer = window.WebGLRenderingContext ? new THREE.WebGLRenderer(canvasElm) : new THREE.CanvasRenderer(); // Fallback to canvas renderer, if necessary.
  renderer.setSize(canvasWidth, canvasHeight); // Set the size of the …
Run Code Online (Sandbox Code Playgroud)

javascript canvas three.js

1
推荐指数
1
解决办法
6058
查看次数