From e4dbf828e0a5fd73919dee750d1331ebe9fa7451 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 6 Jul 2024 11:05:16 +0200 Subject: [PATCH] =?UTF-8?q?go:=20add=20=C2=AB2582.=20Pass=20the=20Pillow?= =?UTF-8?q?=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- go/pass-the-pillow.go | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 go/pass-the-pillow.go diff --git a/go/pass-the-pillow.go b/go/pass-the-pillow.go new file mode 100644 index 0000000..2b956d3 --- /dev/null +++ b/go/pass-the-pillow.go @@ -0,0 +1,10 @@ +package main + +func passThePillow(n int, time int) int { + rounds, leftover := time/(n-1), time%(n-1) + + if rounds%2 == 0 { + return leftover + 1 + } + return n - leftover +}