September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
1
Task/Nautical-bell/00META.yaml
Normal file
1
Task/Nautical-bell/00META.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
--- {}
|
||||
20
Task/Nautical-bell/AutoHotkey/nautical-bell-1.ahk
Normal file
20
Task/Nautical-bell/AutoHotkey/nautical-bell-1.ahk
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
NauticalBell(hh, mm){
|
||||
Hr := 0, min := 30, Bells := [], pattern := []
|
||||
Loop 8 ; genrate 8 patterns
|
||||
{
|
||||
num := A_Index , code := ""
|
||||
while (num/2 >=1)
|
||||
code .= "** ", num := num-2
|
||||
code .= mod(A_Index, 2) ? "*" : ""
|
||||
pattern[A_Index] := code
|
||||
}
|
||||
loop, 48 ; 24 hours * 2 for every half an hour
|
||||
{
|
||||
numBells := !mod(A_Index, 8) ? 8 : mod(A_Index, 8) , min := 30
|
||||
if !Mod(A_Index, 2)
|
||||
hr++ , min := 00
|
||||
Bells[SubStr("0" hr, -1) ":" min] := numBells
|
||||
}
|
||||
Bells[00 ":" 00] := Bells[24 ":" 00] , numBells := Bells[hh ":" mm]
|
||||
return {"bells": numBells, "pattern": Pattern[numBells]}
|
||||
}
|
||||
13
Task/Nautical-bell/AutoHotkey/nautical-bell-2.ahk
Normal file
13
Task/Nautical-bell/AutoHotkey/nautical-bell-2.ahk
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
res := ""
|
||||
loop, 24
|
||||
{
|
||||
hr := SubStr("0" A_Index -1, -1)
|
||||
Loop 60
|
||||
{
|
||||
min := SubStr("0" A_Index -1, -1)
|
||||
if (min = 0 || min = 30)
|
||||
res .= hr ":" min "`t" NauticalBell(hr, min).bells "`t" NauticalBell(hr, min).pattern "`n"
|
||||
}
|
||||
}
|
||||
MsgBox, 262144, , % "Time`tBells`tPattern`n" res
|
||||
return
|
||||
47
Task/Nautical-bell/Go/nautical-bell.go
Normal file
47
Task/Nautical-bell/Go/nautical-bell.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
watches := []string{
|
||||
"First", "Middle", "Morning", "Forenoon",
|
||||
"Afternoon", "Dog", "First",
|
||||
}
|
||||
for {
|
||||
t := time.Now()
|
||||
h := t.Hour()
|
||||
m := t.Minute()
|
||||
s := t.Second()
|
||||
if (m == 0 || m == 30) && s == 0 {
|
||||
bell := 0
|
||||
if m == 30 {
|
||||
bell = 1
|
||||
}
|
||||
bells := (h*2 + bell) % 8
|
||||
watch := h/4 + 1
|
||||
if bells == 0 {
|
||||
bells = 8
|
||||
watch--
|
||||
}
|
||||
sound := strings.Repeat("\a", bells)
|
||||
pl := "s"
|
||||
if bells == 1 {
|
||||
pl = " "
|
||||
}
|
||||
w := watches[watch] + " watch"
|
||||
if watch == 5 {
|
||||
if bells < 5 {
|
||||
w = "First " + w
|
||||
} else {
|
||||
w = "Last " + w
|
||||
}
|
||||
}
|
||||
fmt.Printf("%s%02d:%02d = %d bell%s : %s\n", sound, h, m, bells, pl, w)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
41
Task/Nautical-bell/Julia/nautical-bell.julia
Normal file
41
Task/Nautical-bell/Julia/nautical-bell.julia
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using Dates
|
||||
|
||||
"""
|
||||
nauticalbells(DateTime)
|
||||
|
||||
Return a string according to the "simpler system" of nautical bells
|
||||
listed in the table in Wikipedia at
|
||||
en.wikipedia.org/wiki/Ship%27s_bell#Simpler_system.
|
||||
Note the traditional time zone was determined by local sun position
|
||||
and so should be local time without daylight savings time.
|
||||
"""
|
||||
function nauticalbells(dt::DateTime)
|
||||
hr = hour(dt)
|
||||
mn = minute(dt)
|
||||
if hr in [00, 12, 4, 8, 16, 20]
|
||||
return mn == 00 ? "2 2 2 2" : "1"
|
||||
elseif hr in [1, 5, 9, 13, 17, 21]
|
||||
return mn == 00 ? "2" : "2 1"
|
||||
elseif hr in [2, 6, 10, 14, 18, 22]
|
||||
return mn == 00 ? "2 2" : "2 2 1"
|
||||
elseif hr in [3, 7, 11, 15, 19, 23]
|
||||
return mn == 00 ? "2 2 2" : "2 2 2 1"
|
||||
else
|
||||
return "Gong pattern error: time $dt, hour $hr, minutes $mn"
|
||||
end
|
||||
end
|
||||
|
||||
function nauticalbelltask()
|
||||
untilnextbell = ceil(now(), Dates.Minute(30)) - now()
|
||||
delay = untilnextbell.value / 1000
|
||||
println("Nautical bell task starting -- next bell in $delay seconds.")
|
||||
# The timer wakes its task every half hour. May drift very slightly so restart yearly.
|
||||
timer = Timer(delay; interval=1800)
|
||||
while true
|
||||
wait(timer)
|
||||
gong = nauticalbells(now())
|
||||
println("Nautical bell gong strikes ", gong)
|
||||
end
|
||||
end
|
||||
|
||||
nauticalbelltask()
|
||||
44
Task/Nautical-bell/Perl/nautical-bell.pl
Normal file
44
Task/Nautical-bell/Perl/nautical-bell.pl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use utf8;
|
||||
binmode STDOUT, ":utf8";
|
||||
use DateTime;
|
||||
|
||||
$| = 1; # to prevent output buffering
|
||||
|
||||
my @watch = <Middle Morning Forenoon Afternoon Dog First>;
|
||||
my @ordinal = <One Two Three Four Five Six Seven Eight>;
|
||||
|
||||
my $thishour;
|
||||
my $thisminute = '';
|
||||
|
||||
while () {
|
||||
my $utc = DateTime->now( time_zone => 'UTC' );
|
||||
if ($utc->minute =~ /^(00|30)$/ and $utc->minute != $thisminute) {
|
||||
$thishour = $utc->hour;
|
||||
$thisminute = $utc->minute;
|
||||
bell($thishour, $thisminute);
|
||||
}
|
||||
printf "%s%02d:%02d:%02d", "\r", $utc->hour, $utc->minute, $utc->second;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
sub bell {
|
||||
my($hour, $minute) = @_;
|
||||
|
||||
my $bells = (($hour % 4) * 2 + int $minute/30) || 8;
|
||||
printf "%s%02d:%02d%9s watch,%6s Bell%s Gone: \t", "\b" x 9, $hour, $minute,
|
||||
$watch[(int($hour/4) - (0==($minute + $hour % 4)) + 6) % 6],
|
||||
$ordinal[$bells - 1], $bells == 1 ? '' : 's';
|
||||
chime($bells);
|
||||
}
|
||||
|
||||
sub chime {
|
||||
my($count) = shift;
|
||||
for (1..int($count/2)) {
|
||||
print "\a♫ "; sleep .25;
|
||||
print "\a"; sleep .75;
|
||||
}
|
||||
if ($count % 2) {
|
||||
print "\a♪"; sleep 1;
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue