Created
March 3, 2017 01:41
-
-
Save unixpickle/751c06edc413f8535837e1942f294019 to your computer and use it in GitHub Desktop.
idiom stitching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Produces hilarious quasi-idioms, like: | |
// | |
// add insult to the drawing board | |
// every cloud has a dead horse | |
// an arm and a blue moon | |
// an arm and a dead horse | |
// take with a grain of one's pants | |
// get bent out of both worlds | |
// have eyes in the room | |
// it takes two to the choir | |
// don't have a blue moon | |
// kill two birds with one can chew | |
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"reflect" | |
"strings" | |
"time" | |
) | |
const ( | |
MinStitchWords = 3 | |
) | |
var IgnoreWords = map[string]bool{"the": true} | |
func main() { | |
rand.Seed(time.Now().UnixNano()) | |
toks := tokenizedIdioms() | |
for { | |
idiom1 := toks[rand.Intn(len(toks))] | |
idiom2 := toks[rand.Intn(len(toks))] | |
if reflect.DeepEqual(idiom1, idiom2) { | |
continue | |
} | |
s := stitchings(idiom1, idiom2) | |
if len(s) > 0 { | |
comb := s[rand.Intn(len(s))] | |
fmt.Println(strings.Join(comb, " ")) | |
} | |
} | |
} | |
func tokenizedIdioms() [][]string { | |
var res [][]string | |
for _, line := range idioms { | |
res = append(res, strings.Fields(line)) | |
} | |
return res | |
} | |
func stitchings(a, b []string) [][]string { | |
var res [][]string | |
for i, x := range a { | |
if i < MinStitchWords-1 || IgnoreWords[x] { | |
continue | |
} | |
for j, y := range b { | |
if len(b)-j < MinStitchWords { | |
continue | |
} | |
if y == x { | |
res = append(res, append(append([]string{}, a[:i]...), b[j:]...)) | |
} | |
} | |
} | |
return res | |
} | |
var idioms = []string{ | |
"a bitter pill", | |
"a dime a dozen", | |
"ace in the hole", | |
"achilles' heel", | |
"actions speak louder than words", | |
"add insult to injury", | |
"all ears", | |
"all thumbs", | |
"an arm and a leg", | |
"apple of discord", | |
"at the drop of a hat", | |
"back to the drawing board", | |
"ball is in your court", | |
"balls to the wall!", | |
"barking up the wrong tree", | |
"basket case", | |
"beat around the bush", | |
"beat a dead horse", | |
"bed of roses", | |
"best of both worlds", | |
"bite off more than one can chew", | |
"bite the bullet", | |
"bite the dust", | |
"break a leg", | |
"burn the midnight oil", | |
"bust one's chops", | |
"by the seat of one's pants", | |
"by the skin of one's teeth", | |
"call it a day", | |
"cat nap", | |
"chalk up", | |
"champ at the bit or chomp at the bit", | |
"cheap as chips", | |
"chew the fat", | |
"chink in one's armor", | |
"clam up", | |
"cold shoulder", | |
"couch potato", | |
"crocodile tears", | |
"cut a rug", | |
"cut the cheese", | |
"cut the mustard", | |
"don't have a cow", | |
"don't count chickens before they hatch", | |
"don't give up your day job", | |
"drop a dime", | |
"elephant in the room", | |
"every cloud has a silver lining", | |
"fit as a fiddle", | |
"for a song", | |
"from a to z", | |
"from scratch / to make from scratch", | |
"get bent out of shape", | |
"grasp the nettle", | |
"grass is always greener on the other side", | |
"have a blast", | |
"have eyes in the back of one's head", | |
"heard it through the grapevine", | |
"hit the nail on the head", | |
"hit the road", | |
"hit the sack", | |
"hit the sheets", | |
"hit the hay", | |
"i bet", | |
"ignorance is bliss", | |
"it takes two to tango", | |
"jump ship", | |
"kick the bucket", | |
"kill two birds with one stone", | |
"let the cat out of the bag", | |
"method to my madness", | |
"no horse in this race", | |
"off one's rocker", | |
"off the hook", | |
"once in a blue moon", | |
"piss in one's cornflakes", | |
"pop one's clogs (uk)", | |
"piece of cake", | |
"preaching to the choir", | |
"pull somebody's leg", | |
"pushing up daisies", | |
"put the cat among the pigeons", | |
"raining cats and dogs", | |
"right as rain", | |
"screw the pooch", | |
"shoot the breeze", | |
"shooting fish in a barrel", | |
"sleep with the fishes", | |
"spill the beans", | |
"spin one's wheels", | |
"split the whistle", | |
"sunny smile", | |
"take the cake", | |
"take with a grain of salt", | |
"throw under the bus", | |
"through thick and thin", | |
"thumb one's nose", | |
"tie one on", | |
"to steal someone's thunder", | |
"trip the light fantastic", | |
"under my thumb", | |
"under the weather", | |
"the whole nine yards", | |
"wild goose chase", | |
"you bet", | |
"x marks the spot", | |
"you can say that again", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment