{"id":2429,"date":"2026-11-10T15:51:08","date_gmt":"2026-11-10T07:51:08","guid":{"rendered":"https:\/\/shr1mp.top\/?p=2429"},"modified":"2026-11-10T16:01:12","modified_gmt":"2026-11-10T08:01:12","slug":"2026scssmisc","status":"publish","type":"post","link":"https:\/\/shr1mp.top\/index.php\/2026\/11\/10\/2026scssmisc\/","title":{"rendered":"2026\u56db\u5ddd\u7701\u8d5bMisc"},"content":{"rendered":"\n<h2 id=\"\u6b8b\u54cd\" class=\"wp-block-heading has-large-font-size\">\u6b8b\u54cd<\/h2>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">\u9996\u5148PT\u6587\u4ef6\u662fpytorch\u5c01\u88c5\u540e\u7684\u6587\u4ef6\uff0c\u662f\u4e00\u4e2a\u8bad\u7ec3\u7684\u6a21\u578b\uff0c\u8fd9\u9053\u9898\u91cc\u9762\u770b\u5230\u4ed6\u7684\u6587\u4ef6\u5934\u662fzip\u5f00\u5934\uff0c\u800c\u4e14\u6709code\/\uff0c\u6240\u4ee5\u8fd9\u662ftorchScript\u7684\u5f52\u6863\uff08\u5f53\u7136\uff0c\u5728readme\u91cc\u9762\u4e5f\u6709\u63d0\u8fc7\uff09<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Readme\u91cc\u9762\u5199\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torch\n\nmodel = torch.jit.load(\"uuid-sim-v1.pt\")\nmodel.eval()\n\nx = torch.tensor(&#91;&#91;ids_of_36_chars]], dtype=torch.long)   # &#91;B, 36]\nscore, logits = model(x)                                   # &#91;B], &#91;B, 36]<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">\u63a5\u53e3<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u9879\u76ee<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>\u8f93\u5165<\/td><td><code>int64<\/code> \u5f20\u91cf\uff0c\u5f62\u72b6 <code>[B, 36]<\/code>\uff0c\u5143\u7d20\u662f\u4e0b\u9762\u8bcd\u8868\u91cc\u7684\u4e0b\u6807<\/td><\/tr><tr><td>\u8f93\u51fa 1<\/td><td><code>[B]<\/code> float\uff0c\u8fd9\u6bb5\u7a97\u53e3\u4e0e\u767b\u8bb0\u6807\u8bc6\u7684\u76f8\u4f3c\u5ea6\uff080~1\uff09<\/td><\/tr><tr><td>\u8f93\u51fa 2<\/td><td><code>[B, 36]<\/code> float\uff0c\u6a21\u578b\u5185\u90e8\u805a\u5408\u76f8\u4f3c\u5ea6\u65f6\u7528\u5230\u7684\u9010\u4f4d\u6253\u5206<\/td><\/tr><tr><td>\u7a97\u53e3<\/td><td>36 \u5b57\u7b26\uff1b\u6587\u672c\u66f4\u957f\u65f6\u6309\u6b65\u957f 1 \u6ed1\u7a97\uff0c\u9010\u7a97\u6253\u5206\u540e\u53d6\u6700\u9ad8\u5206<\/td><\/tr><tr><td>\u4e0d\u8db3 36<\/td><td>\u53f3\u4fa7\u8865\u4e0b\u6807 <code>0<\/code>\uff08<code>&lt;pad&gt;<\/code>\uff09<\/td><\/tr><tr><td>\u5927\u5c0f\u5199<\/td><td>\u8bcd\u8868\u53ea\u6709\u5c0f\u5199\uff0c\u8bf7\u5148 <code>text.lower()<\/code><\/td><\/tr><tr><td>\u957f\u5ea6<\/td><td>\u4e0e UUID \u89c4\u8303\u5f62\u5f0f\u4e00\u81f4\uff1a<code>8-4-4-4-12<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u4e0b\u6807<\/th><th>\u5b57\u7b26<\/th><th>\u4e0b\u6807<\/th><th>\u5b57\u7b26<\/th><th>\u4e0b\u6807<\/th><th>\u5b57\u7b26<\/th><\/tr><\/thead><tbody><tr><td>0<\/td><td><code>&lt;pad&gt;<\/code><\/td><td>13<\/td><td><code>c<\/code><\/td><td>26<\/td><td><code>o<\/code><\/td><\/tr><tr><td>1<\/td><td><code>0<\/code><\/td><td>14<\/td><td><code>d<\/code><\/td><td>27<\/td><td><code>p<\/code><\/td><\/tr><tr><td>2<\/td><td><code>1<\/code><\/td><td>15<\/td><td><code>e<\/code><\/td><td>28<\/td><td><code>q<\/code><\/td><\/tr><tr><td>3<\/td><td><code>2<\/code><\/td><td>16<\/td><td><code>f<\/code><\/td><td>29<\/td><td><code>r<\/code><\/td><\/tr><tr><td>4<\/td><td><code>3<\/code><\/td><td>17<\/td><td><code>-<\/code><\/td><td>30<\/td><td><code>s<\/code><\/td><\/tr><tr><td>5<\/td><td><code>4<\/code><\/td><td>18<\/td><td><code>g<\/code><\/td><td>31<\/td><td><code>t<\/code><\/td><\/tr><tr><td>6<\/td><td><code>5<\/code><\/td><td>19<\/td><td><code>h<\/code><\/td><td>32<\/td><td><code>u<\/code><\/td><\/tr><tr><td>7<\/td><td><code>6<\/code><\/td><td>20<\/td><td><code>i<\/code><\/td><td>33<\/td><td><code>v<\/code><\/td><\/tr><tr><td>8<\/td><td><code>7<\/code><\/td><td>21<\/td><td><code>j<\/code><\/td><td>34<\/td><td><code>w<\/code><\/td><\/tr><tr><td>9<\/td><td><code>8<\/code><\/td><td>22<\/td><td><code>k<\/code><\/td><td>35<\/td><td><code>x<\/code><\/td><\/tr><tr><td>10<\/td><td><code>9<\/code><\/td><td>23<\/td><td><code>l<\/code><\/td><td>36<\/td><td><code>y<\/code><\/td><\/tr><tr><td>11<\/td><td><code>a<\/code><\/td><td>24<\/td><td><code>m<\/code><\/td><td>37<\/td><td><code>z<\/code><\/td><\/tr><tr><td>12<\/td><td><code>b<\/code><\/td><td>25<\/td><td><code>n<\/code><\/td><td>38<\/td><td><code>&lt;unk&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">\u5148\u57fa\u672c\u6d4b\u8bd5\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># -*- coding: utf-8 -*-\nimport torch\n\nmodel = torch.jit.load(\"uuid-sim-v1.pt\")\nmodel.eval()\n\n# \u8bcd\u8868\uff1a\u628a\u5b57\u7b26\u7ffb\u8bd1\u6210\u7f16\u53f7\uff08\u5bf9\u5e94 README \u91cc\u90a3\u5f20\u8868\uff09\nCHARS = \"0123456789abcdef-ghijklmnopqrstuvwxyz\"\nSTOI = {c: i + 1 for i, c in enumerate(CHARS)}\n\n\ndef to_ids(s):\n    # \u6bcf\u4e2a\u5b57\u7b26\u67e5\u8868\u6362\u6210\u7f16\u53f7\uff1b\u8868\u91cc\u6ca1\u6709\u7684\u5b57\u7b26\u7528 38\uff08&lt;unk&gt;\uff09\n    return &#91;STOI.get(c, 38) for c in s.lower()]\n\n\n# \u5fc5\u987b\u662f 36 \u4f4d\uff088-4-4-4-12\uff0c4 \u4e2a\u6a2a\u6760\uff09\ntext = \"01234567-89ab-cdef-0123-456789abcdef\"\nids = to_ids(text)\nprint(\"36 \u4e2a\u7f16\u53f7:\", ids)\n\n# &#91;ids] = \u628a 36 \u4e2a\u6570\u5b57\u5305\u6210\"1 \u884c\" -&gt; \u5f62\u72b6 &#91;1, 36]\nx = torch.tensor(&#91;ids], dtype=torch.long)\n\nwith torch.no_grad():\n    score, logits = model(x)\n\nprint(\"\u603b\u5206 score:\", float(score&#91;0]))\nprint(\"\u9010\u4f4d logits:\", logits&#91;0].numpy().round(1))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;python 1.py\n36 \u4e2a\u7f16\u53f7: &#91;1, 2, 3, 4, 5, 6, 7, 8, 17, 9, 10, 11, 12, 17, 13, 14, 15, 16, 17, 1, 2, 3, 4, 17, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]\n\u603b\u5206 score: 0.1944531798362732\n\u9010\u4f4d logits: &#91;-11.2 -11.2 -11.2 -11.2 -11.2 -11.2 -11.2 -11.2  11.5  11.5 -11.2 -11.2\n -11.2  11.5 -11.2 -11.2 -11.2 -11.2  11.5 -11.2 -11.2  11.5 -11.2  11.5\n -11.2 -11.2 -11.2 -11.2 -11.2 -11.2 -11.2 -11.2  11.5 -11.2 -11.2 -11.2]<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">\u8f93\u51fa\u5df2\u7ecf\u8bc1\u660e\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li class=\"has-medium-font-size\">\u6a21\u578b\u4f1a\u9010\u4f4d\u5224\u65ad \u2014\u2014 \u6bcf\u4f4d\u90fd\u6709\u4e00\u4e2a\u660e\u786e\u7684\u6b63\/\u8d1f\u7ed3\u8bba<\/li>\n\n\n\n<li class=\"has-medium-font-size\">\u5bf9\u7684\u5b57\u7b26\u7ed9 +11\uff0c\u9519\u7684\u7ed9 \u221211 \u2014\u2014 \u5dee\u8ddd 22.7\uff0c\u975e\u5e38\u5e72\u51c0<\/li>\n\n\n\n<li class=\"has-medium-font-size\">\u4f4d\u7f6e\u662f\u72ec\u7acb\u7684 \u2014\u2014 \u7b2c 9 \u4f4d\u5bf9\u9519\u4e0d\u53d7\u5176\u4ed6\u4f4d\u5f71\u54cd\uff08\u5176\u4ed6 35 \u4f4d\u51e0\u4e4e\u4e0d\u52a8\uff09<\/li>\n<\/ol>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">\u4e8e\u662f\u65b9\u6cd5\u5c31\u987a\u7406\u6210\u7ae0\uff1a<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">\u5bf9\u6bcf\u4e00\u4e2a\u4f4d\u7f6e\uff1a<br>\u628a 16 \u4e2a\u5019\u9009\u5b57\u7b26\u5206\u522b\u586b\u8fdb\u53bb\uff0c\u95ee\u6a21\u578b<br>\u54ea\u4e2a\u5019\u9009\u62ff\u5230 +11\uff0c\u54ea\u4e2a\u5c31\u662f\u7b54\u6848<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nimport random\nimport torch\n\nCHARS = \"0123456789abcdef-ghijklmnopqrstuvwxyz\"\nSTOI = {c: i + 1 for i, c in enumerate(CHARS)}\n#\u751f\u6210\u4e00\u4e2a\u5b57\u7b26\u8f6c\u7f16\u7801\u7684\u5b57\u5178\uff0c\u7f16\u53f7 0 \u5df2\u7ecf\u88ab &lt;pad&gt;\uff08\u8865\u4f4d\u7b26\uff09\u5360\u7528\u4e86\u6240\u4ee5i+1\n\ndef to_ids(s):\n    return &#91;STOI.get(c, 38) for c in s]\n\n\nmodel = torch.jit.load(\"uuid-sim-v1.pt\")\nmodel.eval()\n\n\ndef run(strings):\n    \"\"\"\u4e00\u6b21\u628a\u5f88\u591a\u4e32\u9001\u8fdb\u6a21\u578b\uff0c\u8fd4\u56de (\u603b\u5206\u6570\u7ec4, \u9010\u4f4d\u4fe1\u53f7\u6570\u7ec4)\"\"\"\n    rows = &#91;to_ids(s) for s in strings]\n    with torch.no_grad():\n        return model(torch.tensor(rows, dtype=torch.long))\n\n\nALPHA = list(\"0123456789abcdef\")        # \u6bcf\u4e00\u4f4d\u53ea\u53ef\u80fd\u662f 16 \u4e2a\u5341\u516d\u8fdb\u5236\u5b57\u7b26\nFIXED = {8: \"-\", 13: \"-\", 18: \"-\", 23: \"-\"}   # UUID \u683c\u5f0f\u91cc\u56fa\u5b9a\u7684 4 \u4e2a\u6a2a\u6760\n\n\ndef recover(start):\n    cur = list(start)\n    for i, c in FIXED.items():\n        cur&#91;i] = c\n    for rnd in range(10):\n        strings, where = &#91;], &#91;]\n        for i in range(36):\n            if i in FIXED:\n                continue\n            for c in ALPHA:\n                candidate = \"\".join(cur&#91;:i] + &#91;c] + cur&#91;i + 1:])\n                strings.append(candidate)\n                where.append((i, c))\n\n        _, logits = run(strings)\n\n        best = {}\n        for k, (i, c) in enumerate(where):\n            v = float(logits&#91;k, i])      # \u53ea\u770b\"\u7b2c i \u4f4d\"\u81ea\u5df1\u7684\u4fe1\u53f7\n            if i not in best or v &gt; best&#91;i]&#91;0]:\n                best&#91;i] = (v, c)\n\n        changed = 0\n        for i, (v, c) in best.items():\n            if cur&#91;i] != c:\n                cur&#91;i] = c\n                changed += 1\n\n        total = float(run(&#91;\"\".join(cur)])&#91;0]&#91;0])\n        print(f\"  \u7b2c {rnd + 1} \u8f6e\uff1a\u6539\u4e86 {changed:2d} \u4f4d\uff0c\u5f53\u524d\u603b\u5206 {total:.8f}\")\n\n        # \u6536\u655b = \u4e00\u8f6e\u4e0b\u6765\u6ca1\u4efb\u4f55\u53d8\u5316\uff0c\u8bf4\u660e\u6bcf\u4e2a\u8f6c\u76d8\u90fd\u62e8\u5230\u6700\u4f18\u4e86\n        if changed == 0:\n            break\n\n    return \"\".join(cur)\n\n\nprint(\"\u5f00\u59cb\u641c\u7d22\uff08\u521d\u59cb\u4e32\u6bcf\u4e00\u4f4d\u90fd\u586b 0\uff0c\u53ea\u6709 4 \u4e2a\u6a2a\u6760\u662f\u5168\u5bf9\u7684\uff09\")\nanswer = recover(\"0\" * 36)\nprint(\"\\n\u8fd8\u539f\u51fa\u7684\u6807\u8bc6:\", answer)\n\nprint(\"\\n\" + \"=\" * 64)\nprint(\"\u9a8c\u8bc1\")\nprint(\"=\" * 64)\n\nscore, logits = run(&#91;answer])\nprint(\"1) \u6700\u7ec8\u603b\u5206 =\", float(score&#91;0]), \"\uff08\u8d8a\u63a5\u8fd1 1 \u8d8a\u597d\uff09\")\nprint(\"2) 36 \u4f4d\u91cc\u6700\u4f4e\u7684\u4fe1\u53f7 =\", float(logits&#91;0].min()), \"\uff08\u5168\u4e3a\u6b63 = 36 \u4f4d\u5168\u90e8\u547d\u4e2d\uff09\")\nprint(f\"3) \u957f\u5ea6 {len(answer)}\uff0c\u7b2c 15 \u4f4d(\u7248\u672c) {answer&#91;14]}\uff0c\u7b2c 20 \u4f4d(\u53d8\u4f53) {answer&#91;19]}\")\n\nprint(\"4) \u6362\u4e24\u4e2a\u968f\u673a\u521d\u59cb\u4e32\u91cd\u641c\uff0c\u770b\u7ed3\u679c\u662f\u5426\u4e00\u81f4\uff1a\")\nfor seed in (1, 2):\n    random.seed(seed)\n    start = \"\".join(random.choice(ALPHA) for _ in range(36))\n    got = recover(start)\n    print(\"   \u4e00\u81f4:\", got == answer)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;python 03_solve.py\n\u5f00\u59cb\u641c\u7d22\uff08\u521d\u59cb\u4e32\u6bcf\u4e00\u4f4d\u90fd\u586b 0\uff0c\u53ea\u6709 4 \u4e2a\u6a2a\u6760\u662f\u5168\u5bf9\u7684\uff09\n  \u7b2c 1 \u8f6e\uff1a\u6539\u4e86 30 \u4f4d\uff0c\u5f53\u524d\u603b\u5206 0.99998993\n  \u7b2c 2 \u8f6e\uff1a\u6539\u4e86  0 \u4f4d\uff0c\u5f53\u524d\u603b\u5206 0.99998993\n\n\u8fd8\u539f\u51fa\u7684\u6807\u8bc6: 39c11281-8e07-4e87-b226-0dc54855cfb7\n\n================================================================\n\u9a8c\u8bc1\n================================================================\n1) \u6700\u7ec8\u603b\u5206 = 0.999989926815033 \uff08\u8d8a\u63a5\u8fd1 1 \u8d8a\u597d\uff09\n2) 36 \u4f4d\u91cc\u6700\u4f4e\u7684\u4fe1\u53f7 = 11.468128204345703 \uff08\u5168\u4e3a\u6b63 = 36 \u4f4d\u5168\u90e8\u547d\u4e2d\uff09\n3) \u957f\u5ea6 36\uff0c\u7b2c 15 \u4f4d(\u7248\u672c) 4\uff0c\u7b2c 20 \u4f4d(\u53d8\u4f53) b\n4) \u6362\u4e24\u4e2a\u968f\u673a\u521d\u59cb\u4e32\u91cd\u641c\uff0c\u770b\u7ed3\u679c\u662f\u5426\u4e00\u81f4\uff1a\n  \u7b2c 1 \u8f6e\uff1a\u6539\u4e86 28 \u4f4d\uff0c\u5f53\u524d\u603b\u5206 0.99998993\n  \u7b2c 2 \u8f6e\uff1a\u6539\u4e86  0 \u4f4d\uff0c\u5f53\u524d\u603b\u5206 0.99998993\n   \u4e00\u81f4: True\n  \u7b2c 1 \u8f6e\uff1a\u6539\u4e86 30 \u4f4d\uff0c\u5f53\u524d\u603b\u5206 0.99998993\n  \u7b2c 2 \u8f6e\uff1a\u6539\u4e86  0 \u4f4d\uff0c\u5f53\u524d\u603b\u5206 0.99998993\n   \u4e00\u81f4: True<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f97\u5230UUID\uff1a39c11281-8e07-4e87-b226-0dc54855cfb7\uff0c\u8f93\u5165\u7ed9\u5e73\u53f0\u5373\u53ef\u62ff\u5230flag<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6b8b\u54cd \u9996\u5148PT\u6587\u4ef6\u662fpytorch\u5c01\u88c5\u540e\u7684\u6587\u4ef6\uff0c\u662f\u4e00\u4e2a\u8bad\u7ec3\u7684\u6a21\u578b\uff0c\u8fd9\u9053\u9898\u91cc\u9762\u770b\u5230\u4ed6\u7684\u6587\u4ef6\u5934\u662fzip\u5f00\u5934\uff0c\u800c\u4e14\u6709 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2439,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_gspb_post_css":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-2429","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/posts\/2429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/comments?post=2429"}],"version-history":[{"count":13,"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/posts\/2429\/revisions"}],"predecessor-version":[{"id":2443,"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/posts\/2429\/revisions\/2443"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/media\/2439"}],"wp:attachment":[{"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/media?parent=2429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/categories?post=2429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shr1mp.top\/index.php\/wp-json\/wp\/v2\/tags?post=2429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}