Try implementing perfume with Go

Introduction

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".

Implement

code

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)

Commentary

Structure

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.

Conditional expression

	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 ".

bonus

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.

Afterword

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

Try implementing perfume with Go
Try implementing RBM with chainer.
Try implementing XOR with PyTorch
Try implementing Yubaba in Go language
Python with Go
Let's try gRPC with Go and Docker
Try using Dropbox API v2 with Go
Try scraping with Python.
Try SNN with BindsNET
Try regression with TensorFlow
Try implementing associative memory with Hopfield network in Python
Try implementing MetaTrader's LWMA with scipy's FIR filter function
Try implementing gRPC structured logs easily and simply with grpc_zap
Draw Bezier curves with Go
Try function optimization with Optuna
Try deep learning with TensorFlow
Operate Db2 container with Go
Try using PythonTex with Texpad.
Getting Started with Go Assembly
Try edge detection with OpenCV
Try using matplotlib with PyCharm
Try programming with a shell!
Try GUI programming with Hy
Try an autoencoder with Pytorch
Try Python output with Haxe 3.2
Try matrix operation with NumPy
Bit full search with Go
Try running CNN with ChainerRL
Try various things with PhantomJS
Hot reload with Go + Air
Try Deep Learning with FPGA
Try running Python with Try Jupyter
Try implementing Yubaba in Python 3
Try Selenium Grid with Docker
Try face recognition with Python
Try OpenCV with Google Colaboratory
Try machine learning with Kaggle
Try TensorFlow MNIST with RNN
Try building JupyterHub with Docker
Try using folium with anaconda
Implementing logistic regression with NumPy
Learn algorithms with Go @ recursive call
Try Deep Learning with FPGA-Select Cucumbers
Try scraping with Python + Beautiful Soup
Reinforcement learning 13 Try Mountain_car with ChainerRL.
GUI development with Fyne by Go
Try to operate Facebook with Python
Go see whales with combinatorial optimization
Tips for running Go with docker
Try implementing extension method in python
Try singular value decomposition with Python
Try deep learning with TensorFlow Part 2
Try http-prompt with interactive http access
Try audio signal processing with librosa-Beginner
Try face recognition with Generated Photos
Try horse racing prediction with Chainer
Try implementing k-NN on your own
Try to profile with ONNX Runtime
Upload & move GCS files with Go
I tried implementing DeepPose with PyTorch
Try machine learning with scikit-learn SVM