tromars@feddit.de to Programmer Humor@lemmy.ml · 1 year agoIdeas for programming rizz?i.imgur.comexternal-linkmessage-square244fedilinkarrow-up12.07Karrow-down139
arrow-up12.04Karrow-down1external-linkIdeas for programming rizz?i.imgur.comtromars@feddit.de to Programmer Humor@lemmy.ml · 1 year agomessage-square244fedilink
minus-squarenickwitha_k (he/him)@lemmy.sdf.orglinkfedilinkarrow-up10arrow-down2·edit-21 year agovar LogicGate = map[string]string{ "OR": "OR", "AND": "AND", "NOT": "NOT", "NOR": "NOR", "NAND": "NOR", "XOR": "XOR", } func isLogicGate(inString string) (bool) { _, ok := LogicGate[strings.ToUpper(inString)] if ok { return true } else { return false } } func stringAsGateLogic(inString string) (bool, error) { inSplit := strings.Split(inString, " ") var phrase1 strings.Builder var phrase2 stringa.Builder var gateString string for word := range inSplit { if isLogicGate(word) { if len(gateString) < 1{ gateString = word } else { phrase2.WriteString(word) } } else { if len(gateString) < 1{ phrase1.WriteString(word) } else { phrase2.WriteString(word) } } } boolPhrase1 := bool(phrase1.String()) boolPhrase2 := bool(phrase2.String()) switch strings.ToUpper(gateString) { case "OR": return (boolPhrase1 || boolPhrase2), nil case "AND": return (boolPhrase1 && boolPhrase2), nil case "NOT": return (!boolPhrase2), nil case "NOR": return (!(boolPhrase1 || boolPhrase2)), nil case "NAND": return (!(boolPhrase1 && boolPhrase2) case "XOR": orRes := (boolPhrase1 || boolPhrase2) nandRes := (!(boolPhrase1 && boolPhrase2)) return (orRes && nandRes), nil default: return false, fmt.Errorf("Why you do dis?: %v", inString) } } func main(){ answer, err := stringAsGateLogic ("This person misunderstands a beautiful function code can be very sexy or maybe I'm a odd girl.") if err != nil { fmt.Println(err) } fmt.Println(answer) }
minus-squaredeegeese@sopuli.xyzlinkfedilinkarrow-up13·1 year agoSorry, Hungarian notation is not beautiful.
minus-squareqaz@lemmy.worldlinkfedilinkarrow-up6·1 year agoif ok { return true } else { return false } Why?
minus-squarenickwitha_k (he/him)@lemmy.sdf.orglinkfedilinkarrow-up4·1 year agoIdiomatic Go way of checking for the presence of a key in a map.
minus-squarewallmenis@lemmy.onelinkfedilinkEnglisharrow-up3·1 year agoisLogicGate is not used. Maybe you mean to place it in “isGate” in the stringAsGateLogic for loop’s if statement?
minus-squarenickwitha_k (he/him)@lemmy.sdf.orglinkfedilinkarrow-up6·1 year agoThank you. That’s what I get for writing a drawn-out shitpost program on my phone over several hours while away from home, instead of in a few minutes in vim.
minus-squareQuazarOmega@lemy.lollinkfedilinkarrow-up3·1 year agoYou make want to cry, when are we marrying? I want a divorce
minus-squarenickwitha_k (he/him)@lemmy.sdf.orglinkfedilinkarrow-up2·1 year agoSorry, merge conflict :(
var LogicGate = map[string]string{ "OR": "OR", "AND": "AND", "NOT": "NOT", "NOR": "NOR", "NAND": "NOR", "XOR": "XOR", } func isLogicGate(inString string) (bool) { _, ok := LogicGate[strings.ToUpper(inString)] if ok { return true } else { return false } } func stringAsGateLogic(inString string) (bool, error) { inSplit := strings.Split(inString, " ") var phrase1 strings.Builder var phrase2 stringa.Builder var gateString string for word := range inSplit { if isLogicGate(word) { if len(gateString) < 1{ gateString = word } else { phrase2.WriteString(word) } } else { if len(gateString) < 1{ phrase1.WriteString(word) } else { phrase2.WriteString(word) } } } boolPhrase1 := bool(phrase1.String()) boolPhrase2 := bool(phrase2.String()) switch strings.ToUpper(gateString) { case "OR": return (boolPhrase1 || boolPhrase2), nil case "AND": return (boolPhrase1 && boolPhrase2), nil case "NOT": return (!boolPhrase2), nil case "NOR": return (!(boolPhrase1 || boolPhrase2)), nil case "NAND": return (!(boolPhrase1 && boolPhrase2) case "XOR": orRes := (boolPhrase1 || boolPhrase2) nandRes := (!(boolPhrase1 && boolPhrase2)) return (orRes && nandRes), nil default: return false, fmt.Errorf("Why you do dis?: %v", inString) } } func main(){ answer, err := stringAsGateLogic ("This person misunderstands a beautiful function code can be very sexy or maybe I'm a odd girl.") if err != nil { fmt.Println(err) } fmt.Println(answer) }
Sorry, Hungarian notation is not beautiful.
Fair.
if ok { return true } else { return false }
Why?
Idiomatic Go way of checking for the presence of a key in a map.
isLogicGate is not used. Maybe you mean to place it in “isGate” in the stringAsGateLogic for loop’s if statement?
Thank you. That’s what I get for writing a drawn-out shitpost program on my phone over several hours while away from home, instead of in a few minutes in vim.
You make want to cry, when are we marrying?
I want a divorce
Sorry, merge conflict :(