This article is just a story with a fucking code that implements what I came up with on my way home from school with just momentum. If you make a mistake, don't try to study Go by looking at this.
There is a part inspired by "Implementing Yubaba in Java".
main.go
package main
import (
"fmt"
)
type human struct {
Dolce bool
Gabbana bool
Kousui perfume
}
type perfume struct {
}
func (p *perfume) say() {
fmt.Println(`I'm fluttering`)
}
func main() {
Kimi := human{true, true, perfume{}}
if Kimi.Dolce && Kimi.Gabbana {
Kimi.Kousui.say()
}
}
Here is the actual code. Since only the fmt package is used, if you can build the basic environment, you should be able to copy and paste as it is. This time, I implemented the most famous part of the song, "It's because of your Dolce & Gabbana's perfume." When implementing it, when I looked up the lyrics, there were other parts that seemed interesting to implement, so I would like to make a complete version even in my spare time (appropriate)
type human struct {
Dolce bool
Gabbana bool
Kousui perfume
}
type perfume struct {
}
The structure used this time is
There are two.
human
was used to express" you "in the lyrics.
As the name suggests, perfume
is the part of" perfume ". With this function, it was not necessary to make it a structure, but I made it a structure because I wanted to use the method explained in the next section.
if Kimi.Dolce && Kimi.Gabbana {
Kimi.Kousui.say()
}
** This is the part I wanted to implement the most. **
Since perfume
is made into a structure and a say method is added, it can be implemented as" Kimi's Dolce && Gabbana's Kousui's say ".
In this code, the values of Dolce and Gabbana are constant, so no matter how many times you execute it, the same thing will be repeated and it will be frustrated again. Therefore,
package main
import (
"fmt"
"math/rand"
)
type human struct {
Dolce bool
Gabbana bool
Kousui perfume
}
type perfume struct {
}
func (p *perfume) say() {
fmt.Println(`I'm fluttering`)
}
func main() {
Kimi := human{true, true, perfume{}}
if rand.Intn(2) == 0 {
Kimi.Dolce = false
}
if rand.Intn(2) == 0 {
Kimi.Gabbana = false
}
if Kimi.Dolce && Kimi.Gabbana {
Kimi.Kousui.say()
}
}
So I added rand.Intn (2)
and changed it to blame the perfume with a 25% chance.
Thank you for reading such a miscellaneous article so far.
This time I implemented perfume (Go water) in Go, but I thought that I could write if Dolce and Gabbana
in Python, so it may be interesting to implement it in other languages as well.
Recommended Posts