以ASCII格式输出当前时间


14

挑战

您的任务是输出时间(以12小时为单位)的ascii艺术。

将使用的所有字符如下:

  ___    __   ___    ____    _  _     _____     __    ______ 
 / _ \  /_ | |__ \  |___ \  | || |   | ____|   / /   |____  |
| | | |  | |    ) |   __) | | || |_  | |__    / /_       / / 
| | | |  | |   / /   |__ <  |__   _| |___ \  | '_ \     / /  
| |_| |  | |  / /_   ___) |    | |    ___) | | (_) |   / /   
 \___/   |_| |____| |____/     |_|   |____/   \___/   /_/    

   ___     ___  
  / _ \   / _ \                                _
 | (_) | | (_) |   __ _ _ __    _ __ _ __     (_)
  > _ <   \__, |  / _` | '  \  | '_ \ '  \     _ 
 | (_) |    / /   \__,_|_|_|_| | .__/_|_|_|   (_)
  \___/    /_/                 |_|          

(有关每个数字/符号,请参阅本要点)。

您将收到以下形式的数组中的输入:

  • [hours, minutes, 'am/pm']。例如,[4, 57, 'am']带单引号的仅用于上午/下午
  • "hours-minutes-am/pm"。例如,"4-56-am"
  • [hours, 'minutes', 'am/pm']无法处理数字前导零的语言。例如,[4, '07', 'am']

您可以使用任何一种输入法。

输出将采用的形式1 2 : 5 9 am,其中有一个初始空格,每个数字之间有两个空格(要点,每个数字在一边已经有一个空格),在:(冒号)和相邻数字之间有一个空格,还有一个空格在最后一个数字和之间am/pm,以及可选的前导和/或尾随换行符。所有空格都在左侧符号的最右点和右侧符号的最左点之间。

允许隐式输出。

最低字节大小为准。

am/pm要被对准,使得底部ppm与输出,即,表示undercore的顶部的其余部分的底部对齐am/pm在第三行开始向下(不计的领先行)。

冒号应对齐,使其第一个字符(下划线)从第二行向下开始(不计入换行符)。

对于minutes < 10,输出带有引号的分钟0(您应该在输入中收到)。例如,[8, 04, 'pm']-> 8 : 0 4 pm

您不得从库或外部资源中获取编号的数据。所有数据必须包含在程序中。

例如,对于input [12, 47, 'am'],输出将如下所示:

  __    ___          _  _      ______  
 /_ |  |__ \    _   | || |    |____  | 
  | |     ) |  (_)  | || |_       / /   __ _ _ __ 
  | |    / /    _   |__   _|     / /   / _` | '  \
  | |   / /_   (_)     | |      / /    \__,_|_|_|_|
  |_|  |____|          |_|     /_/     

(如果您发现任何无法决定如何处理的极端情况,请在评论中发表,我将它们添加到示例中)。




@Mego你认为吗?这个问题只是说将(任何)数字渲染为(非常)基本的ascii艺术。这个问题加强了ascii艺术,添加了am / pm和冒号,并使用混合了类型的数组指定输入。

具体来说:这个问题是时钟样式的数字。这个问题是实际时间,格式正确。

数字的不同格式以及冒号和am / pm的添加对区分imo挑战无济于事。挑战的主要部分仍然是将整数转换为ascii art。
Mego

9
@Mego我不认为这是重复的。另一个挑战是超简单的格式设置(甚至可以压缩为二进制格式)。这可能会得到更多类似于kolmogorov-complexity的答案。
PurkkaKoodari '16

Answers:


5

Perl中,592个 579 540 522 510字节

下界!

($L,$C,$b)=unpack"W/aW/aB*",q!12346677889999 _|/\)(
'<,>.` PP¨ 
¨@T @ôäð˜SÀ§€fÌU`à¨Àäð'€GÖf`3 X½`fÍ5 s Î|½`gËÖ— $¡))õ™˜À8Sô BÁªx~O àÔýåËþÏÃÆ~O‡ŸY¬Àf s 
½`À*õŸ/X8|½`p>^€<¯å­kgúºÖ·Óʸ°ªÀj® kª¸•p¸å\×   ­ô!;@c=map{$i<<=$_-$P if$_>$P;$P=$_;sprintf"%${l}b",$i++}$L=~/./g;while($b){$b=~s/^$c[$_]// and$g.=($C=~/./sg)[$_]for 0..$#c}$_=pop;s/-/:/;y/apm-/;</d;for$a(0..5){map{$o.=substr((split$/,$g)[$a],($x=-48+ord)*12,('6356766766099'=~/./g)[$x]+3)}/./g;$o.=$/}print$o

该程序期望第二种格式的时间(“ 12-34-am”)作为命令行参数。

评论:

($L,$C,$b) = unpack "W/aW/aB*",             # extract code lengths, chars, and bitstream
    q!12346677889999 _|/\)(
'<,>.` PP¨ 
¨@T @ôäð˜SÀ§€fÌU`à¨Àäð'€GÖf`3 X½`fÍ5 s Î|½`gËÖ— $¡))õ™˜À8Sô BÁªx~O àÔýåËþÏÃÆ~O‡ŸY¬Àf s 
½`À*õŸ/X8|½`p>^€<¯å­kgúºÖ·Óʸ°ªÀj® kª¸•p¸å\×   ­ô!;
@c = map {                                  # reconstruct huffman prefix codes
    $i <<= $_-$P if $_ > $P;                # increase code size
    $P = $_;                                # keep track of previous code
    sprintf "%${l}b", $i++                  # append code as bitstring
}
$L=~/./g;                                   # canonical huffman prefix lengths
while ( $b ) {                              # decompress font
        $b =~ s/^$c[$_]//                   # match and strip prefix code
        and $g .= ($C=~/./sg)[$_]           # append char for prefix code
    for 0..$#c                              # iterate prefix codes in order
}                                           # luckily we can omit checking trailing bytes    

$_ = pop;                                   # get cmdline arg "12-34-am"    
s/-/:/;                                     # ord(':')-ord('0')=10
y/apm-/;</d;                                # 'a'-> chr(11), 'p' -> chr(12), strip -,m
for $a (0..5) {                             # iterate 6 output lines
    map {                                   # iterate each char in input
        $o .= substr(
            ( split $/, $g )[$a],           # grab line $a
            ( $x=-48+ord ) * 12,            # $x=glyph index, 12=glyph width
            ('6356766766099'=~/./g)[$x]+3   # glyph display width
        )
    } /./g;
    $o .= $/                                # append newline
}
print $o                                    # output

请注意,由于字符编码问题,当您将上述代码粘贴到文件中时,输出可能会出现某种形式的错误。因此,这是基于base-64编码的高尔夫球版本。复制它,并将其粘贴到base64 -d > 510.pl

KCRMLCRDLCRiKT11bnBhY2siVy9hVy9hQioiLHEhDjEyMzQ2Njc3ODg5OTk5DiBffC9cKSgKJzws
Pi5gFQBQAVACqAIgCqgBQBVUAqAFQAH05PAOmANTwBqngGbMBlVgHOAaqMDk8AcngEfWZmAzAA9Y
Ar1gZs0DNQBzoAHOBny9YGfL1g+XoAUkoSkp9ZmYDMAHOANT9A1Cwap4Bn5PABzgH9T9AeV/GBAB
y/7Pw8Z+Tx+Hn1mswGYAc6AKvWAMwCr1gZ8vWAc4Bny9YA5wPl6APK/lrWtn+rrWt9PKuAawBqrA
aq4AawGquAeVcA64AeVcAdcAAAABrfQhO0BjPW1hcHskaTw8PSRfLSRQIGlmJF8+JFA7JFA9JF87
c3ByaW50ZiIlJHtsfWIiLCRpKyt9JEw9fi8uL2c7d2hpbGUoJGIpeyRiPX5zL14kY1skX10vLyBh
bmQkZy49KCRDPX4vLi9zZylbJF9dZm9yIDAuLiQjY30kXz1wb3A7cy8tLzovO3kvYXBtLS87PC9k
O2ZvciRhKDAuLjUpe21hcHskby49c3Vic3RyKChzcGxpdCQvLCRnKVskYV0sKCR4PS00OCtvcmQp
KjEyLCgnNjM1Njc2Njc2NjA5OSc9fi8uL2cpWyR4XSszKX0vLi9nOyRvLj0kL31wcmludCRv

这是我使用的字体。为了方便索引,我将字形间隔了12个字符(上午/下午的大小)。

   ___        __          ___         ____        _  _        _____         __        ______       ___         ___            
  / _ \      /_ |        |__ \       |___ \      | || |      | ____|       / /       |____  |     / _ \       / _ \      _  
 | | | |      | |           ) |        __) |     | || |_     | |__        / /_           / /     | (_) |     | (_) |    (_)          __ _ _ __   _ __ _ __ 
 | | | |      | |          / /        |__ <      |__   _|    |___ \      | '_ \         / /       > _ <       \__, |     _          / _` | '  \ | '_ \ '  \
 | |_| |      | |         / /_        ___) |        | |       ___) |     | (_) |       / /       | (_) |        / /     (_)         \__,_|_|_|_|| .__/_|_|_|
  \___/       |_|        |____|      |____/         |_|      |____/       \___/       /_/         \___/        /_/                              |_|

该字体为592字节。
先前的方法在RLE压缩上使用了一些变体,以将其减少到353字节,但代价是78字节的解压缩代码。
Huffman编码将字体压缩为221个字节,而解压缩算法的代价是154个字节。


该死!我真想串压缩哈斯克尔..
Ĵ阿特金

2

Bash + GNU实用程序+ figlet,134

不知道是否figlet允许与否,但它确实提供正确的字体- big为数字和small:{a,p}m

f=figlet\ -f
b()(date +%$1|sed 's/./& /g'|$f big)
b -I|paste - <(echo "    ";$f small ": ") <(b M) <(echo;date +%P|$f small)|tr \\t \ 

剩下的只是从中获取正确的信息date并重新排列格式,这样看起来就正确了:

  ___          _____    ___    
 / _ \    _   | ____|  / _ \               
| (_) |  (_)  | |__   | | | |   __ _ _ __  
 > _ <    _   |___ \  | | | |  / _` | '  \ 
| (_) |  (_)   ___) | | |_| |  \__,_|_|_|_|
 \___/        |____/   \___/               

Figlet可以使用来安装在Ubuntu上sudo apt-get install figlet


哦,没有想到这个漏洞。我将编辑问题以确保程序中包括字符数据,但请保持提交状态并将其标记为非活动状态-仍然是一个不错的选择。

2
但是,我确实使用figlet来获取数字的数据,所以+1来解决这个问题:)

为了清楚起见:不能从外部源或库中加载字体。

2

C ++,938字节

具有一些基本压缩输入数据的修订版本:在此处测试

#include <stdio.h>
#include <time.h>
int main(){char e[]="!1`2!3`1!2`1!4`2!4`!1`!4`4!4`1!3`5!4`2!4`2!35^!`!]!1^`!}!}`1!]!1}`2!]!1}!}1!}!2}!`3}!2^!^!2}`3!1}!2^!`!]!2^!`!]!31`!}!}!}!}!1}!}!3*!}!2`1*!}!}!}1!}`!1}!}`1!3^!^`!6^!^!2}!)`*!}!}!)`*!}!2`1!`!`!`1!3`!`1!`!`1!4)`*}!}!}!}!1}!}!2^!^!2}`1!=!1}`1!2`}!}`2!]!1}!(`!]!4^!^!4?!`!=!2]`1-!}!1^!`a!}!(!1]!1}!(`!]!(!1]!4`!}!}`}!}!1}!}!1^!^`!2`2*!}!3}!}!3`2*!}!}!)`*!}!2^!^!4}!)`*!}!3^!^!2]`1-`}`}`}`}!}!/`1^`}`}`}!2)`*!]`2^!2}`}!}`3}!}`3^!4}`}!2}`3^!2]`2^!2^`^!6]`2^!3^`^!16}`}!14",l[]="8578988998>?3",f[666],*q=f,*p=e,c,r;time_t z;time(&z);tm*u=localtime(&z);while(*p){if(*p>47&&*p<58){r=*p++-48;if(*p>47&&*p<58)r=r*10+*p++-48;while(r--)*q++=c;}else{*q++=c=*p++==94?48:p[-1];}}c=u->tm_hour;sprintf(e,"%02d<%02d%c",c%12,u->tm_min,':'+c/12);for(int s,n,o,r=0;r<6;r++){for(q=e;*q;q++){o=r*111;for(n=0; n<*q-48;n++)o+=l[n]-48;s=l[n]-48;for(n=o;n<o+s;n++)putchar(f[n]-1);}putchar('\n');}return 0;}

与所需数据相比,此提交的标头对字节大小的影响不大,因此实际上有很大的机会获胜。

2

Haskell,932699字节

是的,不到700个字节!!

t=transpose
i=intercalate
l=lines
u=unlines
s=show
c(h,m,a)=u$t$l(i(r"!!\n!!\n")(map d(s h++':':(if m<10 then '0':s m else s m)))++r"!!"++(d$a!!0))
e s z n=i s$splitOn z n
r=e"   ""!"
d 'a'=b 10
d 'p'=b 11
d ':'=b 12
d n=b$read[n]
b n=splitOn(r"!!")(u$t$l$r$e" |""@"$e"___""$"$e"_|""~"$e"!!""*"$e"_ ""#""  $! __!$! $_! # _!  $__!  __! $$! $!  $*****  \n / #\\  /_@@_#\\ @$ \\ @@|@!| $~!/ /!|$#@  / #\\!/ #\\****!  #\n|@@@ @@! )@!__)@@@|@#@@__! / /_* / / @ (_)@@ (_)@  _###__! #_##__!(_)\n|@@@ @@!/ /!|_#< @__!~@$ \\ @ '#\\!  / /! > #<!\\__,@ / _`@ '  \\ @ '#\\ '  \\!#\n|@~@ @@  / /_!$)@!@@! $)@@ (_)@!/ /!@ (_)@! / /  \\__,~~~~@ .__/~~~ (_)\n \\$/!|~@$~@$_/! @~!|$_/!\\$/!/_/*\\$/! /_/**!@~** ")!!n

有点不满意

module Clock where
import Data.Lists

main :: IO ()
main = putStr $ clock (5,05,"am")

clock :: (Int, Int, String) -> String
clock (h,m,a) | m <- if m < 10 then '0':show m else show m
              , hm <- intercalate "      \n      \n" (map digit (show h ++ ':' :m))
              =  unlines $ transpose $ lines (hm ++ "      "++(digit$a!!0))

digit :: Char -> String
digit 'a' = numbers 10
digit 'p' = numbers 11
digit ':' = numbers 12
digit n = numbers (read [n])


numbers :: Int -> String
numbers n = splitOn "      " (unlines $ transpose $ lines "  ___    __   ___    ____    _  _     _____     __    ______    ___     ___                                \n / _ \\  /_ | |__ \\  |___ \\  | || |   | ____|   / /   |____  |  / _ \\   / _ \\                             _ \n| | | |  | |    ) |   __) | | || |_  | |__    / /_       / /  | (_) | | (_) |  __ _ _ __    _ __ _ __   (_)\n| | | |  | |   / /   |__ <  |__   _| |___ \\  | '_ \\     / /    > _ <   \\__, | / _` | '  \\  | '_ \\ '  \\   _ \n| |_| |  | |  / /_   ___) |    | |    ___) | | (_) |   / /    | (_) |    / /  \\__,_|_|_|_| | .__/_|_|_| (_)\n \\___/   |_| |____| |____/     |_|   |____/   \\___/   /_/      \\___/    /_/                |_|             ") !! n

怎么运行的

(这主要是非高尔夫程序的工作方式)

clock :: (Int, Int, String) -> String
clock (h,m,a) | m <- if m < 10 then '0':show m else show m
              , hm <- intercalate "      \n      \n" (map digit (show h ++ ':' :m))
              =  unlines $ transpose $ lines (hm ++ "      "++(digit$a!!0))

clock花费时间的元组并返回一个字符串。m是当前分钟,0如果添加了前导,则为分钟<10hm是小时和分钟与连在一起:。它要做的最后一件事是转置输出。

digit :: Char -> String
digit 'a' = numbers 10
digit 'p' = numbers 11
digit ':' = numbers 12
digit n = numbers (read [n])

这里相当简单。digit是将字符映射到存储的字符串中的位置的函数。

numbers :: Int -> String
numbers n = splitOn "      " (unlines $ transpose $ lines  replace" |""@"$replace"___""$"$replace"_|""~"$replace"!!""*"$replace"_ ""#""  $! __!$! $_! # _!  $__!  __! $$! $!  $*****  \n / #\\  /_@@_#\\ @$ \\ @@|@!| $~!/ /!|$#@  / #\\!/ #\\****!  #\n|@@@ @@! )@!__)@@@|@#@@__! / /_* / / @ (_)@@ (_)@  _###__! #_##__!(_)\n|@@@ @@!/ /!|_#< @__!~@$ \\ @ '#\\!  / /! > #<!\\__,@ / _`@ '  \\ @ '#\\ '  \\!#\n|@~@ @@  / /_!$)@!@@! $)@@ (_)@!/ /!@ (_)@! / /  \\__,~~~~@ .__/~~~ (_)\n \\$/!|~@$~@$_/! @~!|$_/!\\$/!/_/*\\$/! /_/**!@~** ")!!n

这是魔术存储的字符串。

高尔夫程序和非高尔夫程序之间的唯一真正变化是,高尔夫程序通过用替换一些常见的字符模式来增加一些字符串压缩!@$。原始数据字符串为667字节,替换压缩后为390字节


1

JavaScript(ES6),994985字节

原始数据根本没有压缩的可怕尝试,以及非常俗气的输出方法。

但是,嘿……这只是我的第二个答案!

d="   ___   !  / _ \\  ! | | | | ! | | | | ! | |_| | !  \\___/  0  __  ! /_ | !  | | !  | | !  | | !  |_| 0  ___   ! |__ \\  !    ) | !   / /  !  / /_  ! |____| 0  ____   ! |___ \\  !   __) | !  |__ <  !  ___) | ! |____/  0  _  _    ! | || |   ! | || |_  ! |__   _| !    | |   !    |_|   0  _____  ! | ____| ! | |__   ! |___ \\  !  ___) | ! |____/  0    __   !   / /   !  / /_   ! |  _ \\  ! | (_) | !  \\___/  0  ______  ! |____  | !     / /  !    / /   !   / /    !  /_/     0   ___   !  / _ \\  ! | (_) | !  > _ <  ! | (_) | !  \\___/  0   ___   !  / _ \\  ! | (_) | !  \\__, | !    / /  !   /_/   0   ! _ !(_)! _ !(_)!   0!! __ _ _ __ !/ _` | '  \\!\\__,_|_|_|_|!0!! _ __ _ __ !| '_ \\ '  \\!| .__/_|_|_|!|_|".split(0);
f=a=>{t="toString",s="split",h=a[0][t]()[s](""),m=a[1][s](""),p=a[2]=='am'?11:12,g=h.length>1?1:0,r="";for(i=0;i<6;i++){r+=d[h[0]][s]('!')[i];r+=(g&&1)?d[h[1]][s]('!')[i]:"";r+=d[10][s]('!')[i]+d[m[0]][s]('!')[i]+d[m[1]][s]('!')[i]+d[p][s]('!')[i]+"\n"}return r}

旧提交(994字节)

d=["   ___   !  / _ \\  ! | | | | ! | | | | ! | |_| | !  \\___/  ","  __  ! /_ | !  | | !  | | !  | | !  |_| ","  ___   ! |__ \\  !    ) | !   / /  !  / /_  ! |____| ","  ____   ! |___ \\  !   __) | !  |__ <  !  ___) | ! |____/  ","  _  _    ! | || |   ! | || |_  ! |__   _| !    | |   !    |_|   ","  _____  ! | ____| ! | |__   ! |___ \\  !  ___) | ! |____/  ","    __   !   / /   !  / /_   ! |  _ \\  ! | (_) | !  \\___/  ","  ______  ! |____  | !     / /  !    / /   !   / /    !  /_/     ","   ___   !  / _ \\  ! | (_) | !  > _ <  ! | (_) | !  \\___/  ","   ___   !  / _ \\  ! | (_) | !  \\__, | !    / /  !   /_/   ","   ! _ !(_)! _ !(_)!   ","!! __ _ _ __ !/ _` | '  \\!\\__,_|_|_|_|!","!! _ __ _ __ !| '_ \\ '  \\!| .__/_|_|_|!|_|"];
f=a=>{
    t="toString",s="split",h=a[0][t]()[s](""),m=a[1][s],p=(a[2]=='am')?11:12,g=(h.length>1)?1:0,r="";
    for(i=0;i<6;i++){
        r+=d[h[0]].s('!')[i];
        r+=g&&1?d[h[1]].s('!')[i]:"";
        r+=d[10].s('!')[i]+d[m[0]].s('!')[i]+d[m[1]].s('!')[i]+d[p].s('!')[i]+"\n"
    }
return r
}

分成几行以使其更易于阅读。

基本上:

var f = function (a) {
  hours = a[0].toString().split(""), // convert hours to a string then array to
                                    // handle single and and double numbers
  minutes = a[1].split(""), // ditto with minutes
  period = a[2] == "am" ? 11 : 12, // if it is am, get data[11], if pm, get data[12]
  g = hours.length > 1 ? 1 : 0, // if hours > 9, then g is true
  r = ""; // the string that will be returned
for (i = 0; i < 6; i++) {
    r += data[hours[0]].split("!")[i]; // add the first digit of hours to r
    r += g && 1 ? data[hours[1]].split("!")[i] : ""; // if g is true, add the second 
                                                    //digit of hours to r
    r += data[10].split("!")[i] + // colon
    data[minutes[0]].split("!")[i] + // first digit of minutes
    data[minutes[1]].split("!")[i] + // second digit of minutes
    data[period].split("!")[i] + // am/pm
    "\n"; // and finally linebreak.
  } // entire loop repeated six times, each iteration adds one line to the string
return r; // return the string
};

0

Python 3,1085 1072字节

打高尔夫球

def f(h,c="",n=["   ___   @  / _ \  @ | | | | @ | | | | @ | |_| | @  \___/  ","  __  @ /_ | @  | | @  | | @  | | @  |_| ","  ___   @ |__ \  @    ) | @   / /  @  / /_  @ |____| ","  ____   @ |___ \  @   __) | @  |__ <  @  ___) | @ |____/  ","  _  _    @ | || |   @ | || |_  @ |__   _| @    | |   @    |_|   ","  _____  @ | ____| @ | |__   @ |___ \  @  ___) | @ |____/  ","    __   @   / /   @  / /_   @ |  _ \  @ | (_) | @  \___/  ","  ______  @ |____  | @     / /  @    / /   @   / /    @  /_/     ","   ___   @  / _ \  @ | (_) | @  > _ <  @ | (_) | @  \___/  ","   ___   @  / _ \  @ | (_) | @  \__, | @    / /  @   /_/   ","   @ _ @(_)@ _ @(_)@   ","            @            @ __ _ _ __ @/ _` | '  \@\__,_|_|_|_|@            ","            @            @ _ __ _ __ @| '_ \ '  \@| .__/_|_|_|@|_|"]):
 for i in range(6):
  for j in range(3):
   if j<2:
    x=int(h[j]);d=x//10;u=x%10
    if d>0 or j>0:c+=n[d].split("@")[i]
    c+=n[u].split("@")[i]
    if j==0:c+=" "+n[10].split("@")[i]+" "
   else:y=11 if h[j]=="am" else 12;c+=" "+n[y].split("@")[i]
  c+="\n"
 return c

不打高尔夫球

import os
from time import ctime

def asciiClock(hour):
    num = ["   ___   @  / _ \  @ | | | | @ | | | | @ | |_| | @  \___/  @","  __  @ /_ | @  | | @  | | @  | | @  |_| @",
   "  ___   @ |__ \  @    ) | @   / /  @  / /_  @ |____| @","  ____   @ |___ \  @   __) | @  |__ <  @  ___) | @ |____/  @",
   "  _  _    @ | || |   @ | || |_  @ |__   _| @    | |   @    |_|   @","  _____  @ | ____| @ | |__   @ |___ \  @  ___) | @ |____/  @",
   "    __   @   / /   @  / /_   @ |  _ \  @ | (_) | @  \___/  @","  ______  @ |____  | @     / /  @    / /   @   / /    @  /_/     @",
   "   ___   @  / _ \  @ | (_) | @  > _ <  @ | (_) | @  \___/  @","   ___   @  / _ \  @ | (_) | @  \__, | @    / /  @   /_/   @",
   "   @ _ @(_)@ _ @(_)@   @","            @            @ __ _ _ __ @/ _` | '  \@\__,_|_|_|_|@            @",
   "            @            @ _ __ _ __ @| '_ \ '  \@| .__/_|_|_|@|_|@"]
    clock = ""
    for i in range(6):
        for j in range(3):
            if j < 2:
                x = int(hour[j])
                d = x // 10
                u = x % 10
                if d > 0 or j > 0:
                    clock += num[d].split("@")[i]
                clock += num[u].split("@")[i]
                if j == 0:
                    clock += " " + num[10].split("@")[i] + " "
            else:
                y = 11 if hour[j] == "am" else 12
                clock += " " + num[y].split("@")[i]
        clock += "\n"
    return clock

previousMinute = -1
while True:
    hour = ctime().split()[3].split(":")
    h = int(hour[0])
    m = hour[1]
    x = "am" if h < 12 else "pm"
    if h > 12:
        h -= 12
    if  previousMinute != m:
        os.system("clear") # if using Windows change to "cls"
        print(asciiClock([h, m, x]))
    previousMinute = m
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.