Skip to content

Instantly share code, notes, and snippets.

@Delta456
Last active May 4, 2020 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Delta456/8c0939a435afe9836a78c442e9d4f9fc to your computer and use it in GitHub Desktop.
Save Delta456/8c0939a435afe9836a78c442e9d4f9fc to your computer and use it in GitHub Desktop.
is thirteen module in V
module is_thirteen
import math
import time
import strings
const (
thirteen_strs = [
"xiii", // Roman numeral 13
"1.3", // Basically 13, see proof in https://github.com/jezen/is-thirteen/pull/420
"1️⃣ 3️⃣", // emoji sequence of 1 and 3
"https://en.wikipedia.org/wiki/This_Is_Thirteen", // Because it is thirteen
"https://scontent.cdninstagram.com/hphotos-xtf1/t51.2885-15/s320x320/e35/12237511_444845689040315_1101385461_n.jpg", // Just because we can
"https://www.youtube.com/watch?v=pte3Jg-2Ax4", // Thirteen by Big Star
"https://www.youtube.com/watch?v=33Kv5D2zwyc", // The best Johny Cash's song
"remy hadley", // And because she's "Thirteen"
"olivia wilde", // AND because SHE's "Thirteen"
"baker's dozen", // Bakers gonna bake
"dr. remy beauregard hadley", // Why not 13's real name?!
"patty tsai", // 蔡依珊 is a public figure in Taiwan. Her Chinese name sounds like "13".
"https://s3.amazonaws.com/rapgenius/calle13.jpg", // Calle 13, famous Puerto Rican band
"jason fly", // XIII of The XX
"http://www.imdb.com/title/tt0798817/", // 13 (2010)
"https://www.imdb.com/title/tt2991516/", // 13/13/13 (2013)
"https://en.wikipedia.org/wiki/XIII_(video_game)", // Because video games are also culture
"dilma", //Dilma, former president of Brazil. Her number is 13: https://www.google.com/search?q=dilma+13
"PT", // PT is Brazilian political party represented by the number 13
"Washington Luís", // Brazil's thirteenth president
"Millard Fillmore", // Thirteenth President of the United States
"Louis XIII", // Thirteenth king of France
"https://s3.amazonaws.com/rapgenius/calle13.jpg", // Calle 13, famous latin american band
"sharon carter", // Agent 13
"end of slavery", // Thirteenth Amendment
// Television characters
"Jodie Whittaker", // the 13th Doctor in the BBC series, "Doctor Who"
"weedle", //#13 Pokémon
// Imaginary 13's
"13+0i",
"13 + 13i",
"13i",
// B just looks like 13 written closer
"B",
//For cultural inclusiveness also include German variants
"ß",
"ẞ",
//Also greek
"β",
"Β", //actually upper case Beta, not B
//And Chinese
"阝", //(Kangxi radical)
//Adding "l" 3, "i"3, |3 and !3 because they basically look like thirteen
"i3",
"l3",
"|3",
"!3",
//Looks like 13 (flipped horizontally) - E equal to 3
"ei",
"e1",
"el",
"e|",
// Flipped characters
"ƖƐ",
"ƐƖ",
// Password variations
"th1rt33n",
"th1rte3n",
"th1rteen",
"thirt3en",
"thirt33n",
"thirte3n",
// code variations
// binary
"00001101",
"0b1101",
// Octal
"0o15",
// Hexadecimal
"0xd",
// Morse
".---- ...--",
"- .... .. .-. - . . -.",
"- .... .. .-. - . . -.",
// Caesar shift
"wkluwhhq",
"Wkluwhhq",
"WKLUWHHQ",
// hex
"74 68 69 72 74 65 65 6e",
"54 48 49 52 54 45 45 4e",
"31 33",
"74 68 69 72 74 65 65 6e 0d 0a",
"54 68 69 72 74 65 65 6e 0d 0a",
"54 48 49 52 54 45 45 4e 0d 0a 0d 0a",
// base64
"dGhpcnRlZW4=",
"VGhpcnRlZW4=",
"VEhJUlRFRU4=",
"MTM=",
// Languages
"thirteen", // English
"ثلاثة عشر", // Arabic (masculine)
"ثلاث عشرة", // Arabic (feminine)
"تلطاشر", // Arabic Slang
"تلتاشر", // Arabic Slang
"طلتاشر", // Arabic Slang
"طلطاشر", // Arabic Slang
"يج", //Arabic (gematria)
"سیزده", // Persian
"۱۳", // Persian number
"dertien", // Afrikaans / Dutch
"dertiendertien", // Double Dutch
"seri-un-teng", // Belter creole
"seriunteng",
"serí-un-teng",
"seríunteng",
"тринадесет", // Bulgarian
"тринайсет", // Also Bulgarian
"tretze", // Catalan
"napulo ug tulo", // Cebuano
"十三", // Chinese / Japanese
"拾參", // Chinese (traditional, upper case)
"拾叁", // Chinese (simplified, upper case)
"拾叄", // Chinese (variant)
"拾参", // Chinese (variant)
"サーティーン", // Japanese
"13", // Japanese full-width
"trinaest", // Croatian / Serbian (latin)
"tretten", // Danish / Norwegian
"senthi", //Dothraki
"þrettán", // Icelandic, following are different inflections
"þrettándi", // e. thirteenth
"þrettánda",
"þrettándinn", // e. the thirteenth
"þrettándann",
"þrettándanum",
"þrettándans",
"þrettándar", // e. multiple thirteenths
"þrettándu",
"þrettándum",
"þrettándarnir", // e. the multiple thirteenths
"þrettándana",
"þrettándunum",
"þrettándanna",
"threttan", // strings without special icelandic characters
"threttandi",
"threttanda",
"threttandinn",
"threttandann",
"threttandanum",
"threttandans",
"threttandar",
"threttandu",
"threttandum",
"threttandarnir",
"threttandana",
"threttandunum",
"threttandanna", // end of Icelandic
"threttandum", // end of Icelandic
"třináct", // Czech
"kolmteist", // Estonian
"labintatlo", // Filipino
"kolmetoista", // Finnish
"treize", // French
"treizième", //French (ordinal form)
"dreizehn", // German
"ცამეტი", // Georgian
"δεκατρία", // Greek
"drizäh", // Swiss German
"wa’maH wej", // Klingon
"‘umikūmākolu", // Hawaiian
"שלוש עשרה", // Hebrew
"שלושעשרה", // Hebrew (without space)
"ֹשְלֹש- עֶשְֹרֵה", // Hebrew (with punctuation)
"שלושה עשר", // Hebrew (male form)
"שלושהעשר", // Hebrew (male form, without space)
"ֹשְלֹשָה- עָשָֹר", // Hebrew (male form, with punctuation)
"יג", // Hebrew (gematria)
"י״ג", // Hebrew (gematria - apostrophes)
"quainel", // Quenya
"mînuiug", // Sindarin
"dektri", // Esperanto
"tizenhárom", // Hungarian
"trí déag", // Irish
"tredici", // Italian
"ಹದಿಮೂರು", //Kannada (for thirteen)
"೧೩", //Kannada (for 13)
"sêzdeh", // Kurdish
"tredecim", // Latin
"trīspadsmit", // Latvian
"trylika", // Lithuanian
"dräizéng", // Luxembourgish
"тринаесет", // Macedonian
"tiga belas", // Malay
"പതിമൂന്ന്", //Malayalam
"तेरा", // Marathi (१३)
"арван", // Mongolian
".---- ...--", // Morse code
"irteenthay", // Pig Latin
// Beginning of some Korean variants 🇰🇷
"열셋", // Korean
"십삼", // Korean
"써틴", // Korean
"썰틴", // Korean
"떠틴", // Korean
"떨틴", // Korean
"씹쌈", // Korean
"십쌈", // Korean
"씹삼", // Korean
"10삼", // Korean
"십3", // Korean
"시입삼", // Korean
"시이입삼", // Korean (TODO: Anything that matches "^(십|(시이*입))(삼|(사아*암))$" is 13)
"여얼세엣", // Korean
"열세엣", // Korean (TODO: Also, Anything that matches "^(열|(여어*얼))(셋|(세에*엣))$" is 13)
// End of some Korean variants 🇰🇷
// Beginning of all Polish variants 🇵🇱
"trzynaście", // Polish
"trzynasty", // Polish
"trzynasta", // Polish
"trzynaste", // Polish
"trzynaści", // Polish
"trzynastego", // Polish
"trzynastej", // Polish
"trzynastych", // Polish
"trzynastemu", // Polish
"trzynastym", // Polish
"trzynastą", // Polish
"trzynastymi", // Polish
"trzynastu", // Polish
"trzynastek", // Polish
"trzynastoma", // Polish
"trzynaścioro", // Polish
"trzynastka", // Polish
"trzynastki", // Polish
"trzynastką", // Polish
"trzynastce", // Polish
"trzynastko", // Polish
"trzynaściorgiem", // Polish
"trzynaściorgu", // Polish
"trzynaściorga", // Polish
"trzynastokrotny", // Polish
"trzynastokrotnie", // Polish
"trzynastokrotną", // Polish
"trzynastokrotnemu", // Polish
"trzynastokrotnej", // Polish
"trzynastokrotnych", // Polish
"trzynastokrotność", // Polish
"trzynastokrotności", // Polish
"trzynastokrotnością", // Polish
// End of all Polish variants 🇵🇱
// Bangla/Bengali variants
"১৩", // Bengali numeral
"তেরো",
"তের",
"ত্রয়োদশ",
// end of Bangla/Bengali variants
"treze", // Portuguese
"ਤੇਰਾਂ", // Punjabi - thirteen
"੧੩", // Punjabi Numeral - 13
"treisprezece", // Romanian
"treispe", // Romanian
"тринадцать", // Russian (cyrillic)
"ⱅⱃⰺⱀⰰⰴⱌⰰⱅⱐ", // Russian (glagolitic)
"тринаест", // Serbian (cyrillic)
"trinásť", // Slovak
"trinajst", // Slovenian
"trece", // Spanish
"diez-y-tres", // Spanglish
"trese", // Tagalog
"on üç", // Turkish
"dektri", //Speranto
"tlettax", // Maltese
"tretton", // Swedish
"பதின்மூன்று", // Tamil
"สิบสาม", // Thai
"๑๓", // Thai Numeral
"SipSam", // Thai Transcription
"Sip Sam", // Thai Transcription with space
"тринадцять", // Ukrainian
"تیرہ", // Urdu
"mười ba", // Vietnamese
"tri ar ddeg", // Welsh
"דרייַצן", // Yiddish,
"דרייצן", // Yiddish (without diacritics),
"kumi na tatu", // Swahili
"तेह्र", //Nepali
"१३", //Devanagari
"तेरह", //Hindi
"7h1r733n", // Crypto
// Thirteen pronunciation
"θərˈtiːn",
"పదమూడు", //Telugu
"shí sān", // Pinyin (formal)
"shi san", // Pinyin (without tones)
"shísān", // Pinyin (without spaces)
"shisan", // Pinyin (without spaces and tones)
"он үш", // Kazakh
"он уш", // Kazakh
"onúsh", // Kazakh latin,
"онүш", // Kazakh
"онуш", // Kazakh
"onúsh", // Kazakh latin
"ishumi nantathu", // isiZulu
"lishumi elinesithathu", // isiXhosa
]
thirteen = 13
)
struct NumMatcher {
value f64
roughly RoughlyMatcher
not InvertedMatcher
divisible_by DivMatcher
square_of SqMatcher
greater_than GreaterMatcher
less_than LessMatcher
year_of_birth BirthMatcher
}
// number Instanitiate a matcher for number type
pub fn number(value f64) NumMatcher {
return NumMatcher{
value: value,
roughly: RoughlyMatcher{value},
not: InvertedMatcher{value},
divisible_by: DivMatcher{value},
square_of: SqMatcher{value},
greater_than: GreaterMatcher{value},
less_than: LessMatcher{value},
year_of_birth: BirthMatcher{value/*,RealClock{}*/},
}
}
// thirteen Check if the number is Thirteen
pub fn (m NumMatcher) thirteen() bool {
return m.value == thirteen
}
struct OfWithinMatcher {
of WithinMatcher
}
// within instanitiate a matcher for number within a range around thirtheen
pub fn (m NumMatcher) within(number_range f64) OfWithinMatcher {
return OfWithinMatcher{
of: WithinMatcher{
value: m.value,
num_range: number_range,
},
}
}
// plus instanitiate a number matcher with a new value with add
pub fn (m NumMatcher) plus(num f64) NumMatcher {
return number(m.value + num)
}
// minus instanitiate a number matcher with a new value with a sub
pub fn (m NumMatcher) minus(num f64) NumMatcher {
return number(m.value - num)
}
// times instanitiate a number matcher with a new value with a product
pub fn (m NumMatcher) times(num f64) NumMatcher {
return number(m.value * num)
}
// divides Instanitiate a matcher with a new value with a division
pub fn (m NumMatcher) divides(num f64) NumMatcher {
return number(m.value / num)
}
struct StrMatcher {
value string
can_spell SpellMatcher
//anagram_of AnagramMatcher
backwards BackwardsMatcher
atomic_number AtomicMatcher
}
// str Instanitiate a matcher for string type
pub fn str(value string) StrMatcher {
return StrMatcher{
value: value,
can_spell: SpellMatcher{value},
//anagram_of: AnagramMatcher{value},
backwards: BackwardsMatcher{value},
atomic_number: AtomicMatcher{value},
}
}
// thirteen check whether the string is 13 in base 10 or is one of thirteen_strs
pub fn (m StrMatcher) thirteen() bool {
if m.value in thirteen_strs {
return true
}
return m.value.int() == thirteen
}
// base instanitiate a number matcher with a new value of base b
pub fn (m StrMatcher) base(b int) NumMatcher {
return number(f64(m.value.int()))
}
struct RoughlyMatcher {
value f64
}
// thirteen check if the number is roughly Thirteen
pub fn (m RoughlyMatcher) thirteen() bool {
return math.round(m.value) == thirteen
}
struct InvertedMatcher {
value f64
}
// thirteen check if the number is not Thirteen
pub fn (m InvertedMatcher) thirteen() bool {
return m.value != thirteen
}
struct DivMatcher {
value f64
}
// thirteen check if the number is divisible by Thirteen
pub fn (m DivMatcher) thirteen() bool {
return math.fmod(m.value, 13) == 0
}
struct SqMatcher {
value f64
}
// thirteen check if the number is square of thirteen
pub fn (m SqMatcher) thirteen() bool {
return m.value == thirteen*thirteen
}
struct GreaterMatcher {
value f64
}
// thirteen check if the number is greater than thirteen
pub fn (m GreaterMatcher) thirteen() bool {
return m.value > thirteen
}
struct LessMatcher{
value f64
}
// thirteen check if the number is less than thirteen
pub fn (m LessMatcher) thirteen() bool {
return m.value < thirteen
}
struct WithinMatcher {
value f64
num_range f64
}
// thirteen check if the number is within a range of Thirteen
pub fn (m WithinMatcher) thirteen() bool {
return m.value > (thirteen-m.num_range) && m.value < (thirteen+m.num_range)
}
struct BirthMatcher {
value f64
//real RealClock
}
/*
struct RealClock{}
fn (RealClock) now() time.Time { return time.Now() }
// Thirteen Check if person with this year of birth is Thirteen year-old
fn (m BirthMatcher) thirteen() bool {
return m.value-f64(time.now().year()) == 13
}
*/
struct SpellMatcher {
value string
}
// thirteen check if a string has enough character to spells Thirteen
pub fn (m SpellMatcher) thirteen() bool {
return has_chars(m.value, {"t": 2, "h": 1, "i": 1, "r": 1, "e": 2, "n": 1})
}
/*
struct AnagramMatcher{
value string
}
fn (m AnagramMatcher) is_anagram(str string) bool {
if m.value.len != str.len {
return false
}
return m.value.bytes() == str.bytes()
}
fn sort_byte(arr mut []byte) {
for j := 0; j < arr.len - 1; j++ {
for i := j + 1; i < n; i++ {
if arr[j] > arr[i] {
arr[j], arr[i] = arr[i], arr[j]
}
}
}
// thirteen Check if a string is an anagram of Thirteen
fn (m AngramMatcher) thirteen() bool {
return anagram.AreAnagram(strings.ToLower(m.value), "thirteen")
}
*/
struct BackwardsMatcher {
value string
}
// thirteen check if a string is thirteen spelled backwards
pub fn (m BackwardsMatcher) thirteen() bool {
return m.value.to_lower().reverse() == "thirteen"
}
struct AtomicMatcher {
value string
}
// thirteen check if the string can spell Aluminum - the 13th chemical element
pub fn (m AtomicMatcher) thirteen() bool {
return has_chars(m.value, {"a": 1,"l": 1,"u": 2,"m": 2,"i": 1,"n": 1})
}
fn has_chars(s string, occurr_count map[string]int) bool {
for ch, count in occurr_count {
if s.to_lower().count(ch) < count {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment