C#, 174 172 147 bytes
Saved 25 bytes by "borrowing" some ideas from raznagul's C# answer and merging them with the sum of first n numbers trick!
Saved 2 bytes by using the sum of first n numbers trick for a loss of precision of 185 milliseconds.
class P{static void Main(){for(int i=1;;){System.Console.WriteLine(i++<731?"Not ready yet":"Eat your hot dog");System.Threading.Thread.Sleep(i);}}}
Ungolfed program:
class P
{
static void Main()
{
for (int i=1;;)
{
System.Console.WriteLine( i++ < 731 ? "Not ready yet" : "Eat your hot dog");
System.Threading.Thread.Sleep(i);
}
}
}
Explanation:
Since the total time to wait is hardcoded at 267 seconds, one can consider this number as a telescopic sum of the first n natural numbers, n * (n + 1) / 2
, which must equal 267000 milliseconds.
This is equivalent to n^2 + n - 534000 = 0
.
By solving this second order equation, n1 = 730.2532073142067
, n2 = -n1
. Of course, only the positive solution is accepted and can be approximated as 730.
The total time can be calculated as 730 * (730 + 1) / 2 = 266815 milliseconds
. The imprecision is 185 milliseconds, imperceptible to humans.
The code will now make the main (and only) thread sleeps for 1 millisecond, 2 milliseconds and so on up to 730, so the total sleep period is ~267 seconds.
Update:
The program's logic can be simplified further - basically it needs to continuously display a message and wait a specified time until switching to the second message.
The message can be change by using a ternary operator to check the passing of the specified time (~267 seconds).
The timing aspect is controlled by using an increasing counter and pausing the execution thread.
However, since the counter variable continues increasing indefinitely without any conditions to check its value, one can expect an integer overflow at some point, when the message reverts to Not ready yet
.
A condition can be added to detect and mitigate the issue by assigning a positive value greater than 730 when the overflow occurs - like i=i<1?731:i
inside the for
loop. Sadly, it comes at the cost of 11 additional bytes:
class P{static void Main(){for(int i=1;;i=i<1?731:i){System.Console.Write(i++<731?"\nNot ready yet":"\nEat your hot dog");System.Threading.Thread.Sleep(i);}}}
Ключевым моментом здесь является использование значения счетчика в миллисекундах, чтобы значительно задержать момент переполнения.
Время до переполнения можно рассчитать по sum(1..n)
формуле, где n = максимальное 32-разрядное целое число со знаком в C # (и .NET Framework) или 2 ^ 31 - 1 = 2147483647:
2 147 483 647 * 2 147 483 648 / 2 = 2,305843008 x 10^18 milliseconds = 2,305843008 x 10^15 seconds = 26 687 997 779 days = ~73 067 755 years
Через 73 миллиона лет может не иметь значения, если в системе появится сбой - хот-дог, голодный ОП и, возможно, сама человеческая раса давно исчезли.
Предыдущая версия (172 байта):
namespace System{class P{static void Main(){for(int i=1;i<731;){Console.Write("\nNot ready yet");Threading.Thread.Sleep(i++);}for(;;)Console.Write("\nEat your hot dog");}}}
Нежелтая программа:
namespace System
{
class P
{
static void Main()
{
for (int i = 1; i < 731; )
{
Console.Write("\nNot ready yet");
Threading.Thread.Sleep(i++);
}
for ( ; ; )
Console.Write("\nEat your hot dog");
}
}
}
Предыдущая версия (174 байта):
namespace System{class P{static void Main(){for(int i=0;i++<267e3;){Console.Write("\nNot ready yet");Threading.Thread.Sleep(1);}for(;;)Console.Write("\nEat your hot dog");}}}
Нежелтая программа:
namespace System
{
class P
{
static void Main()
{
for (int i=0; i++ < 267e3; )
{
Console.Write("\nNot ready yet");
Threading.Thread.Sleep(1);
}
for ( ; ; )
Console.Write("\nEat your hot dog");
}
}
}
Кроме того, программа может отображать Not ready yet
только один раз, подождать, пока не истечет указанное время, и затем вывести Eat your hot dog
ее, переписав предыдущее сообщение, в то время как оно на несколько байт короче:
C #, 145 байт
namespace System{class P{static void Main(){Console.Write("Not ready yet");Threading.Thread.Sleep(267000);Console.Write("\rEat your hot dog");}}}
Нежелтая программа:
namespace System
{
class P
{
static void Main()
{
Console.Write("Not ready yet");
Threading.Thread.Sleep(267000);
Console.Write("\rEat your hot dog");
}
}
}