Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global keys := ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid", "cid"]
- , keysCount := keys.Count()
- passports =
- (
- ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
- byr:1937 iyr:2017 cid:147 hgt:183cm
- iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
- hcl:#cfa07d byr:1929
- hcl:#ae17e1 iyr:2013
- eyr:2024
- ecl:brn pid:760753108 byr:1931
- hgt:179cm
- hcl:#cfa07d eyr:2025 pid:166559648
- iyr:2011 ecl:brn hgt:59in
- )
- OutputDebug, % "Valid Passports: " countValidPassports(passports) "`n"
- passports := genPassports()
- OutputDebug, % "Valid Passports: " countValidPassports(passports) "`n"
- genPassports(qty := 10)
- {
- ; wikipedia.org/wiki/Human_hair_color#Natural_hair_colors
- static hairColors := [ "brn" ; Brown
- , "bld" ; Blond
- , "blk" ; Black
- , "aub" ; Auburn
- , "red" ; Red
- , "gry" ; Gray
- , "wte" ] ; White"
- , hairColorsCount := hairColors.Count()
- ; wikipedia.org/wiki/Eye_color#Eye_color_chart_(Martin_scale)
- , eyeColors := [ "amb" ; Amber
- , "blu" ; Blue
- , "brn" ; Brown
- , "gry" ; Gray
- , "grn" ; Green
- , "hzl" ; Hazel
- , "red" ; Red
- , "vio" ] ; Violet
- , eyeColorsCount := eyeColors.Count()
- ; worldometers.info/geography/how-many-countries-are-there-in-the-world/
- , countriesCount := 195
- , passports := ""
- loop, % qty
- {
- passport := {}
- ; Birth Year
- Random, byr, % A_Year - 90, % A_Year
- passport.byr := byr
- ; Issue Year
- Random, iyr, % A_Year - 10, % A_Year
- iyr := (byr > iyr ? byr : iyr)
- passport.iyr := iyr
- ; Expiration Year
- Random, eyr, % iyr, % iyr + 10
- passport.eyr := eyr
- ; Height
- Random, hgt, 50, 210
- passport.hgt := hgt "cm"
- ; Hair Color
- Random, hcl, 1, % hairColorsCount
- passport.hcl := hairColors[hcl]
- ; Eye Color
- Random, ecl, 1, % eyeColorsCount
- passport.ecl := eyeColors[ecl]
- ; Passport ID
- Random, hasPid, 0, 1
- if (hasPid)
- {
- passport.pid := A_TickCount
- }
- ; Country ID
- Random, cid, 1, % countriesCount
- passport.cid := cid
- ; Randomly invalidate
- Random, rnd, 0, 1
- if (rnd)
- {
- Random, rem, 1, % keysCount
- passport.Delete(keys[rem])
- }
- for key,val in passport
- {
- Random, separator, 0, 1
- passports .= key ":" val (separator ? " " : "`n")
- }
- passports := RTrim(passports) "`n`n"
- }
- return passports
- }
- countValidPassports(data)
- {
- passport := ""
- , count := tot := pos := 0
- , data .= "`n" ; Must end in new line
- Loop, parse, data, `n, `r
- {
- if (A_LoopField)
- {
- passport .= A_LoopField " "
- while (pos := InStr(A_LoopField, ":",, ++pos))
- {
- tot++
- }
- }
- else if (tot)
- {
- count += isValid := (tot = keysCount || (tot = (keysCount-1) && !InStr(passport, "cid")))
- ; OutputDebug, % isValid " | " tot " | " passport "`n"
- passport := "", tot := pos := 0
- }
- }
- return count
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement