Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created September 2, 2024 18:05
Show Gist options
  • Save unilecs/94f15271fe9cc51cd6ee3df1e1e1def5 to your computer and use it in GitHub Desktop.
Save unilecs/94f15271fe9cc51cd6ee3df1e1e1def5 to your computer and use it in GitHub Desktop.
Задача: Горячая картошка
using System;
public class Program
{
public static int HotPotato(int n, int time) {
int full = time / (n - 1);
int extra = time % (n - 1);
int direction = full % 2 == 0 ? 1 : -1;
return direction == 1 ? extra + 1 : n - extra;
}
public static void Main()
{
Console.WriteLine("UniLecs");
// tests
Console.WriteLine(HotPotato(4, 5).ToString()); // 2
Console.WriteLine(HotPotato(3, 2).ToString()); // 3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment