Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

抽奖送3本<WebAssembly标准入门>图书 #4

Closed
chai2010 opened this issue Dec 9, 2018 · 68 comments
Closed

抽奖送3本<WebAssembly标准入门>图书 #4

chai2010 opened this issue Dec 9, 2018 · 68 comments
Assignees
Labels
bug

Comments

@chai2010
Copy link
Collaborator

@chai2010 chai2010 commented Dec 9, 2018

抽奖链接

#4


<WebAssembly标准入门>相关链接:

几个有意思的例子(基于asm.js):


公平公正的抽奖规则

抽奖规则的设计原则:

  • 组织方和参与者均有参与感
  • 抽奖的结果可重现,但是开奖之前无法预支结果

收集参与抽奖的人

  • 必须有github账号,并在这个issue留言参与抽奖
  • github账号必须2018年之前申请的
  • 只接受大陆普通快递可达地区

抽奖的流程

  1. 开始前,大家可以验证规则是否有缺陷,有任何问题都可以讨论
  2. 我在抽奖正式开始时(可以提前参与),会准备一个秘密的字符串作为种子,然后先公布种子字符串的MD5,同时公布截止的规则(可以是ID达到一个数量, 或者是设置一个截止时间里程碑)
  3. 参与抽象的同学回复一个幸运字符串([0-9a-zA-Z-_]等字符组成,1-32个字符),也可以用自己的账号(如果用户如果担心泄密,也可以公布MD5)
  4. 开奖前我公布作为种子的秘密字符串,大家可以验证MD5,以防止我作弊
  5. 开奖前,参与者如果是提供MD5的也需要公布自己的幸运字符串,大家也去验证
  6. 每个ID和秘密的种子字符串各生成一个对应的crc32数字,最后把数字加起来对人数取模就是中奖号
  7. 每个ID作为utf8字符串排序,排序后的位置就是每个ID的抽奖号码
  8. 在开奖后和结果公布之前,会锁定这个issue,之后会再重新打开
  9. 抽完一个之后删除中奖ID,继续上述流程
  10. 任何人可以验证结果

补充点:

  • 有任何疑问请加入 QQ群 (726475047) 讨论
  • 如果用户以MD5公布的幸运号,那么在抽奖截止后要公布真实的幸运号,否则作废
  • 如果担心MD5不够安全,可以加盐,比如 abc:sdfsd 生成的MD5, abc是幸运号,冒号后面是salt
  • 每个账号如果回复多个幸运字符串,以开奖前的最后一个为准
  • chai2010和ending不参与

抽奖的代码(Go语言实现)

下面是抽奖算法的例子,种子字符串是wasm,2各参与者:

// Copyright 2018 chaishushan@gmail.com. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"fmt"
	"hash/crc32"
	"sort"
)

func main() {
	luckyStar := MakeLuckyStar("wasm", map[string]string{
		"chai2010": "chai2010",
		"ending":   "ending",
	})

	fmt.Println(luckyStar)
	// output: ending
}

func MakeLuckyStar(seed string, luckyTokens map[string]string) string {
	var (
		crc32Sum   = uint64(crc32.ChecksumIEEE([]byte(seed)))
		sortedKeys = make([]string, 0, len(luckyTokens))
	)

	for id, tok := range luckyTokens {
		crc32Sum += uint64(crc32.ChecksumIEEE([]byte(tok)))
		sortedKeys = append(sortedKeys, id)
	}
	sort.Strings(sortedKeys)

	idx := int(crc32Sum) % len(luckyTokens)
	return sortedKeys[idx]
}

https://play.golang.org/p/mox2zhbde49

@chai2010 chai2010 self-assigned this Dec 9, 2018
@chai2010 chai2010 added the bug label Dec 9, 2018
@zlus

This comment has been minimized.

Copy link

@zlus zlus commented Dec 10, 2018

zlus

@z-jingjie

This comment has been minimized.

Copy link

@z-jingjie z-jingjie commented Dec 10, 2018

重在参与!谢谢大神为WASM社区贡献作品~
幸运字符串用GitHub ID就好~

@hoperuin

This comment has been minimized.

Copy link

@hoperuin hoperuin commented Dec 10, 2018

gogogo

@yxwsbobo

This comment has been minimized.

Copy link

@yxwsbobo yxwsbobo commented Dec 10, 2018

1

@oracle3

This comment has been minimized.

Copy link

@oracle3 oracle3 commented Dec 10, 2018

没看懂

@elvinn

This comment has been minimized.

Copy link

@elvinn elvinn commented Dec 10, 2018

elvinn

@500646

This comment has been minimized.

Copy link

@500646 500646 commented Dec 10, 2018

分母+`

@duobei

This comment has been minimized.

Copy link

@duobei duobei commented Dec 10, 2018

+1

@qiushuiqs

This comment has been minimized.

Copy link

@qiushuiqs qiushuiqs commented Dec 10, 2018

qiushuiqs

@un-defined

This comment has been minimized.

Copy link

@un-defined un-defined commented Dec 10, 2018

3

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 10, 2018

合法的幸运字符串必须以 [0-9a-zA-Z-_] 等字符组成,长度为1-32个字符。
如果是不合法的幸运码,那么将用ID作为幸运码。

如果是不合法的幸运码,可以重新想一个,
最终以截止时间前最后一次回复为准。

@logeable

This comment has been minimized.

Copy link

@logeable logeable commented Dec 10, 2018

A_A

@vfan

This comment has been minimized.

Copy link

@vfan vfan commented Dec 10, 2018

jscoder

@happytoTom

This comment has been minimized.

Copy link

@happytoTom happytoTom commented Dec 10, 2018

happytoTom

@zacklocx

This comment has been minimized.

Copy link

@zacklocx zacklocx commented Dec 10, 2018

zacklocx

@Maopy

This comment has been minimized.

Copy link

@Maopy Maopy commented Dec 10, 2018

maopy

@xbox1994

This comment has been minimized.

Copy link

@xbox1994 xbox1994 commented Dec 10, 2018

niupi

@niucang

This comment has been minimized.

Copy link

@niucang niucang commented Dec 10, 2018

niucang

@renji001

This comment has been minimized.

Copy link

@renji001 renji001 commented Dec 10, 2018

v587

@litianjiao

This comment has been minimized.

Copy link

@litianjiao litianjiao commented Dec 10, 2018

JoJo

@gladmo

This comment has been minimized.

Copy link

@gladmo gladmo commented Dec 10, 2018

gladmo

@yyh1102

This comment has been minimized.

Copy link

@yyh1102 yyh1102 commented Dec 10, 2018

lowesyang

@yohoj

This comment has been minimized.

Copy link

@yohoj yohoj commented Dec 10, 2018

yohoj

@yangliyl

This comment has been minimized.

Copy link

@yangliyl yangliyl commented Dec 10, 2018

yangliyl

@Deteriorator

This comment has been minimized.

Copy link

@Deteriorator Deteriorator commented Dec 10, 2018

JustForFun

@YL2014

This comment has been minimized.

Copy link

@YL2014 YL2014 commented Dec 10, 2018

YL2014

@Noel1992

This comment has been minimized.

Copy link

@Noel1992 Noel1992 commented Dec 10, 2018

happy

@mrFranklin

This comment has been minimized.

Copy link

@mrFranklin mrFranklin commented Dec 10, 2018

20150308

@orangemio

This comment has been minimized.

Copy link

@orangemio orangemio commented Dec 12, 2018

orange

@tinysniper

This comment has been minimized.

Copy link

@tinysniper tinysniper commented Dec 13, 2018

赞!

@jeanary

This comment has been minimized.

Copy link

@jeanary jeanary commented Dec 13, 2018

谢谢无私贡献,参与抽奖

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 13, 2018

很多同学有点等不及提前下单了,因此我们也希望快点抽奖。
我目前想法是,下周三(2018.12.19)24:00前参与的有效,下周四公布种子字符串开奖(根据之前的规则提前一周通知)。

另外,有些回复中文的直接以id作为幸运码了,还有一个幸运码包含了C++中的加号不在有效字符中。
希望能将+符号也作为有效的字符。

大家如果有异议,在本周提出(直接回issue)。
如果没有异议,就按这个计划执行了。

最终开奖时,会给出完整的Go代码,大家自己运行验证。

@SteveJiao

This comment has been minimized.

Copy link

@SteveJiao SteveJiao commented Dec 13, 2018

tell

@smartepsh

This comment has been minimized.

Copy link

@smartepsh smartepsh commented Dec 14, 2018

py_trade

@zhmushan

This comment has been minimized.

Copy link

@zhmushan zhmushan commented Dec 16, 2018

zhmushan

@shoukailiang

This comment has been minimized.

Copy link

@shoukailiang shoukailiang commented Dec 16, 2018

goodliang

@CookiesEason

This comment has been minimized.

Copy link

@CookiesEason CookiesEason commented Dec 16, 2018

cookiesEason

@woshidaxian

This comment has been minimized.

Copy link

@woshidaxian woshidaxian commented Dec 16, 2018

nice

@JeoA

This comment has been minimized.

Copy link

@JeoA JeoA commented Dec 16, 2018

yeah

@LinkXSystem

This comment has been minimized.

Copy link

@LinkXSystem LinkXSystem commented Dec 16, 2018

will

@anheiqq

This comment has been minimized.

Copy link

@anheiqq anheiqq commented Dec 17, 2018

aishing

@wxyPostman

This comment has been minimized.

Copy link

@wxyPostman wxyPostman commented Dec 17, 2018

postman

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 19, 2018

今天晚上凌晨截止

@chenlx0

This comment has been minimized.

Copy link

@chenlx0 chenlx0 commented Dec 19, 2018

excited

@vyf

This comment has been minimized.

Copy link

@vyf vyf commented Dec 19, 2018

vyf

Repository owner locked as resolved and limited conversation to collaborators Dec 19, 2018
@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 19, 2018

$ md5 -s ending-law:wasm
MD5 ("ending-law:wasm") = 1674409b850179fab3d35f400054ff79

种子字符串为: ending-law

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 19, 2018

感谢大家的参与。一共收集到53个参与者,信息如下。
大家帮忙检查下是否有记录错误的,如果没有的话,就以此为准明天正式生效。

PS: 大家不要改前面的回复了,因为可能干扰最终结果。

var luckyIdTable = map[string]string{
	"zlus":      "zlus",
	"z-jingjie": "z-jingjie",
	"hoperuin":  "gogogo",
	"yxwsbobo":  "1",
	//"oracle3":      "oracle3", // 无效幸运码, 用ID; 重复设置, 保留后一个
	"elvinn":         "elvinn",
	"500646":         "500646", // 无效幸运码, 用ID
	"duobei":         "+1",
	"qiushuiqs":      "qiushuiqs",
	"un-defined":     "3",
	"logeable":       "A_A",
	"vfan":           "jscoder",
	"happytoTom":     "happytoTom",
	"zacklocx":       "zacklocx",
	"Maopy":          "maopy",
	"xbox1994":       "niupi",
	"niucang":        "niucang",
	"renji001":       "v587",
	"litianjiao":     "JoJo",
	"gladmo":         "gladmo",
	"yyh1102":        "lowesyang",
	"yohoj":          "yohoj",
	"yangliyl":       "yangliyl",
	"Deteriorator":   "JustForFun",
	"YL2014":         "YL2014",
	"Noel1992":       "happy",
	"mrFranklin":     "20150308",
	"yunshang":       "alshin",
	"Ir1d":           "ir1dxd",
	"penghua123":     "goodluck",
	"oracle3":        "oracle3", // 覆盖之前的值
	"itstudying":     "webassembly",
	"loohoo":         "loohoo",
	"googya":         "hoodoo",
	"1124219777":     "lihail",
	"fqd511":         "511",
	"yj21world":      "yj",
	"thecorsair":     "webassembly",
	"sjtutyx":        "wasmjs",
	"Orangem21":      "orange",
	"tinysniper":     "tinysniper",
	"jeanary":        "jeanary",
	"SteveJiao":      "tell",
	"smartepsh":      "py_trade",
	"zhmushan":       "zhmushan",
	"shoukailiang":   "goodliang",
	"CookiesEason":   "cookiesEason",
	"woshidaxian":    "nice",
	"JeoA":           "yeah",
	"LinkXSystem":    "will",
	"anheiqq":        "aishing",
	"WXY1228":        "postman",
	"Hurricane-Chen": "excited",
	"vyf":            "vyf",
}
Repository owner unlocked this conversation Dec 19, 2018
@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 19, 2018

取消了锁定,有问题尽快反馈。

如果没有疑问,明天就生效了。
生效之后,即使发现新的错误也不会再改了。

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 20, 2018

package main

import (
	"fmt"
	"hash/crc32"
	"sort"
)

// MD5 ("ending-law:wasm") = 1674409b850179fab3d35f400054ff79
const luckySeed = "ending-law"

// https://github.com/3dgen/cppwasm-book/issues/4
var luckyIdTable = map[string]string{
	"zlus":      "zlus",
	"z-jingjie": "z-jingjie",
	"hoperuin":  "gogogo",
	"yxwsbobo":  "1",
	//"oracle3":      "oracle3", // 无效幸运码, 用ID; 重复设置, 保留后一个
	"elvinn":         "elvinn",
	"500646":         "500646", // 无效幸运码, 用ID
	"duobei":         "+1",
	"qiushuiqs":      "qiushuiqs",
	"un-defined":     "3",
	"logeable":       "A_A",
	"vfan":           "jscoder",
	"happytoTom":     "happytoTom",
	"zacklocx":       "zacklocx",
	"Maopy":          "maopy",
	"xbox1994":       "niupi",
	"niucang":        "niucang",
	"renji001":       "v587",
	"litianjiao":     "JoJo",
	"gladmo":         "gladmo",
	"yyh1102":        "lowesyang",
	"yohoj":          "yohoj",
	"yangliyl":       "yangliyl",
	"Deteriorator":   "JustForFun",
	"YL2014":         "YL2014",
	"Noel1992":       "happy",
	"mrFranklin":     "20150308",
	"yunshang":       "alshin",
	"Ir1d":           "ir1dxd",
	"penghua123":     "goodluck",
	"oracle3":        "oracle3", // 覆盖之前的值
	"itstudying":     "webassembly",
	"loohoo":         "loohoo",
	"googya":         "hoodoo",
	"1124219777":     "lihail",
	"fqd511":         "511",
	"yj21world":      "yj",
	"thecorsair":     "webassembly",
	"sjtutyx":        "wasmjs",
	"Orangem21":      "orange",
	"tinysniper":     "tinysniper",
	"jeanary":        "jeanary",
	"SteveJiao":      "tell",
	"smartepsh":      "py_trade",
	"zhmushan":       "zhmushan",
	"shoukailiang":   "goodliang",
	"CookiesEason":   "cookiesEason",
	"woshidaxian":    "nice",
	"JeoA":           "yeah",
	"LinkXSystem":    "will",
	"anheiqq":        "aishing",
	"WXY1228":        "postman",
	"Hurricane-Chen": "excited",
	"vyf":            "vyf",
}

func main() {
	for i := 1; len(luckyIdTable) > 0; i++ {
		luckyStar := MakeLuckyStar(luckySeed, luckyIdTable)
		delete(luckyIdTable, luckyStar)

		fmt.Println(i, luckyStar)
	}
}

func MakeLuckyStar(seed string, luckyTokens map[string]string) string {
	var (
		crc32Sum   = uint64(crc32.ChecksumIEEE([]byte(seed)))
		sortedKeys = make([]string, 0, len(luckyTokens))
	)

	for id, tok := range luckyTokens {
		crc32Sum += uint64(crc32.ChecksumIEEE([]byte(tok)))
		sortedKeys = append(sortedKeys, id)
	}
	sort.Strings(sortedKeys)

	idx := int(crc32Sum % uint64(len(luckyTokens)))
	return sortedKeys[idx]
}

https://play.golang.org/p/dwEqj1jrRYu

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 21, 2018

恭喜以下三位同学:

1 yohoj
2 Orangem21
3 WXY1228

同时感谢所有的参与者,这是大家共同选择的结果。

希望上面3为同学给我发下邮寄地址(chaishushan@gmail.com),
或者加入 QQ群:726475047,给我发QQ消息

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 21, 2018

@yohoj@wxy1228 的奖品已经寄出。
麻烦 @Orangem21 尽快提供地址

@orangemio

This comment has been minimized.

Copy link

@orangemio orangemio commented Dec 21, 2018

已经发了邮件,请查收下~

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 21, 2018

@Orangem21 奖品已经处理

@chai2010

This comment has been minimized.

Copy link
Collaborator Author

@chai2010 chai2010 commented Dec 21, 2018

感谢大家的参与,这个issue就关闭了。
近期如果有任何问题,依然可以在此留言

谢谢

@chai2010 chai2010 closed this Dec 21, 2018
@cifer-lee

This comment has been minimized.

Copy link

@cifer-lee cifer-lee commented Dec 25, 2018

好可惜, 已经结束了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.