91欧美超碰AV自拍|国产成年人性爱视频免费看|亚洲 日韩 欧美一厂二区入|人人看人人爽人人操aV|丝袜美腿视频一区二区在线看|人人操人人爽人人爱|婷婷五月天超碰|97色色欧美亚州A√|另类A√无码精品一级av|欧美特级日韩特级

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

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

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

OpenAI 在精簡代碼方面的出色表現(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)尋找靈感時,我發(fā)現(xiàn)了一個看起來很有趣的組件:

https://reactive.network/hackathon

我覺得帶有運行 ASCII 藝術(shù)的區(qū)塊看起來很酷,但我不太明白它是如何實現(xià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" } }) })    );},
通常情況下,我會通過閱讀最小化的代碼來理解其實現(xiàn)(或者查找 .map 文件來還原原始代碼)。不過,我意識到我從未嘗試過讓 ChatGPT 幫我做這件事...... 于是,我復(fù)制了上述所有代碼,并要求 ChatGPT “解釋代碼”。以下是回復(fù):

提供的代碼非常復(fù)雜,但我會將其分解為更易于理解的格式,解釋其不同部分及其功能。
概述該代碼使用 JavaScript 定義了幾個函數(shù)和組件,特別是在 React 應(yīng)用程序的上下文中。它處理使用預(yù)定義字符集中的字符生成一些動態(tài)文本內(nèi)容,可能是 ASCII 藝術(shù)或某種視覺效果。此外,它還包括用于事件處理、性能計時和 HTML 內(nèi)容轉(zhuǎn)換的實用函數(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),并定義了兩組字符,存儲在中O5。
根據(jù)當(dāng)前時間(Date.now() % 3),它會選擇其中一個集合(G7)以供稍后使用。
所選字符集的長度存儲在中V5。
動態(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)前時間(t.time)生成一個字符。
它使用一些縱橫比計算來調(diào)整位置,并根據(jù)G7位置和時間的組合選擇一個字符。
YE從代碼中無法直接看出該函數(shù)的用途,但它似乎是此計算中使用的自定義函數(shù)。
tT用于顯示動態(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" } }) });};這是一個 React 組件,它設(shè)置一個間隔,以使用動態(tài)生成的字符定期更新div元素的內(nèi)容( )。e.current
它根據(jù)窗口大小計算列數(shù)(s)和行數(shù)( ),然后用函數(shù)生成的字符填充。odiveT
該效果以每秒指定的幀數(shù)運行(JE.fps)。
我繼續(xù)詢問“用 TypeScript 實現(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)不僅足夠好,而且可讀性也很強。

上述組件的實際運行情況如下:

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

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

常用合集匯總:

和 Dr Peter 一起學(xué) KiCad

KiCad 8 探秘合集

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

KiCad 設(shè)計項目(Made with KiCad)

常見問題與解決方法

KiCad 開發(fā)筆記

審核編輯 黃宇

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

    關(guān)注

    30

    文章

    4971

    瀏覽量

    74074
  • OpenAI
    +關(guān)注

    關(guān)注

    9

    文章

    1245

    瀏覽量

    10158
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

    C語言中一些令人震驚的結(jié)構(gòu)介紹

    C語言同意一些令人震驚的結(jié)構(gòu),下面的結(jié)構(gòu)是合法的嗎,如果是它做些什么? int a = 5, b = 7, c; c = a+++b; 考察點: 這個問題將作為這個測驗的一個愉快的結(jié)尾
    發(fā)表于 12-23 08:15

    GPT-5.1發(fā)布 OpenAI開始拼情商

    Thinking:高級推理模型,簡單任務(wù)上更快,復(fù)雜任務(wù)上更持久,也更容易理解。 對于新上線的GPT-5.1大模型,OpenAI?官方表示出色的 AI 不僅是要夠聰明,還要讓人與
    的頭像 發(fā)表于 11-13 15:49 ?728次閱讀

    CW32L010F8P600的優(yōu)勢

    的場景,易于升級迭代,減少對EEPROM的依賴,耐用性更高。 代碼安全防護:代碼安全防護方面達到黑客級別。保護用戶
    發(fā)表于 11-13 07:07

    內(nèi)存價格漲幅超過黃金! 怎么搞的?

    近期內(nèi)存市場的漲勢令人震驚。行業(yè)分析報告顯示,2025年第三季度DRAM合約價格同比上漲高達171.8%,這一數(shù)字甚至超過了同期黃金的漲幅。有業(yè)內(nèi)觀察人士指出,2025年第四季度將標志著 “DRAM牛市” 的真正開始。市場普遍預(yù)期,2026年可能會出現(xiàn)更嚴重的DRAM供應(yīng)短缺。
    的頭像 發(fā)表于 11-06 16:46 ?3277次閱讀
    內(nèi)存價格漲幅超過黃金! 怎么搞的?

    NVIDIA攜手OpenAI構(gòu)建AI基礎(chǔ)設(shè)施

    NVIDIA 首席執(zhí)行官黃仁勛、OpenAI 首席執(zhí)行官 Sam Altman 和 OpenAI 總裁 Greg Brockman 宣布了一項新的合作伙伴關(guān)系,旨在推動 OpenAI 的發(fā)展,并支持幾乎所有行業(yè)和用戶大規(guī)模使用
    的頭像 發(fā)表于 09-23 14:38 ?973次閱讀

    了解SOLIDWORKS202仿真方面的改進

    和效率,從而幫助設(shè)計師更好地應(yīng)對復(fù)雜的設(shè)計挑戰(zhàn)。本文將深入探討SOLIDWORKS 2025仿真方面的改進,揭示這些改進如何助力設(shè)計師實現(xiàn)更有效、更準確的仿真分析。
    的頭像 發(fā)表于 09-04 10:36 ?718次閱讀
    了解SOLIDWORKS202仿真<b class='flag-5'>方面的</b>改進

    OpenAI或在周五凌晨發(fā)布GPT-5 OpenAI以低價向美國政府提供ChatGPT

    外界一直期待的OpenAI新一代大語言模型GPT-5或?qū)l(fā)布。據(jù)外媒的報道,GPT-5很可能在周五凌晨發(fā)布。這是OpenAI2023年的3月份推出自然語言處理模型GPT-4之后,兩
    的頭像 發(fā)表于 08-07 14:13 ?1.3w次閱讀

    國產(chǎn)主板耐用性和可靠性上有哪些具體表現(xiàn)

    國產(chǎn)主板耐用性和可靠性上有著諸多令人矚目的具體表現(xiàn)不同領(lǐng)域發(fā)揮著關(guān)鍵作用。
    的頭像 發(fā)表于 07-22 18:21 ?1085次閱讀

    解析SMA接口電磁兼容性方面的卓越表現(xiàn)

    德索精密工業(yè)通過材料選用、工藝處理以及結(jié)構(gòu)和內(nèi)導(dǎo)體設(shè)計等多方面的不懈努力,使得其生產(chǎn)的SMA接口電磁兼容性方面表現(xiàn)卓越,
    的頭像 發(fā)表于 05-20 08:48 ?747次閱讀
    解析SMA接口<b class='flag-5'>在</b>電磁兼容性<b class='flag-5'>方面的</b>卓越<b class='flag-5'>表現(xiàn)</b>

    距離Robotaxi上線僅剩數(shù)周,特斯拉尚未開始無安全員測試引發(fā)質(zhì)疑

    令人震驚的是,截至上個月,特斯拉尚未開始進行無安全員的道路測試。
    的頭像 發(fā)表于 05-15 17:58 ?599次閱讀

    解析 SMA 接口電磁兼容性方面的卓越表現(xiàn)

    德索精密工業(yè)通過材料選用、工藝處理以及結(jié)構(gòu)和內(nèi)導(dǎo)體設(shè)計等多方面的不懈努力,使得其生產(chǎn)的SMA接口電磁兼容性方面表現(xiàn)卓越,
    的頭像 發(fā)表于 05-14 09:12 ?695次閱讀
    解析 SMA 接口<b class='flag-5'>在</b>電磁兼容性<b class='flag-5'>方面的</b>卓越<b class='flag-5'>表現(xiàn)</b>

    如何獲取 OpenAI API Key?API 獲取與代碼調(diào)用示例 (詳解教程)

    OpenAI API Key 獲取與使用詳解:從入門到精通 OpenAI 正以其 GPT 和 DALL-E 等先進模型引領(lǐng)全球人工智能創(chuàng)新。其 API 為開發(fā)者和企業(yè)提供了強大的 AI 能力集成途徑
    的頭像 發(fā)表于 05-04 11:42 ?1.6w次閱讀
    如何獲取 <b class='flag-5'>OpenAI</b> API Key?API 獲取與<b class='flag-5'>代碼</b>調(diào)用示例 (詳解教程)

    SOLIDWORKS教育版——全方面的學(xué)習(xí)資源與教程

    功能,更以其全方面的學(xué)習(xí)資源與教程,為學(xué)生構(gòu)建了一個從理論到實踐、從基礎(chǔ)到進階的完整學(xué)習(xí)體系。本文將深入探討SOLIDWORKS教育版如何憑借其豐富的學(xué)習(xí)資源與教程,為工程教育注入新的活力,助力學(xué)生成長為未來的工程精英。
    的頭像 發(fā)表于 04-23 11:03 ?910次閱讀
    SOLIDWORKS教育版——全<b class='flag-5'>方面的</b>學(xué)習(xí)資源與教程

    有單片機方面的大佬嗎?有幾個單片機方面的問題需要請教一下

    如題,有單片機方面的內(nèi)容需要請教一下 (先疊個甲)純小白 我需要一個單片機控制模塊,我現(xiàn)在的想法是:一個單片機上,我要讓他控制一個傳感器和一個步進電機(運動系統(tǒng),運動距離為13.5cm),同時
    發(fā)表于 03-29 18:35