{"id":1237,"date":"2022-11-23T13:02:00","date_gmt":"2022-11-23T05:02:00","guid":{"rendered":"https:\/\/fdream.net\/blog\/?p=1237"},"modified":"2022-11-24T10:37:02","modified_gmt":"2022-11-24T02:37:02","slug":"go%e6%8c%87%e5%8d%97%e7%bb%83%e4%b9%a02-%e5%88%87%e7%89%87","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/1237","title":{"rendered":"Go\u6307\u5357\u7ec3\u4e602-\u5207\u7247"},"content":{"rendered":"\n<p>\u8fd9\u4e2a\u662f<a rel=\"noreferrer noopener\" href=\"https:\/\/go.dev\/tour\/list\" target=\"_blank\">A Tour of Go<\/a>\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u7684\u7b2c\u4e8c\u4e2a\u7ec3\u4e60\uff0c<a href=\"https:\/\/tour.go-zh.org\/moretypes\/18\" target=\"_blank\" rel=\"noreferrer noopener\">\u539f\u9898<\/a>\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5b9e\u73b0&nbsp;<code>Pic<\/code>\u3002\u5b83\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;<code>dy<\/code>&nbsp;\u7684\u5207\u7247\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;<code>dx<\/code>\uff0c\u5143\u7d20\u7c7b\u578b\u4e3a&nbsp;<code>uint8<\/code>&nbsp;\u7684\u5207\u7247\u3002\u5f53\u4f60\u8fd0\u884c\u6b64\u7a0b\u5e8f\u65f6\uff0c\u5b83\u4f1a\u5c06\u6bcf\u4e2a\u6574\u6570\u89e3\u91ca\u4e3a\u7070\u5ea6\u503c\uff08\u597d\u5427\uff0c\u5176\u5b9e\u662f\u84dd\u5ea6\u503c\uff09\u5e76\u663e\u793a\u5b83\u6240\u5bf9\u5e94\u7684\u56fe\u50cf\u3002<\/p>\n\n\n\n<p>\u56fe\u50cf\u7684\u9009\u62e9\u7531\u4f60\u6765\u5b9a\u3002\u51e0\u4e2a\u6709\u8da3\u7684\u51fd\u6570\u5305\u62ec&nbsp;<code>(x+y)\/2<\/code>,&nbsp;<code>x*y<\/code>,&nbsp;<code>x^y<\/code>,&nbsp;<code>x*log(y)<\/code>&nbsp;\u548c&nbsp;<code>x%(y+1)<\/code>\u3002<\/p>\n\n\n\n<p>\uff08\u63d0\u793a\uff1a\u9700\u8981\u4f7f\u7528\u5faa\u73af\u6765\u5206\u914d&nbsp;<code>[][]uint8<\/code>&nbsp;\u4e2d\u7684\u6bcf\u4e2a&nbsp;<code>[]uint8<\/code>\uff1b\u8bf7\u4f7f\u7528&nbsp;<code>uint8(intValue)<\/code>&nbsp;\u5728\u7c7b\u578b\u4e4b\u95f4\u8f6c\u6362\uff1b\u4f60\u53ef\u80fd\u4f1a\u7528\u5230&nbsp;<code>math<\/code>&nbsp;\u5305\u4e2d\u7684\u51fd\u6570\u3002\uff09<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u4e2a\u9898\u6bd4\u8f83\u7b80\u5355\uff0c\u5c31\u662f\u8981\u5229\u7528\u5faa\u73af\uff0c\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u5207\u7247\uff08\u6570\u7ec4\uff09\uff0c\u7136\u540e\u7ed9\u6bcf\u4e2a\u5143\u7d20\u8d4b\u4e00\u4e2a\u503c\uff0c\u8fd9\u4e2a\u503c\u53ef\u4ee5\u6839\u636e\u4e8c\u7ef4\u6570\u7ec4\u7684\u5750\u6807xy\u6765\u8ba1\u7b97\uff0c\u9898\u76ee\u4e2d\u63d0\u4f9b\u4e86\u51e0\u4e2a\u51fd\u6570\u3002\u6211\u4eec\u7528<code>x ^ y<\/code>\u8bd5\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"golang.org\/x\/tour\/pic\"\n\nfunc Pic(dx, dy int) &#91;]&#91;]uint8 {\n\t\/\/ \u4e8c\u7ef4\u5207\u7247\uff0c\u5916\u5c42\u957f\u5ea6\u4e3ady\n\tp := make(&#91;]&#91;]uint8, dy)\n\t\/\/ \u901a\u8fc7\u5faa\u73af\uff0c\u7ed9\u6bcf\u4e2a\u5916\u5c42\u5143\u7d20\u521b\u5efa\u4e00\u4e2a\u5207\u7247\n\tfor y := range p {\n\t\tp&#91;y] = make(&#91;]uint8, dx)\n\t\tfor x := range p&#91;y] {\n\t\t\t\/\/ \u7ed9\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\uff0c\u53c2\u8003\u9898\u76ee\u4e2d\u7684\u5176\u4ed6\u51fd\u6570\n\t\t\tp&#91;y]&#91;x] = uint8(x ^ y)\n\t\t}\n\t}\n\treturn p\n}\n\nfunc main() {\n\tpic.Show(Pic)\n}\n<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u7ed3\u679c\u662f\u4e00\u5f20256X256\u7684\u56fe\u7247\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/fdream.net\/blog\/wp-content\/uploads\/2022\/11\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"256\" height=\"256\" src=\"https:\/\/fdream.net\/blog\/wp-content\/uploads\/2022\/11\/image-4.png\" alt=\"\" class=\"wp-image-1238\" srcset=\"https:\/\/fdream.net\/blog\/wp-content\/uploads\/2022\/11\/image-4.png 256w, https:\/\/fdream.net\/blog\/wp-content\/uploads\/2022\/11\/image-4-150x150.png 150w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><\/figure>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u8bd5\u8bd5\u5176\u4ed6\u51fd\u6570\uff0c\u4f1a\u751f\u6210\u4e0d\u540c\u7684\u56fe\u7247\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u662fA Tour of Go\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u7684\u7b2c\u4e8c\u4e2a\u7ec3\u4e60\uff0c\u539f\u9898\u5982\u4e0b\uff1a \u5b9e\u73b0&nbsp;Pic\u3002\u5b83\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;dy&nbsp;\u7684\u5207\u7247\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;dx\uff0c\u5143\u7d20\u7c7b\u578b\u4e3a&nbsp;uint8&nbsp;\u7684\u5207\u7247\u3002\u5f53\u4f60\u8fd0\u884c\u6b64\u7a0b\u5e8f\u65f6\uff0c\u5b83\u4f1a\u5c06\u6bcf\u4e2a\u6574\u6570\u89e3\u91ca\u4e3a\u7070\u5ea6\u503c\uff08\u597d\u5427\uff0c\u5176\u5b9e\u662f\u84dd\u5ea6\u503c\uff09\u5e76\u663e\u793a\u5b83\u6240\u5bf9\u5e94\u7684\u56fe\u50cf\u3002 \u56fe\u50cf\u7684\u9009\u62e9\u7531\u4f60\u6765\u5b9a\u3002\u51e0\u4e2a\u6709\u8da3\u7684\u51fd\u6570\u5305\u62ec&nbsp;(x+y)\/2,&nbsp;x*y,&nbsp;x^y,&nbsp;x*log(y)&nbsp;\u548c&nbsp;x%(y+1)\u3002 \uff08\u63d0\u793a\uff1a\u9700\u8981\u4f7f\u7528\u5faa\u73af\u6765\u5206\u914d&nbsp;[][]uint8&nbsp;\u4e2d\u7684\u6bcf\u4e2a&nbsp;[]uint8\uff1b\u8bf7\u4f7f\u7528&nbsp;uint8(intValue)&nbsp;\u5728\u7c7b\u578b\u4e4b\u95f4\u8f6c\u6362\uff1b\u4f60\u53ef\u80fd\u4f1a\u7528\u5230&nbsp;math&nbsp;\u5305\u4e2d\u7684\u51fd\u6570\u3002\uff09 \u8fd9\u4e2a\u9898\u6bd4\u8f83\u7b80\u5355\uff0c\u5c31\u662f\u8981\u5229\u7528\u5faa\u73af\uff0c\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u5207\u7247\uff08\u6570\u7ec4\uff09\uff0c\u7136\u540e\u7ed9\u6bcf\u4e2a\u5143\u7d20\u8d4b\u4e00\u4e2a\u503c\uff0c\u8fd9\u4e2a\u503c\u53ef\u4ee5\u6839\u636e\u4e8c\u7ef4\u6570\u7ec4\u7684\u5750\u6807xy\u6765\u8ba1\u7b97\uff0c\u9898\u76ee\u4e2d\u63d0\u4f9b\u4e86\u51e0\u4e2a\u51fd\u6570\u3002\u6211\u4eec\u7528x ^ y\u8bd5\u4e00\u4e0b\uff1a \u6267\u884c\u7ed3\u679c\u662f\u4e00\u5f20256X256\u7684\u56fe\u7247\uff0c\u5982\u4e0b\uff1a \u4e5f\u53ef\u4ee5\u8bd5\u8bd5\u5176\u4ed6\u51fd\u6570\uff0c\u4f1a\u751f\u6210\u4e0d\u540c\u7684\u56fe\u7247\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[374],"class_list":["post-1237","post","type-post","status-publish","format-standard","hentry","category-coding","tag-go"],"views":318,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=1237"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1237\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=1237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=1237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=1237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}