Octal Prime Numbers (challenge)

Salih Dincer salihdb at hotmail.com
Thu Jun 27 13:24:07 UTC 2024


On Tuesday, 25 June 2024 at 06:44:28 UTC, Salih Dincer wrote:
> 
> I'm not sharing the code for now because
> it's a challenge.

Since we couldn't get a code snippet, I'd like to share some 
framing code without answers:

```d
struct SumPrimes(size_t size)
{
   import std.bigint;

   auto next = BigInt(1);
   auto power = BigInt(4);
   size_t index;

   auto empty() => index > size;
   auto front() => next + power;
   auto popFront()
   {
     // ...
     index++;
   }
}

unittest
{
   for (auto p = SumPrimes!10(); !p.empty; p.popFront())
   {
     auto n = p.front();
     if (n.isPrime)
     {
       n.writef!"%11o: ";
       n.writeln(", ", p.index);
     }
   }
}
```

SDB at 79




More information about the Digitalmars-d-learn mailing list