Xah Talk Show 2019-12-21 EmTime system/notation. Live coding golang. convert 24h time system to 36h system with base 6 notation

EmTime system/notation. Live coding golang. convert 24h time system to 36h system with base 6 notation. 2019-12-21
emily heximal watch 2019-11-17 g94fc
emily heximal watch [happy hacking emily lisp server]

problem: given a time in 24h notation, convert to EmTime system/notation.

EmTimeSystem: a day is divided into 36 emHour, each emHour is divided into 36 emMin, and each is 36 EmSecs. But the notation of EmTimeSystem, must be written in base 6.

write a function, that takes a string of the form "hh:mm:ss" that is 24hour clock, the function returns a string of the form "hh:mm:ss", where the output is em time, where hh ranges from 0 to 35, but is in heximal number notation (where digits are 0 to 5 only). Similar for mm and ss.

your code must follow this format.

live coding

in live stream am gonna explain the problem, and explain how to convert number system notation. and live coding it, in one of emacs lisp, JavaScript, or golang. (type in YouTube chat to let me know which you prefer)

The following is incomplete

package main

// EmTime system/notation. Live coding golang. convert 24h time system to 36h system with base 6 notation. 2019-12-21
// http://xahlee.info/talk_show/xah_talk_show_2019-12-21.html

// by xahlee

import "fmt"
import "strings"
import "strconv"

// import "math"

// emTime takes a input of this format "13:01:01" and return a string that is em time system
func emTime(time24 string) string {
	// algorithm
	// first find out what is the total number of seconds
	// and find out what is the total number of seconds in em system

	var totalSecs = 24 * 60 * 60   // 86400
	var totalEmSecs = 36 * 36 * 36 // 46656

	var hhmmssSlice = strings.Split(time24, ":")

	var hh = hhmmssSlice[0]
	var mm = hhmmssSlice[1]
	var ss = hhmmssSlice[2]

	var hhNum, err1 = strconv.ParseInt(hh, 10, 64)
	var mmNum, err2 = strconv.ParseInt(mm, 10, 64)
	var ssNum, err3 = strconv.ParseInt(ss, 10, 64)

	if err1 != nil {
		panic(err1)
	}
	if err2 != nil {
		panic(err2)
	}
	if err3 != nil {
		panic(err3)
	}

	var totalSecsNow = hhNum*60*60 + mmNum*60 + ssNum

	var emSecsNow = int64(float64(totalSecsNow) / float64(totalSecs) * float64(totalEmSecs))

	var emH = emSecsNow / (36 * 36)
	// var emM = (emSecsNow % (36 * 36)) / 36
	// var emS = (emSecsNow % (36 * 36)) % 36

	// todo. need to convert to base 6

	return fmt.Sprintf("%v:xx:xx", emH )

}

func main() {

	fmt.Printf("%#v\n", emTime("10:00:00"))
	fmt.Printf("%#v\n", emTime("16:00:00"))

}

Solutions

reference implementation. emacs lisp emtime_emily.el

;; 2019-12-21
;; by emily
;; added interactive optional arg, by xl

(defun emi/sen (&optional time24h)
  "convert 24h time to 36h system and display base 6 number notation. emily's time system"
  (interactive)
  (labels ((emi/rem-mod (x y) (list (mod x y) (floor (/ x y)))))
    (let* ((Time
            (split-string
             (concat
              (if time24h
                  time24h
                (read-from-minibuffer "Time: "))) ":"))
           (num '("00" "01" "02" "03" "04" "05" "10" "11" "12" "13" "14" "15" "20" "21" "22" "23" "24" "25" "30" "31" "32" "33" "34" "35" "40" "41" "42" "43" "44" "45" "50" "51" "52" "53" "54" "55"))
           (message Time)
           (hou (string-to-number (first Time)))
           (min (string-to-number (second Time)))
           (sec (string-to-number (third Time)))
           (cur (+ (* sec 1000000000)
                   (* min 60 1000000000)
                   (* hou 60 60 1000000000)))
           (ful (* 60 60 24 1000000000))
           (h-sec (cadr (emi/rem-mod cur (/ ful (* 36 36 36 36)))))
           (p-hou (emi/rem-mod h-sec (* 36 36 36)))
           (p-min (emi/rem-mod (car p-hou) (* 36 36)))
           (p-sec (emi/rem-mod (car p-min) 36)))
      (message (format "%s:%s:%s"
                       (nth (cadr p-hou) num)
                       (nth (cadr p-min) num)
                       (nth (cadr p-sec) num))))))

(emi/sen "00:00:00")
;; "00:00:00"

(emi/sen "00:00:30")
;; "00:00:24"

(emi/sen "00:01:00")
;; "00:00:52"

(emi/sen "00:30:00")
;; "00:43:00"

(emi/sen "01:00:00")
 ;; "01:30:00"

(emi/sen "12:00:00")
;; "30:00:00"

(emi/sen "13:00:00")
;; "31:30:00"

(emi/sen "13:14:15")
;; "31:50:45"

(emi/sen "16:00:00")
;; "40:00:00"

ruby

# EmTime system/notation. Live coding golang. convert 24h time system to 36h system with base 6 notation. 2019-12-21
# http://xahlee.info/talk_show/xah_talk_show_2019-12-21.html

# by George

require 'time'

def emtime(time_str)
  time = Time.parse(time_str)
  emtime_int = (fraction_of_day(time) * 46_656).to_i
  emtime_senary = emtime_int.to_s(6).rjust(6, '0')
  hour, minute, second = emtime_senary[0..1], emtime_senary[2..3], emtime_senary[4..5]
  present_time(hour, minute, second)
end

def present_time(hour, min, sec)
  [hour, min, sec]
    .map { |n| n.to_s.rjust(2, '0') }
    .join(':')
end

def fraction_of_day(time)
  day_start = Time.new(time.year, time.month, time.day, 0, 0, 0).to_r
  day_end = Time.new(time.year, time.month, time.day, 23, 59, 59).to_r
  (time.to_r - day_start) / (day_end - day_start)
end

puts " Normies  | Emily    "
puts "----------+----------"
now = Time.now
t = present_time(now.hour, now.min, now.sec)
puts " #{t} | #{emtime(t)} "
12.times.with_index do |i|
  t = present_time(i * 2, i * 5, i * 5)
  puts " #{t} | #{emtime(t)} "
end

#  Normies  | Emily
# ----------+----------
#  00:05:06 | 00:04:33
#  00:00:00 | 00:00:00
#  02:05:05 | 03:04:32
#  04:10:10 | 10:13:05
#  06:15:15 | 13:21:42
#  08:20:20 | 20:30:14
#  10:25:25 | 23:34:51
#  12:30:30 | 30:43:24
#  14:35:35 | 33:52:01
#  16:40:40 | 41:00:33
#  18:45:45 | 44:05:10
#  20:50:50 | 51:13:43
#  22:55:55 | 54:22:20

p emtime("13:14:15")
# 31:50:45

erlang

%% EmTime system/notation. Live coding golang. convert 24h time system to 36h system with base 6 notation. 2019-12-21
%% http://xahlee.info/talk_show/xah_talk_show_2019-12-21.html

%% by emily

-module(emtime).
-export([emtime/1]).

remMod(X, Y) ->
    {math:fmod(X, Y),
     trunc(math:floor(X / Y))}.

toBase6(Value) ->
    element(Value + 1,
            {"00", "01", "02", "03", "04", "05",
             "10", "11", "12", "13", "14", "15",
             "20", "21", "22", "23", "24", "25",
             "30", "31", "32", "33", "34", "35",
             "40", "41", "42", "43", "44", "45",
             "50", "51", "52", "53", "54", "55"}).

display({Rem, Mod}) ->
    toBase6(Mod).

emtime(CurrentTime) ->
    [Hour, Minute, Second] = [list_to_integer(X) || X <- string:lexemes(CurrentTime, ":")],
    Percent =
        (Second * 1000000000) +
        (Minute * 1000000000 * 60) +
        (Hour * 1000000000 * 60 * 60),
    Total = 60 * 60 * 24 * 1000000000,
    {_, Secs} = remMod(Percent, (Total / (36 * 36 * 36 * 36))),
    EmHour = remMod(Secs, 36 * 36 * 36),
    EmMinute = remMod(element(1, EmHour), 36 * 36),
    EmSecond = remMod(element(1, EmMinute), 36),
    io:format("~p~n", [display(EmHour) ++ ":"
                       ++ display(EmMinute) ++ ":"
                       ++ display(EmSecond)]).

%$ erl
%1> c("emtime").
%2> emtime:emtime("23:23:23").
%"55:03:01"

JavaScript

JavaScript [2019-12-21 https://captainalan.github.io/36-time/ ]

misc

here's cobol

      ******************************************************************
      * Author: Sezen
      * Date:   12/23/2019
      ******************************************************************
      * OUTPUTS:
      * STANDARD TIME: 15:55:15
      * EMILY TIME:    35:51:42
      ******************************************************************
      * MORE ON EMILY TIME:
      * http://xahlee.info/kbd/happy_hacking_emily.html
      ******************************************************************
       IDENTIFICATION DIVISION.
       PROGRAM-ID. EMTIME-CONVERTER.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
            FUNCTION ALL INTRINSIC.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       01   WS-STANDARD-TIME.
            05   WS-STANDARD-HOUR   PIC 99.
                 88   HOUR-CHECK    VALUE 00 THRU 24.
            05   COL1               PIC X VALUE ':'.
            05   WS-STANDARD-MINUTE PIC 99.
                 88   MIN-CHECK     VALUE 00 THRU 59.
            05   COL2               PIC X VALUE ':'.
            05   WS-STANDARD-SECOND PIC 99.
                 88   SEC-CHECK     VALUE 00 THRU 59.
       01   WS-EM-TIME.
            05   WS-EM-HOUR         PIC 9(2).
            05                      PIC X VALUE ':'.
            05   WS-EM-MINUTE       PIC 9(2).
            05                      PIC X VALUE ':'.
            05   WS-EM-SECOND       PIC 9(2).
       01   EM-TIME-TOTAL           PIC 99999 VALUE 46656.
       01   STANDARD-TIME-TOTAL     PIC 99999 VALUE 86400.
       01   DAY-PERCENT             PIC 9V9(25).
       01   EM-DAY-VAL              PIC 99999.
       01   DAY-SECONDS             PIC 9(6).

       PROCEDURE DIVISION.
            DISPLAY 'Enter HH:MM:SS: '.
            ACCEPT WS-STANDARD-TIME.
      *     CHECK IF VALID...
            IF NOT (HOUR-CHECK AND MIN-CHECK AND SEC-CHECK AND (
      -     COL1 AND COL2 = ':'))
            THEN
               DISPLAY 'INVALID TIME ENTERED. TRY AGAIN :)'
               STOP RUN
            END-IF.
            COMPUTE DAY-SECONDS = ((WS-STANDARD-HOUR*60)*60)+(WS-STANDAR
      -     D-MINUTE*60)+WS-STANDARD-SECOND.
            COMPUTE DAY-PERCENT =  DAY-SECONDS / STANDARD-TIME-TOTAL.
            COMPUTE EM-DAY-VAL = EM-TIME-TOTAL * DAY-PERCENT.
            COMPUTE WS-EM-HOUR = (EM-DAY-VAL / (36*36)).
            COMPUTE WS-EM-MINUTE = (EM-DAY-VAL - (WS-EM-HOUR * (36 * 36
      -     ))) / 36.
            MOVE MOD(EM-DAY-VAL, 36) TO WS-EM-SECOND.
      *     CONVERT BASE-10 -> BASE-6...
            CALL 'CONV-BASE-6' USING WS-EM-HOUR.
            CALL 'CONV-BASE-6' USING WS-EM-MINUTE.
            CALL 'CONV-BASE-6' USING WS-EM-SECOND.
      *     OUTPUT TO CONSOLE
            DISPLAY 'STANDARD TIME: ', WS-STANDARD-TIME.
            DISPLAY 'EMILY TIME:    ', WS-EM-TIME.
            STOP RUN.
      *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. CONV-BASE-6.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01   WS-QUO        PIC Z(9) VALUE 1.
       01   WS-REM        PIC Z(9) VALUE 1.
       01   WS-STRING-REM REDEFINES WS-REM PIC X(9).
       01   RETURN-STR    PIC X(20).
       LINKAGE SECTION.
       01   LS-TIME PIC 9(2).
       PROCEDURE DIVISION USING LS-TIME.
            MOVE SPACES TO RETURN-STR.
            MOVE 1 TO WS-QUO.
            PERFORM UNTIL WS-QUO = SPACES
            MOVE 0 TO WS-QUO
            DIVIDE LS-TIME BY 6 GIVING WS-QUO REMAINDER WS-REM
      *     BECAUSE WE ARE USING Z, ZEROES TURN TO SPACES. REPLACE IT!
            IF WS-REM = SPACES THEN
                STRING '0',RETURN-STR INTO RETURN-STR
            ELSE
                STRING TRIM(WS-STRING-REM),RETURN-STR INTO RETURN-STR
            END-IF
            MOVE WS-QUO TO LS-TIME
            END-PERFORM.
            MOVE RETURN-STR(2:) TO RETURN-STR.
            MOVE NUMVAL(RETURN-STR) TO LS-TIME.
       END PROGRAM CONV-BASE-6.
       END PROGRAM EMTIME-CONVERTER.

C INCORRECT emtime_arwn.c

emtime crashhacker 2019-12-21 x5cnv
emtime crashhacker 2019-12-21

xah_talk_show_2019-12-21.txt