Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/Nautical-bell/D/nautical-bell-1.d
Normal file
50
Task/Nautical-bell/D/nautical-bell-1.d
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import std.stdio, core.thread, std.datetime;
|
||||
|
||||
class NauticalBell : Thread {
|
||||
private shared bool stopped;
|
||||
|
||||
this() {
|
||||
super(&run);
|
||||
}
|
||||
|
||||
void run() {
|
||||
uint numBells;
|
||||
auto time = cast(TimeOfDay)Clock.currTime();
|
||||
auto next = TimeOfDay();
|
||||
|
||||
void setNextBellTime() {
|
||||
next += minutes(30);
|
||||
numBells = 1 + (numBells % 8);
|
||||
}
|
||||
|
||||
while (next < time)
|
||||
setNextBellTime();
|
||||
|
||||
while (!this.stopped) {
|
||||
time = cast(TimeOfDay)Clock.currTime();
|
||||
if (next.minute == time.minute &&
|
||||
next.hour == time.hour) {
|
||||
immutable bells = numBells == 1 ? "bell" : "bells";
|
||||
writefln("%s : %d %s", time, numBells, bells);
|
||||
setNextBellTime();
|
||||
}
|
||||
sleep(dur!"msecs"(100));
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
void stop() {
|
||||
this.stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto bells = new NauticalBell();
|
||||
bells.isDaemon(true);
|
||||
bells.start();
|
||||
try {
|
||||
bells.join();
|
||||
} catch (ThreadException e) {
|
||||
writeln(e.msg);
|
||||
}
|
||||
}
|
||||
17
Task/Nautical-bell/D/nautical-bell-2.d
Normal file
17
Task/Nautical-bell/D/nautical-bell-2.d
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Dim As Byte m = 0
|
||||
For n As Byte = 0 To 23
|
||||
If n = 23 Then
|
||||
Print " 23" + ":30" + " = " + "7 bells"
|
||||
Else
|
||||
m += 1
|
||||
Print ""; n Mod 23; ":30"; " ="; m; " bells"
|
||||
End If
|
||||
If n = 23 Then
|
||||
Print " 00" + ":00" + " = " + "8 bells"
|
||||
Else
|
||||
m += 1
|
||||
Print ""; (n Mod 23+1); ":00"; " ="; m; " bells"
|
||||
If m = 8 Then m = 0
|
||||
End If
|
||||
Next n
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue