n/chit-chatu/Str · 2025-02-28
注册 登录
n/chit-chat · 2025-02-28 · 399 次浏览
u/Str荣誉会员王者

来试试这个prompt,看看你用的ai能不能正确生成

prompt

```
请写一个js函数,传入一个坐标,按蚊香形状生成下一个坐标
规律:[0,0]、[1,0]、[1,1]、[0,1]、[-1,1]、[-1,0]、[-1,-1]、[0,-1]、[1,-1]、[2,-1]……
```

实际上就是按这样子的方式生成步
Image description~~

目前deepseek R1 能做出来, V3 有时候能做出来(不过大多数时候不行)

0
7
登录后参与讨论。

7 条回复

排序
  1. Str 荣誉会员 王者 楼主 2025-02-28

    目前的生成结果都是要用到历史记录的

    Image description~~

    蹲一个不用历史记录就可以生成的代码

    0
  2. Nahida1027 黄金 不离不弃 2025-02-28

    @"‏[已注销]"#p249895 gpt是

    ```
    function generateNextCoordinate(coord) {
    let [x, y] = coord;
    let distance = 1; // 当前螺旋圈的步长
    let direction = 0; // 方向: 0 - 右, 1 - 上, 2 - 左, 3 - 下

    // 先构造一个用于记录每个方向移动的步数
    const directions = [
        [1, 0],  // 向右
        [0, 1],  // 向上
        [-1, 0], // 向左
        [0, -1]  // 向下
    ];
    
    let steps = 0; // 当前已经走的步数
    let changesInDirection = 0; // 用来决定何时增加步长
    
    while (steps < distance) {
        // 按照当前方向移动一步
        x += directions[direction][0];
        y += directions[direction][1];
        steps++;
        
        // 每四步就改变方向
        if (steps === distance) {
            direction = (direction + 1) % 4;
            steps = 0;
            changesInDirection++;
            
            // 每两次改变方向后增加步长
            if (changesInDirection % 2 === 0) {
                distance++;
            }
        }
    }
    
    return [x, y];
    

    }

    let currentCoord = [0, 0];
    for (let i = 0; i < 20; i++) {
    currentCoord = generateNextCoordinate(currentCoord);
    console.log(currentCoord);
    }
    ```

    0
  3. James 💯 传奇 MANAGER 2025-02-28

    @"Nahida1027"#p249974 多行代码要用 ``` 括起来才行。

    0
  4. alphamiaomiao 黄金 2025-02-28

    claude 3.5

    ```javascript
    /**

    • 根据当前坐标按蚊香形状生成下一个坐标

    • @param {number[]} coord - 当前坐标 [x, y]

    • @returns {number[]} - 下一个坐标 [x, y]
      */
      function getNextCoordinate(coord) {
      const [x, y] = coord;

      // 确定当前所在的"层"
      const layer = Math.max(Math.abs(x), Math.abs(y));

      // 判断当前位置在哪个边
      if (x === layer && y < layer) {
      // 右边,向上移动
      return [x, y + 1];
      } else if (y === layer && x > -layer) {
      // 上边,向左移动
      return [x - 1, y];
      } else if (x === -layer && y > -layer) {
      // 左边,向下移动
      return [x, y - 1];
      } else if (y === -layer && x < layer) {
      // 下边,向右移动
      return [x + 1, y];
      } else if (x === layer && y === -layer) {
      // 右下角,开始新的一层
      return [x + 1, y];
      }

      // 默认情况(不应该到达这里)
      console.error("无法确定下一个坐标");
      return coord;
      }

    // 测试函数
    function testSpiral() {
    let current = [0, 0];
    const steps = 20;
    const result = [current];

    for (let i = 0; i &lt; steps; i++) {
        current = getNextCoordinate([...current]);
        result.push(current);
    }
    
    console.log(result);
    

    }

    // 运行测试
    testSpiral();
    ```
    Image description~~
    :ac06:

    0
  5. reatestpiller 黄金 2025-02-28

    Grok-3

    ```
    function nextCoordinate(current) {
    // 输入坐标
    let [targetX, targetY] = current;

    // 定义方向:右、上、左、下
    const directions = [[1, 0], [0, 1], [-1, 0], [0, -1]];

    // 初始化起点和状态
    let cur = [0, 0];
    let m = 0; // 当前段编号
    let s = 0; // 当前段内已走步数
    let dirIndex = 0; // 当前方向索引
    let step_count = Math.floor(m / 2) + 1; // 当前段总步数

    // 模拟序列直到找到目标坐标
    while (cur[0] !== targetX || cur[1] !== targetY) {
    if (s < step_count) {
    // 在当前段内继续移动
    cur[0] += directions[dirIndex][0];
    cur[1] += directions[dirIndex][1];
    s += 1;
    } else {
    // 进入下一段
    m += 1;
    s = 1;
    dirIndex = (dirIndex + 1) % 4;
    step_count = Math.floor(m / 2) + 1;
    // 沿新方向移动一步
    cur[0] += directions[dirIndex][0];
    cur[1] += directions[dirIndex][1];
    }
    }

    // 当前 cur == [targetX, targetY],计算下一个坐标
    if (s < step_count) {
    // 仍在当前段内,沿当前方向移动
    return [
    targetX + directions[dirIndex][0],
    targetY + directions[dirIndex][1]
    ];
    } else {
    // 当前段结束,沿下一方向移动
    let nextDirIndex = (dirIndex + 1) % 4;
    return [
    targetX + directions[nextDirIndex][0],
    targetY + directions[nextDirIndex][1]
    ];
    }
    }
    ```

    0
  6. JeanValJean 白银 2025-03-01

    Claude 3.7-think

    预览图:https://share.cleanshot.com/YxCy6rmy20sJqSxjlPg5

    ```
    /**

    • 根据蚊香形状规律生成下一个坐标

    • @param {Array} coord - 当前坐标 [x, y]

    • @return {Array} - 下一个坐标 [x, y]
      */
      function getNextCoordinate([x, y]) {
      // 特殊情况:起点 [0,0]
      if (x === 0 && y === 0) return [1, 0];

      // 根据示例规律:[0,0]、[1,0]、[1,1]、[0,1]、[-1,1]、[-1,0]、[-1,-1]、[0,-1]、[1,-1]、[2,-1]...
      if (x > 0 && y === 0) return [x, 1]; // 从[1,0]到[1,1],方向:向上
      if (x > 0 && y > 0 && x === y) return [x-1, y]; // 从[1,1]到[0,1],方向:向左
      if (x === 0 && y > 0) return [-1, y]; // 从[0,1]到[-1,1],方向:向左
      if (x < 0 && y > 0 && Math.abs(x) === y) return [x, y-1]; // 从[-1,1]到[-1,0],方向:向下
      if (x < 0 && y === 0) return [x, -1]; // 从[-1,0]到[-1,-1],方向:向下
      if (x < 0 && y < 0 && Math.abs(x) === Math.abs(y)) return [x+1, y]; // 从[-1,-1]到[0,-1],方向:向右
      if (x === 0 && y < 0) return [1, y]; // 从[0,-1]到[1,-1],方向:向右
      if (x > 0 && y < 0 && Math.abs(y) === 1 && x < 2) return [x+1, y]; // 从[1,-1]到[2,-1],方向:向右

      // 确定当前所在的层数
      const ring = Math.max(Math.abs(x), Math.abs(y));

      // 处理后续螺旋轨迹的一般情况
      // 右侧移动,向上
      if (x === ring && y < ring && y > -ring) return [x, y+1];
      // 上侧移动,向左
      if (y === ring && x > -ring) return [x-1, y];
      // 左侧移动,向下
      if (x === -ring && y > -ring) return [x, y-1];
      // 下侧移动,向右
      if (y === -ring && x < ring) return [x+1, y];

      // 处理下一个更大的螺旋开始情况
      if (x === ring && y === -ring) return [x+1, y]; // 右下角,向右进入新的螺旋

      // 如果遇到未预期的情况
      console.error("未处理的坐标情况:", [x, y]);
      return [x+1, y]; // 默认向右移动
      }

    /**

    • 生成蚊香形轨迹的多个点
    • @param {number} numPoints - 要生成的点数量
    • @return {Array} - 生成的点数组
      */
      function generateSpiralPoints(numPoints) {
      const points = [[0, 0]];
      let currentPoint = [0, 0];

    for (let i = 1; i < numPoints; i++) {
    currentPoint = getNextCoordinate([...currentPoint]);
    points.push([...currentPoint]);
    }

    return points;
    }

    // 示例使用
    // const points = generateSpiralPoints(47);
    // console.log(points);
    ```

    0
  7. Str 荣誉会员 王者 楼主 2025-03-01

    @"Nahida1027"#p249974 这个存历史了(

    @"alphamiaomiao"#p250172 哈哈,代码是错的

    @"piller"#p250193 你可以测试一下能不能用

    @"Walker"#p250529 看起来你这个应该是最强的

    0