一区二区三区三上|欧美在线视频五区|国产午夜无码在线观看视频|亚洲国产裸体网站|无码成年人影视|亚洲AV亚洲AV|成人开心激情五月|欧美性爱内射视频|超碰人人干人人上|一区二区无码三区亚洲人区久久精品

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

OpenAI 在精簡(jiǎn)代碼方面的出色表現(xiàn)令人震驚

KiCad ? 來源:KiCad ? 作者:KiCad ? 2025-04-28 18:24 ? 次閱讀

本文轉(zhuǎn)載自https://glama.ai/blog/2024-08-29-reverse-engineering-minified-code-using-openai

wKgaoWcy1ZqAczN2AAUdifcOBoY436.png ? 在瀏覽互聯(lián)網(wǎng)尋找靈感時(shí),我發(fā)現(xiàn)了一個(gè)看起來很有趣的組件:

https://reactive.network/hackathon

我覺得帶有運(yùn)行 ASCII 藝術(shù)的區(qū)塊看起來很酷,但我不太明白它是如何實(shí)現(xiàn)的,于是我開始查看源代碼。

我找到了看起來可以完成這項(xiàng)工作的代碼,但它被精簡(jiǎn)化了。

const { floor: ra, abs: KE, min: QE } = Math,    O5 = ["reactive.network REACTIVE.NETWORK", "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,^`'. .:a–‘a(chǎn)–’a–“a–?"],    G7 = Date.now() % 3 ? O5[1] : O5[0],    V5 = G7.length,    JE = { fps: 60 };function eT(e, t, n, r) {    const i = t.time * 8e-5,        s = QE(t.cols, t.rows),        o = t.metrics.aspect * 0.2,        l = { x: ((4 * (e.x - t.cols / 6.25)) / s) * o, y: (5 * (e.y - t.rows / 4)) / s },        u = ra(KE(YE(l) - i) * V5 + (ra(e.x / 1) % 2) * 2) % V5;    return G7[u];}const tT = () => {    const e = j.useRef(null),        [t, n] = j.useState({ height: null, width: null });    return (        j.useEffect(() => {            function r() {                n({ height: window.innerHeight, width: window.innerWidth });            }            if (typeof window < "u") return n({ height: window.innerHeight, width: window.innerWidth }), window.addEventListener("resize", r), () => window.removeEventListener("resize", r);        }, []),        j.useEffect(() => {            const r = e.current;            if (!r) return;            const i = 12,                s = ra(t.width / i) * 1.6,                o = ra(t.height / i),                l = { aspect: s / o },                u = setInterval(() => {                    let c = "";                    for (let d = 0; d < o; d++) {                        for (let f = 0; f < s; f++) c += eT({ x: f, y: d }, { cols: s, rows: o, metrics: l, time: Date.now() });                        c += ``;                    }                    r.textContent = c;                }, 1e3 / JE.fps);            return () => clearInterval(u);        }, [t]),        a.jsx("div", { style: { position: "absolute", top: 0, left: 0, width: "100%", height: "100%" }, children: a.jsx("div", { ref: e, style: { width: "100%", height: "100%", whiteSpace: "pre", overflow: "hidden" } }) })    );};function nT(e) {    return Math.cos(e.x * e.x - e.y * e.y);}const { floor: ia, abs: rT, min: iT } = Math,    D5 = ["reactive.network REACTIVE.NETWORK", "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,^`'. .:a–‘a(chǎn)–’a–“a–?"],    X7 = Date.now() % 3 ? D5[1] : D5[0],    F5 = X7.length,    sT = { fps: 60 };function oT(e, t, n, r) {    const i = t.time * 8e-5,        s = iT(t.cols, t.rows),        o = t.metrics.aspect * 0.2,        l = { x: ((4 * (e.x - t.cols / 6.25)) / s) * o, y: (5 * (e.y - t.rows / 4)) / s },        u = ia(rT(nT(l) - i) * F5 + (ia(e.x / 1) % 2) * 2) % F5;    return X7[u];}const aT = () => {    const e = j.useRef(null),        [t, n] = j.useState({ height: null, width: null });    return (        j.useEffect(() => {            function r() {                n({ height: window.innerHeight, width: window.innerWidth });            }            if (typeof window < "u") return n({ height: window.innerHeight, width: window.innerWidth }), window.addEventListener("resize", r), () => window.removeEventListener("resize", r);        }, []),        j.useEffect(() => {            const r = e.current;            if (!r) return;            const i = 12,                s = ia(t.width / i) * 1.6,                o = ia(t.height / i),                l = { aspect: s / o },                u = setInterval(() => {                    let c = "";                    for (let d = 0; d < o; d++) {                        for (let f = 0; f < s; f++) c += oT({ x: f, y: d }, { cols: s, rows: o, metrics: l, time: Date.now() });                        c += ``;                    }                    r.textContent = c;                }, 1e3 / sT.fps);            return () => clearInterval(u);        }, [t]),        a.jsx("div", { style: { position: "absolute", top: 0, left: 0, width: "100%", height: "100%" }, children: a.jsx("div", { ref: e, style: { width: "100%", height: "100%", whiteSpace: "pre", overflow: "hidden" } }) })    );},
通常情況下,我會(huì)通過閱讀最小化的代碼來理解其實(shí)現(xiàn)(或者查找 .map 文件來還原原始代碼)。不過,我意識(shí)到我從未嘗試過讓 ChatGPT 幫我做這件事...... 于是,我復(fù)制了上述所有代碼,并要求 ChatGPT “解釋代碼”。以下是回復(fù):

提供的代碼非常復(fù)雜,但我會(huì)將其分解為更易于理解的格式,解釋其不同部分及其功能。
概述該代碼使用 JavaScript 定義了幾個(gè)函數(shù)和組件,特別是在 React 應(yīng)用程序的上下文中。它處理使用預(yù)定義字符集中的字符生成一些動(dòng)態(tài)文本內(nèi)容,可能是 ASCII 藝術(shù)或某種視覺效果。此外,它還包括用于事件處理、性能計(jì)時(shí)和 HTML 內(nèi)容轉(zhuǎn)換的實(shí)用函數(shù)。
關(guān)鍵部件和功能字符集選擇:
const { floor: ra, abs: KE, min: QE } = Math;const O5 = ["reactive.network REACTIVE.NETWORK", "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,^`'. .:a–‘a(chǎn)–’a–“a–?"];const G7 = Date.now() % 3 ? O5[1] : O5[0];const V5 = G7.length;這部分代碼導(dǎo)入了一些常見的數(shù)學(xué)函數(shù)(floor、、abs和min),并定義了兩組字符,存儲(chǔ)在中O5。
根據(jù)當(dāng)前時(shí)間(Date.now() % 3),它會(huì)選擇其中一個(gè)集合(G7)以供稍后使用。
所選字符集的長(zhǎng)度存儲(chǔ)在中V5。
動(dòng)態(tài)角色選擇功能:
function eT(e, t, n, r) {    const i = t.time * 8e-5;    const s = QE(t.cols, t.rows);    const o = t.metrics.aspect * 0.2;    const l = { x: ((4 * (e.x - t.cols / 6.25)) / s) * o, y: (5 * (e.y - t.rows / 4)) / s };    const u = ra(KE(YE(l) - i) * V5 + (ra(e.x / 1) % 2) * 2) % V5;    return G7[u];}該eT函數(shù)根據(jù)輸入位置(e.x,e.y)和當(dāng)前時(shí)間(t.time)生成一個(gè)字符。
它使用一些縱橫比計(jì)算來調(diào)整位置,并根據(jù)G7位置和時(shí)間的組合選擇一個(gè)字符。
YE從代碼中無法直接看出該函數(shù)的用途,但它似乎是此計(jì)算中使用的自定義函數(shù)。
tT用于顯示動(dòng)態(tài)內(nèi)容的React 組件( ):
const tT = () => {    const e = j.useRef(null);    const [t, n] = j.useState({ height: null, width: null });    j.useEffect(() => {        function r() {            n({ height: window.innerHeight, width: window.innerWidth });        }        if (typeof window < "u") {            n({ height: window.innerHeight, width: window.innerWidth });            window.addEventListener("resize", r);            return () => window.removeEventListener("resize", r);        }    }, []);
    j.useEffect(() => {        const r = e.current;        if (!r) return;        const i = 12;        const s = ra(t.width / i) * 1.6;        const o = ra(t.height / i);        const l = { aspect: s / o };        const u = setInterval(() => {            let c = "";            for (let d = 0; d < o; d++) {                for (let f = 0; f < s; f++) c += eT({ x: f, y: d }, { cols: s, rows: o, metrics: l, time: Date.now() });                c += ``;            }            r.textContent = c;        }, 1e3 / JE.fps);        return () => clearInterval(u);    }, [t]);
    return a.jsx("div", { style: { position: "absolute", top: 0, left: 0, width: "100%", height: "100%" }, children: a.jsx("div", { ref: e, style: { width: "100%", height: "100%", whiteSpace: "pre", overflow: "hidden" } }) });};這是一個(gè) React 組件,它設(shè)置一個(gè)間隔,以使用動(dòng)態(tài)生成的字符定期更新div元素的內(nèi)容( )。e.current
它根據(jù)窗口大小計(jì)算列數(shù)(s)和行數(shù)( ),然后用函數(shù)生成的字符填充。odiveT
該效果以每秒指定的幀數(shù)運(yùn)行(JE.fps)。
我繼續(xù)詢問“用 TypeScript 實(shí)現(xiàn)等效代碼并使其易于閱讀”,并得到了以下答復(fù):

import React, { useEffect, useRef, useState } from 'react';
const selectedCharacterSet =  "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,^`'. .:a–‘a(chǎn)–’a–“a–?";const characterSetLength = selectedCharacterSet.length;
const calculateCharacter = (  x: number,  y: number,  cols: number,  rows: number,  aspect: number,  time: number,): string => {  const timeFactor = time * 0.000_08;  const size = Math.min(cols, rows);  const aspectRatio = aspect * 0.2;  const position = {    x: ((4 * (x - cols / 6.25)) / size) * aspectRatio,    y: (5 * (y - rows / 4)) / size,  };
  const index =    Math.floor(      Math.abs(        Math.cos(position.x * position.x - position.y * position.y) -          timeFactor,      ) *        characterSetLength +        (Math.floor(x) % 2) * 2,    ) % characterSetLength;  return selectedCharacterSet[index];};
type Size = {  height: null | number;  width: null | number;};
const AsciiArtGenerator: React.FC = () => {  const textRef = useRef(null);  const [size, setSize] = useState({ height: null, width: null });
  useEffect(() => {    const handleResize = () => {      setSize({ height: window.innerHeight, width: window.innerWidth });    };
    // Initial size setting    handleResize();
    window.addEventListener('resize', handleResize);    return () => {      window.removeEventListener('resize', handleResize);    };  }, []);
  useEffect(() => {    const element = textRef.current;    if (!element || !size.width || !size.height) return undefined;
    const cols = Math.floor(size.width / 12) * 1.6;    const rows = Math.floor(size.height / 12);    const aspectRatio = cols / rows;
    const intervalId = setInterval(() => {      let content = '';
      for (let y = 0; y < rows; y++) {        for (let x = 0; x < cols; x++) {          content += calculateCharacter(            x,            y,            cols,            rows,            aspectRatio,            Date.now(),          );        }
        content += 'n';      }
      element.textContent = content;    }, 1_000 / 60); // 60 fps
    return () => {      clearInterval(intervalId);    };  }, [size]);
  return (    
);}; export default () => { return ;};
令我驚訝的是,響應(yīng)不僅足夠好,而且可讀性也很強(qiáng)。

上述組件的實(shí)際運(yùn)行情況如下:

比較輸出結(jié)果,LLM 響應(yīng)似乎忽略了一些實(shí)現(xiàn)細(xì)節(jié),但它仍然是一個(gè)值得學(xué)習(xí)的好實(shí)現(xiàn)。這絕對(duì)是一個(gè)我以前從未考慮過的巧妙用例!

注意:如果想第一時(shí)間收到 KiCad 內(nèi)容推送,請(qǐng)點(diǎn)擊下方的名片,按關(guān)注,再設(shè)為星標(biāo)。

常用合集匯總:

和 Dr Peter 一起學(xué) KiCad

KiCad 8 探秘合集

KiCad 使用經(jīng)驗(yàn)分享

KiCad 設(shè)計(jì)項(xiàng)目(Made with KiCad)

常見問題與解決方法

KiCad 開發(fā)筆記

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 代碼
    +關(guān)注

    關(guān)注

    30

    文章

    4880

    瀏覽量

    69995
  • OpenAI
    +關(guān)注

    關(guān)注

    9

    文章

    1196

    瀏覽量

    8296
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    OpenAI O3與DeepSeek R1:推理模型性能深度分析

    ,OpenAI的O3在編碼任務(wù)方面超過了DeepSeek的R1,而R1在數(shù)學(xué)和推理方面表現(xiàn)出了競(jìng)爭(zhēng)力,同時(shí)成本效益和開源可訪問性
    的頭像 發(fā)表于 02-18 11:07 ?596次閱讀

    OpenAI:DeepSeek與Kimi揭秘o1,長(zhǎng)思維鏈提升模型表現(xiàn)

    近日,據(jù)月之暗面報(bào)道,OpenAI發(fā)布了一項(xiàng)令人矚目的研究報(bào)告。報(bào)告指出,DeepSeek和Kimi兩個(gè)研究團(tuán)隊(duì)通過獨(dú)立研究,成功利用思維鏈學(xué)習(xí)方法,在數(shù)學(xué)解題與編程挑戰(zhàn)中顯著提升了模型的綜合表現(xiàn)
    的頭像 發(fā)表于 02-18 09:35 ?342次閱讀

    OpenAI宣布GPT 4o升智計(jì)劃

    透露,GPT 4o的智力水平將得到顯著提升,目標(biāo)直指o3 pro的水平。這一升級(jí)不僅意味著GPT 4o在理解和生成文本方面的能力將得到質(zhì)的飛躍,更將使其處理復(fù)雜問題、進(jìn)行邏輯推理等方面的表現(xiàn)
    的頭像 發(fā)表于 02-17 14:24 ?460次閱讀

    今年,還要搶GPU?

    能指標(biāo)上與世界頂級(jí)大模型,如Meta的Llama3.1、OpenAI的GPT-4、Anthropic的ClaudeSonnet3.5等,不分伯仲。最令人震驚的是,Dee
    的頭像 發(fā)表于 02-14 10:04 ?307次閱讀
    今年,還要搶GPU?

    3D打印技術(shù)材料、工藝方面的突破

    弧并行打印、大尺寸陶瓷打印等;材料方面,可重復(fù)使用光固化樹脂以及可直接打印透明牙套的材料都是不得忽視的重要突破;應(yīng)用方面,用戶經(jīng)過幾年的積累開始更大膽的使用這項(xiàng)技術(shù),制藥、發(fā)動(dòng)機(jī)技術(shù)等方面
    的頭像 發(fā)表于 01-13 18:11 ?726次閱讀
    3D打印技術(shù)<b class='flag-5'>在</b>材料、工藝<b class='flag-5'>方面的</b>突破

    UPS電源與EPS電源功能和應(yīng)用方面的區(qū)別

    電子發(fā)燒友網(wǎng)站提供《UPS電源與EPS電源功能和應(yīng)用方面的區(qū)別.pdf》資料免費(fèi)下載
    發(fā)表于 10-31 10:17 ?7次下載

    微軟與OpenAI展開140億美元投資股權(quán)談判

    作為OpenAI的最大股東,其公司治理和發(fā)展方面的實(shí)際控制權(quán)也成為此次談判的重點(diǎn)。微軟希望能夠OpenAI的戰(zhàn)略規(guī)劃、產(chǎn)品研發(fā)以及市場(chǎng)拓
    的頭像 發(fā)表于 10-23 11:36 ?561次閱讀

    光通信技術(shù)醫(yī)療健康方面的應(yīng)用

    光通信技術(shù)醫(yī)療健康方面的應(yīng)用是一個(gè)日益受到關(guān)注且快速發(fā)展的領(lǐng)域。隨著科技的進(jìn)步,光通信技術(shù)以其高速、大容量、低損耗、抗干擾等優(yōu)勢(shì),醫(yī)療設(shè)備的研發(fā)、診斷、治療及健康管理等方面展現(xiàn)出了
    的頭像 發(fā)表于 08-09 16:19 ?1653次閱讀

    小米印度市場(chǎng)遭遇重創(chuàng):利潤(rùn)暴跌77%,收入下降32%

    近年來,中國(guó)智能設(shè)備制造商小米科技印度市場(chǎng)的表現(xiàn)一直備受關(guān)注。然而,最新的監(jiān)管文件揭示了一個(gè)令人震驚的事實(shí):小米2022-2023財(cái)年的印度利潤(rùn)同比暴跌了驚人的77%,從上一財(cái)年的
    的頭像 發(fā)表于 07-16 16:55 ?1514次閱讀

    大數(shù)據(jù)軍事方面的應(yīng)用

    智慧華盛恒輝大數(shù)據(jù)軍事方面的應(yīng)用廣泛且深入,涵蓋了戰(zhàn)爭(zhēng)決策、情報(bào)分析、裝備研發(fā)、后勤保障、科研方法、管理水平、作戰(zhàn)能力和信息化建設(shè)等多個(gè)方面。以下是對(duì)這些應(yīng)用的詳細(xì)歸納: 智慧華盛恒輝一、戰(zhàn)爭(zhēng)決策
    的頭像 發(fā)表于 07-16 09:44 ?1521次閱讀

    大數(shù)據(jù)軍事方面的應(yīng)用有哪些

    智慧華盛恒輝大數(shù)據(jù)軍事方面的應(yīng)用涵蓋了多個(gè)方面,這些應(yīng)用不僅提高了軍事管理的效率和水平,也極大地提升了軍隊(duì)的作戰(zhàn)能力和情報(bào)獲取能力。以下是大數(shù)據(jù)軍事
    的頭像 發(fā)表于 06-23 10:34 ?1544次閱讀

    OpenAI推出ChatGPT Edu,助力教育及學(xué)術(shù)領(lǐng)域AI應(yīng)用普及

    OpenAI近日宣布推出全新服務(wù)——ChatGPT Edu,旨在推動(dòng)教育機(jī)構(gòu)與學(xué)術(shù)單位在人工智能領(lǐng)域的深入應(yīng)用與發(fā)展。此舉不僅彰顯了OpenAI普及AI技術(shù)方面的決心,也為廣大師生及
    的頭像 發(fā)表于 06-04 09:17 ?694次閱讀

    OpenAI聯(lián)合創(chuàng)始人Llya Sutskever離任,研發(fā)總監(jiān)Jakub Pachock接任

    他贊揚(yáng)OpenAI近十年的驚人發(fā)展和Sam Altman等領(lǐng)導(dǎo)者的出色表現(xiàn),并堅(jiān)信他們能夠建立起安全且有益的人工智能系統(tǒng)(AGI)。
    的頭像 發(fā)表于 05-15 17:02 ?776次閱讀

    基于555定時(shí)器的機(jī)器聲音發(fā)生器的電路

    已經(jīng)開發(fā)了無數(shù)項(xiàng)目,產(chǎn)生了各種令人震驚的影響。我們更喜歡不同的地方有不同的聲音效果。例如,基于安全的項(xiàng)目中,尖銳和令人震驚的聲音被認(rèn)為是最佳選擇,而在門鈴中,柔和的聲音會(huì)讓耳朵感到
    的頭像 發(fā)表于 05-05 09:59 ?841次閱讀
    基于555定時(shí)器的機(jī)器聲音發(fā)生器的電路