From e2dc8c813b1abcf9b9c1aa2518602af9050738f3 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Wed, 30 Mar 2022 10:08:59 +0800 Subject: optimize --- challenge-158/cheok-yin-fung/dart/ch-2.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/challenge-158/cheok-yin-fung/dart/ch-2.dart b/challenge-158/cheok-yin-fung/dart/ch-2.dart index 08b2ad77b0..265cae1291 100644 --- a/challenge-158/cheok-yin-fung/dart/ch-2.dart +++ b/challenge-158/cheok-yin-fung/dart/ch-2.dart @@ -18,7 +18,8 @@ void main(List args) { while (pp <= arg) { if (pp % 5 == 0) continue; // pp must be coprime to 2 and 3. if (spokes.last <= sqrt(pp)) { - for (int k=1; k*30 <= sqrt(pp); k++) + var k = ((spokes.last+1)/30).floor(); + for (; k*30 <= sqrt(pp); k++) rp_to_30.forEach( (e) => spokes.add(e+k*30) ); } y++; -- cgit From 28e89e8ad9b1250176d0700b3a4602ea8f162fce Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Sun, 3 Apr 2022 09:51:38 +0800 Subject: further optimize --- challenge-158/cheok-yin-fung/dart/ch-2.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/challenge-158/cheok-yin-fung/dart/ch-2.dart b/challenge-158/cheok-yin-fung/dart/ch-2.dart index 265cae1291..7d425e4584 100644 --- a/challenge-158/cheok-yin-fung/dart/ch-2.dart +++ b/challenge-158/cheok-yin-fung/dart/ch-2.dart @@ -17,10 +17,9 @@ void main(List args) { spokes.add( rp_to_30[i] ); // skip 1 while (pp <= arg) { if (pp % 5 == 0) continue; // pp must be coprime to 2 and 3. - if (spokes.last <= sqrt(pp)) { + if (spokes.last < sqrt(pp)) { var k = ((spokes.last+1)/30).floor(); - for (; k*30 <= sqrt(pp); k++) - rp_to_30.forEach( (e) => spokes.add(e+k*30) ); + rp_to_30.forEach( (e) => spokes.add(e+k*30) ); } y++; if (spokes.any( (d) => pp % d == 0 )) { -- cgit