diff --git a/.DS_Store b/.DS_Store index 67e11d3..2b8e4d2 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/go.mod b/go.mod index 0eee7df..fe8e41f 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,14 @@ module jaggedpill go 1.22.1 -require github.com/mroth/weightedrand/v2 v2.1.0 +require ( + github.com/mroth/weightedrand/v2 v2.1.0 + github.com/schollz/progressbar/v3 v3.18.0 +) + +require ( + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect + github.com/rivo/uniseg v0.4.7 // indirect + golang.org/x/sys v0.29.0 // indirect + golang.org/x/term v0.28.0 // indirect +) diff --git a/go.sum b/go.sum index 10f880e..69871ea 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,24 @@ +github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM= +github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/mroth/weightedrand/v2 v2.1.0 h1:o1ascnB1CIVzsqlfArQQjeMy1U0NcIbBO5rfd5E/OeU= github.com/mroth/weightedrand/v2 v2.1.0/go.mod h1:f2faGsfOGOwc1p94wzHKKZyTpcJUW7OJ/9U4yfiNAOU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA= +github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= +golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 18276af..22de39d 100644 --- a/main.go +++ b/main.go @@ -3,11 +3,13 @@ package main import ( "fmt" "github.com/mroth/weightedrand/v2" + "github.com/schollz/progressbar/v3" "io" "math/rand" "net/http" "os" "path/filepath" + "slices" "strings" "text/template" "time" @@ -67,6 +69,7 @@ func main() { var fileFolder = "html_pages" var wordTree PocketGraph = isShePervertedLikeMe() +var distances DelusionGraph = weAllHadDelusions(wordTree) // youOughtaKnow returns an HTTP handler that processes requests. func youOughtaKnow() http.Handler { @@ -381,7 +384,7 @@ func thanksForYourPatience() (string, error) { return fmt.Sprintf("Error calculating size of file folder %s: %v\n", fileFolder, err), err } - if size > 10*1024*1024 { // If the size of the folder is greater than 100 MB + if size > 10*1024*1024 { // If the size of the folder is greater than 10 MB // If the file is older than the average file age, delete it err = filepath.Walk(fileFolder, func(_ string, info os.FileInfo, err error) error { if err != nil { @@ -424,7 +427,11 @@ func isShePervertedLikeMe() PocketGraph { } // read words.txt into a list - wordsBytes, err := os.ReadFile("word_lists/longman9000.txt") + longmanBytes, err := os.ReadFile("word_lists/longman9000.txt") + jaggedLittlePillBytes, err := os.ReadFile("word_lists/jaggedlittlepill.txt") + + wordsBytes := append(longmanBytes, jaggedLittlePillBytes...) + if err != nil { fmt.Println("Error reading words.txt:", err) } @@ -458,7 +465,7 @@ func isShePervertedLikeMe() PocketGraph { // connect word to connector words? shouldConnect := rand.Intn(2) == 0 if shouldConnect { - numConnectionWords := rand.Intn(len(ConnectionWords)) + 1 // Random number of connection words between 1 and 3 + numConnectionWords := rand.Intn(2) + 1 for j := 0; j < numConnectionWords; j++ { connectionWord := ConnectionWords[rand.Intn(len(ConnectionWords))] tree[word] = append(tree[word], connectionWord) @@ -468,6 +475,50 @@ func isShePervertedLikeMe() PocketGraph { return tree } +type DelusionGraph map[string]map[string]int + +func weAllHadDelusions(m PocketGraph) DelusionGraph { + distances := make(DelusionGraph) + + bar := progressbar.Default(int64(len(m)*len(m)), "Calculating distances...") + + // Initialize distances for each word + for word := range m { + distances[word] = make(map[string]int) + for otherWord := range m { + if word == otherWord { + distances[word][otherWord] = 0 // Distance to itself is 0 + } else if slices.Contains(m[word], otherWord) { + distances[word][otherWord] = 1 // Direct connection + } + bar.Add(1) + } + } + + for word, linkedWords := range m { + for _, linkedWord := range linkedWords { + if _, exists := distances[word][linkedWord]; !exists { + distances[word][linkedWord] = 1 // Direct connection + } + for otherWord, distance := range distances[linkedWord] { + if otherWord == word { + continue // Skip self-distance + } + if _, exists := distances[word][otherWord]; !exists { + distances[word][otherWord] = distance + 1 // Update distance + } else { + // If the distance is shorter, update it + if distance+1 < distances[word][otherWord] { + distances[word][otherWord] = distance + 1 + } + } + } + } + } + + return distances +} + // forgiveMeLove generates N random words from the tree func (m PocketGraph) forgiveMeLove(n int) Words { if n <= 0 { @@ -477,18 +528,49 @@ func (m PocketGraph) forgiveMeLove(n int) Words { // Create a slice to hold the random words randomWords := make(Words, 0, n) - // Generate N random words from the tree - word := m[iWentToYourHouse(m)] // Start with a random word from the tree - for i := 0; i < n-1; i++ { - if len(word) == 0 { - break + // Pick 30% of N words out of the tree at random + numWords := int(float64(n) * 0.3) + for i := 0; i < numWords; i++ { + randomWord := iWentToYourHouse(m) + if randomWord == "" { + continue // Skip if the word is empty } - random := rand.Intn(len(word)) - nextWord := word[random] // Randomly select a word from the current word's linked words - randomWords = append(randomWords, nextWord) - word = m[nextWord] // Update the word to the next linked word + randomWords = append(randomWords, randomWord) } + // Connect the randomWords together using words that are linked to them, refering to distance + + for i := 0; i < len(randomWords) && len(randomWords) <= n; i++ { + if len(randomWords) >= n { + break + } + if len(randomWords[i]) == 0 { + continue // Skip empty words + } + // Get the linked words for the random word + wordDistances := distances[randomWords[i]] + if len(wordDistances) == 0 { + continue // Skip if there are no linked words + } + // do any of the random words link to each other? + for j := 0; j < len(randomWords); j++ { + if i == j || len(randomWords[j]) == 0 { + continue // Skip self or empty words + } + // Check if the random word links to the other random word + if distance, exists := wordDistances[randomWords[j]]; exists && distance > 0 { + // If they are linked, connect them by adding the other random word to the slice + if !slices.Contains(randomWords, randomWords[j]) { + randomWords = append(randomWords, randomWords[j]) + } + } + for linkedWord, dist := range distances[randomWords[j]] { + if dist > 0 && !slices.Contains(randomWords, linkedWord) { + randomWords = append(randomWords, linkedWord) + } + } + } + } return randomWords } diff --git a/word_lists/jaggedlittlepill.txt b/word_lists/jaggedlittlepill.txt new file mode 100644 index 0000000..e7a162f --- /dev/null +++ b/word_lists/jaggedlittlepill.txt @@ -0,0 +1,796 @@ +able +about +adored +advice +afraid +afternoon +again +air +alarmed +alive +all +alleluia +along +already +alright +am +ammunition +amount +an +and +angry +any +anymore +anyone +anyway +apart +apathy +apprehensive +appropriate +are +army +around +as +ask +ass +at +attraction +aversion +aware +away +baby +babysitter +back +back-loaded +backwards +bandage +bath +be +bear +bearer +beat +beautiful +bed +been +before +believe +bell +bend +benefits +best +better +big +bills +biting +black +bleed +blew +blind +blocks +blows +boils +both +bottle +bottom +boy +brave +braver +break +breath +broke +brothers +bruises +bug +burned +but +by +cab +calm +can +can't +care +carry +cars +case +catch +catholic +cause +caution +cds +censor +certainly +chance +chardonnay +chew +chicken +child +chill +choice +choir +choke +choose +cigarette +clears +cling +close +clothes +coaster +cologne +come +comes +comfort +coming +common +compared +concept +confessed +conflicts +confusing +consequence +consumed +corrupted +could +couldn't +counting +crashed +craziness +credit +credits +cross +crusader +cry +crying +damn +dance +danced +darkest +day +deadlines +dear +death +deeds +deeper +deliverance +delusions +den +deny +desk +did +didn't +die +died +dig +dine +dinner +direction +dissect +distraction +disturb +do +doctor +does +doesn't +doing +don't +door +down +drawer +drawers +dream +dreams +drift +drunk +dry +duplicity +dust +easier +easy +egg +eloquently +else +else's +empty +enough +envious +estella +eventually +ever +every +everything +everything's +ex +excellent +excuse +eyes +face +fade +fair +fall +falling +farther +fascinated +fast +father +fault +feel +feelings +feels +feet +fell +felt +few +figured +figures +filler +find +fine +fire +first +fish +five +flawless +flicking +flight +floor +fly +flying +focused +food +foot +for +forget +forgive +forgiven +forgot +found +fountain +fractured +free +freedom +fresh +fridge +friend +friendly +friends +frightened +from +frustrated +fuck +full +fun +fundamental +funny +gave +get +getting +girl +girls +give +giving +glass +glue +go +goes +going +golf +gone +gonna +good +goodbye +got +gotta +granted +great +green +grieve +ground +grounded +guilt +gunshot +had +hailing +half +hall +hand +handle +hands +happy +hard +harder +has +hate +have +haven't +he +head +heading +heads +healthy +hear +heart +heights +held +hello +help +helping +her +here +hey +hidden +high +him +his +hold +holds +hole +holes +home +honest +hope +hopeful +hours +house +how +humble +humbled +hungry +hunt +hunter +hurry +hurt +i +i'd +i'll +i'm +i've +idol +if +impatient +in +incense +information +inhaling +innocent +inquisition +inside +insist +insistence +intellectual +intercourse +into +ironic +is +isn't +it +it's +its +jagged +jam +jane +joke +joni +jump +jumping +just +justice +keep +kids +kill +killer +kind +kindred +kissed +knife +knock +know +laid +land +last +late +laugh +laughing +learn +learned +least +left +lend +let's +letter +life +light +like +liking +line +lip +listener +little +live +lived +living +long +look +lose +losing +lost +lottery +love +loverless +made +make +maker +malt +man +many +mary +matter +matters +may +maybe +me +meal +mean +measure +meet +meeting +melt +merely +mess +met +middle +midnight +might +mind +minds +mine +minute +minutes +mispronounced +miss +moment +money +months +more +mother +motto +mouth +mr +much +must +my +nails +naked +name +nature +need +needed +never +next +nice +nine +ninety-eight +no +not +nothing +noticed +now +obvious +occasion +of +off +oh +okay +old +older +on +one +one's +only +open +opened +or +other +oughta +our +out +over +overwhelmed +own +packed +paid +pain +pardon +past +pat +path +patience +peace +peaceful +pedestal +perfect +permission +perverted +petrified +piano +pick +pieces +pill +pity +place +plane +play-it-safe +played +playing +please +pocket +point +poor +pray +pretenses +pretty +priests +princess +problem +proud +prouder +puppet +push +put +question +quickly +quiet +quite +rain +raising +ran +rational +rays +really +reasons +receive +recommend +reel +rejected +relentless +remind +replaced +represent +resistance +responsible +restless +ride +right +ringing +robe +roller +room +rose +row +ruler +sad +said +salt +sane +sang +sat +saviors +say +scan +scratch +scream +screw +see +seem +selfish +sentimental +service +settles +shake +she +she'd +sheep +shells +shit +short +should +shouldn't +show +shower +sick +sign +silence +simply +single +sinners +sir +sit +six +skeptic +slap +smell +smile +smoke +smoking +sneak +sneaking +snow +so +sober +solely +solitary +some +someday +someone +something +sometimes +son +soon +sorry +soul +soulmate +sound +speak +speed +spiritual +spit +spite +splintered +spoons +stairs +stated +stay +sticking +still +stomach +streetcar +stress +strung +stupid +substitute +suffer +suitcase +sunday +sure +surprised +swallow +swallowed +sweater +sweeper +sweet +swimming +take +taken +talk +taste +taxi +tears +tell +ten +than +thank +thanks +that +that's +the +theatre +then +there +there's +they +thick +thing +things +think +thinking +this +thought +thousand +three-year-old +thrill +through +throw +ticket +til +time +times +tired +to +today +together +told +tonight +too +took +track +traffic +trampled +treat +trembling +trucks +try +trying +turned +two +unconditional +underestimated +underpaid +untied +until +up +upon +us +used +value +version +very +vicarious +visiting +voice +void +wait +waited +wake +walk +walked +walking +wanna +want +wanted +warm +was +wasn't +wavelength +way +ways +we +we'll +wear +wedding +week +weight +well +went +what +what's +when +where +while +whiskey +who +whole +why +wide +wife +will +win +wind +window +wine +wise +wish +with +without +womb +won +wonder +woo +word +working +worry +would +would've +wouldn't +wound +wounded +writing +wrong +yeah +yet +you +you'd +you'll +you're +you've +young +your +yours +zillionaire