From 4f89ccfe471a725a5d081038c93841b4b3bd36d8 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 7 Dec 2021 09:06:14 +0100 Subject: [PATCH] improve by only searching halfway --- 07b.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/07b.c b/07b.c index 87ba2f0..a711578 100644 --- a/07b.c +++ b/07b.c @@ -24,17 +24,18 @@ int main() ncrabs++; } - int mindist = INT_MAX; - for (int i = minp; i<=maxp; i++) { - int dist = 0; + int lastdist = INT_MAX; + int dist = INT_MAX; + int i = minp; + do { + lastdist = dist; + dist = 0; for (int j = 0; j