🥋 Codewars: Opposites Attract#

Some members from http://guayahack.co came up with the idea for us to practise and discuss some code katas together and I couldn’t resist.

This is a slighly over-complicated version of the problem below and a more realistic test for the new snippets plumbing I’ve built into the blog; for the sake of showing how to play a bit with the http module.

Problem#

Description#

Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.

Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren’t.

Solution#

See jdsalaro/jdsalaro.com

Execution#

It’s possible to run the opposites-attract project in several ways: building it as a standalone go binary and executing it, building and running the Docker container or using docker compose up. Use the different methods to experiment.

Standalone#
1$ go run main.go 
2
32024/05/19 21:47:21 RUNNING SERVER
42024/05/19 21:47:22 RUNNING CLIENT
52024/05/19 21:47:22 PETALS: sarah WITH 4
62024/05/19 21:47:22 PETALS: timmy WITH 5
72024/05/19 21:47:22 VERDICT: {"inLove":true}
Docker#
 1$ docker build -t tmp .; docker run -p 8080:8080 tmp
 2
 3docker build -t tmp .; docker run -p 8080:8080 tmp
 4[+] Building 3.1s (18/18) FINISHED                           docker:rancher-desktop
 5 => [internal] load build definition from Dockerfile                           0.0s
 6 => => transferring dockerfile: 381B                                           0.0s
 7 => [internal] load .dockerignore                                              0.0s
 8[...]
 9 => exporting to image                                                         0.0s
10 => => exporting layers                                                        0.0s
11 => => writing image sha256:b3bb13ee1c7b4ecb4dabd65daf70af5cf4d84bb5ec4634104  0.0s
12 => => naming to docker.io/library/tmp                                         0.0s
132024/05/19 19:46:12 RUNNING SERVER
142024/05/19 19:46:13 RUNNING CLIENT
152024/05/19 19:46:13 PETALS: timmy WITH 5
162024/05/19 19:46:13 PETALS: sarah WITH 4
172024/05/19 19:46:13 VERDICT: {"inLove":true}
Docker Compose#
 1$ docker compose up
 2
 3[+] Building 19.2s (18/18) FINISHED                          docker:rancher-desktop
 4 => [app internal] load build definition from Dockerfile                       0.0s
 5 => => transferring dockerfile: 381B                                           0.0s
 6 => [app internal] load .dockerignore                                          0.0s
 7 => => transferring context: 2B                                                0.0s
 8 => [app internal] load metadata for docker.io/library/alpine:latest           3.1s
 9[...]
10 => [app] exporting to image                                                   0.0s
11 => => exporting layers                                                        0.0s
12 => => writing image sha256:61cca6ca37b41c753fd2aa102aefcfa4a6c05ca36dd588d6f  0.0s
13 => => naming to docker.io/library/assets-app                                  0.0s
14[+] Running 2/1
15  Network assets_default  Created                                             0.2s 
16  Container assets-app-1  Created                                             0.1s 
17Attaching to app-1
18app-1  | 2024/05/19 19:31:53 RUNNING SERVER
19app-1  | 2024/05/19 19:31:54 RUNNING CLIENT
20app-1  | 2024/05/19 19:31:54 PETALS: timmy WITH 5
21app-1  | 2024/05/19 19:31:54 PETALS: sarah WITH 4
22app-1  | 2024/05/19 19:31:54 VERDICT: {"inLove":true}
23^CGracefully stopping... (press Ctrl+C again to force)
24[+] Stopping 0/1
25
26## Footnotes
27+++