ChatGPT 是一种以相似谈天的方法进行交互的人工智能网络,从名字上看起来像是另一个“谈天机器人”,但实际上已经远超谈天的领域了,当要求它编写一些代码时,成果持平震撼,它能够写出一些意想不到的衔接代码,而这些代码关于开发者很有启示。

开端要求它运用 JavaScript 编写一个散列(HASH)暗码的函数。详细一点就是编写一个 JavaScript 函数,它接受暗码的字符串输入并输出散列(HASH)暗码。

function hashPassword(password) {
    return crypto.createHash("sha256").update(password).digest("hex");
}

然后逐步提高编码的难度,完成一些愈加符合项目开发的需求,所以输入:

编写一个在请求正文中包括用户名和暗码的 Express 路由处理程序,对暗码进行哈希处理,在 MySQL 数据库中查找现有用户并查看哈希后的暗码是否匹配。

const express = require("express");
const bcrypt = require("bcrypt");
const mysql = require("mysql");
// 创立 MySQL 数据库衔接
const db = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "mydb",
});
// 衔接数据库
db.connect((err) => {
    if (err) {
        throw err;
    }
    console.log("MySQL connected...");
});
// 创立 express app
const app = express();
// 路由 handler
app.post("/login", (req, res) => {
    // get username and password from request body
    const { username, password } = req.body;
    // HASH 暗码
    const hashedPassword = bcrypt.hashSync(password, 10);
    // 在数据库中查找用户称号
    let sql = `SELECT * FROM users WHERE username = '${username}'`;
    let query = db.query(sql, (err, result) => {
        if (err) throw err;
        // 查看暗码是否匹配
        if (bcrypt.compareSync(result[0].password, hashedPassword)) {
            res.send("Login successful!");
        } else {
            res.send("Incorrect username or password");
        }
    });
});

这段 JavaScript 代码基本是没什么问题的,能够直接复制到项目中进行调试。接下来运用其他言语来试一下:

用C言语编写一个链表结构的代码,具有依据“标识”属性在链表中添加、删去和查找节点的功能。

#include <stdio.h>
#include <stdlib.h>
// Structure for a node in the linked list
typedef struct Node {
    int identity; // Property of the node
    struct Node *next; // Pointer to the next node
} Node;
// Function to add a node to the linked list
void addNode(Node **head, int identity) {
    // Create a new node
    Node *newNode = (Node*)malloc(sizeof(Node));
    // Set the identity of the new node
    newNode->identity = identity;
    // Set the next pointer of the new node to point to the head
    newNode->next = *head;
    // Set the head to point to the new node
    *head = newNode;
}
// Function to delete a node from the linked list
void deleteNode(Node **head, int identity) {
    // Create a temporary node to traverse the linked list
    Node *temp = *head;
    // Check if the head is the node to be deleted
    if (temp != NULL && temp->identity == identity) {
        // Set the head to point to the next node
        *head = temp->next;
        // Free the memory allocated for the node
        free(temp);
        return;
    }
    // Traverse the linked list to find the node to be deleted
    while (temp != NULL && temp->identity != identity) {
        // Set the previous node to the current node
        Node *prev = temp;
        // Set the current node to the next node
        temp = temp->next;
    }
    // Check if the node was found
    if (temp == NULL) return;
    // Set the previous node to point to the next node
    prev->next = temp->next;
    // Free the memory allocated for the node
    free(temp);
}
// Function to find a node in the linked list
Node* findNode(Node *head, int identity) {
    // Create a temporary node to traverse the linked list
    Node *temp = head;
    // Traverse the linked list to find the node
    while (temp != NULL) {
        // Check if the current node has the given identity
        if (temp->identity == identity) {
            return temp;
        }
        // Set the current node to the next node
        temp = temp->next;
    }
    // Return NULL if the node was not found
    return NULL;
}
int main() {
    // Create a head node for the linked list
    Node *head = NULL;
    // Add some nodes to the linked list
    addNode(&head, 1);
    addNode(&head, 2);
    addNode(&head, 3);
    // Find a node in the linked list
    Node *node = findNode(head, 2);
    // Print the identity of the node
    printf("Node with identity 2: %d\n", node->identity);
    // Delete a node from the linked list
    deleteNode(&head, 2);
    // Find the deleted node in the linked list
    node = findNode(head, 2);
    // Check if the node was deleted
    if (node == NULL) {
        printf("Node with identity 2 was deleted\n");
    }
    return 0;
}

所以似乎开端担心未来的程序员,关于AI的机器学习才能,肯定是强于人类的。一个程序员名贵的工作生涯就算 20 年,就假定这个程序员在工作生涯中相当勤奋好学,可AI应该能够通过学习收集全世界所有程序员的经历!人脑无法与在极端巨大的数据集上训练有素的 AI 模型的核算才能相提并论。未来是不是有可能程序员通过AI把自己这个工作淘汰掉!

本文正在参与「金石方案 . 分割6万现金大奖」