Unicode现在几点钟了?


12

给定输入时间以下任何一种格式的字符串,挑战是简单化的:

hhhh:mmhh:mm:ss0 ≤ hh ≤ 230 ≤ mm ≤ 590 ≤ ss ≤ 59

使用以下符号输出当前几点钟:

AA  LABEL FOR CHARACTER     CODE POINT   HEXADECIMAL
==  ====================    ==========   ===========
🕐  Clock Face 01 Oclock    128336       0x1F550  
🕑  Clock Face 02 Oclock    128337       0x1F551  
🕒  Clock Face 03 Oclock    128338       0x1F552  
🕓  Clock Face 04 Oclock    128339       0x1F553  
🕔  Clock Face 05 Oclock    128340       0x1F554  
🕕  Clock Face 06 Oclock    128341       0x1F555  
🕖  Clock Face 07 Oclock    128342       0x1F556  
🕗  Clock Face 08 Oclock    128343       0x1F557  
🕘  Clock Face 09 Oclock    128344       0x1F558  
🕙  Clock Face 10 Oclock    128345       0x1F559  
🕚  Clock Face 11 Oclock    128346       0x1F55A  
🕛  Clock Face 12 Oclock    128347       0x1F55B  

采用以下格式:

It is currently {Clock Face 1} with {mm} minutes and {ss} seconds until {Clock Face 2}.

示例(包括所有附带情况):

只有几个小时的情况...

f("12") = "It is currently 🕛."

带有小时和分钟的表壳...

f("12:30") = "It is currently 🕛 with 30 minutes until 🕐."

案件只有几个小时,但分钟数已包含为00 ...

f("12:00") = "It is currently 🕛."

带有小时,分钟和秒的表壳...

f("12:30:30") = "It is currently 🕛 with 29 minutes and 30 seconds until 🕐."

带有小时和分钟的表壳,但秒数包含为00 ...

f("12:30:00") = "It is currently 🕛 with 30 minutes until 🕐."

具有小时和分钟的情况,直到下一个小时不到一分钟...

f("12:59:59") = "It is currently 🕛 with 1 seconds until 🕐."

您不必从复数更改为单数。


带小时和分钟的表壳,下一个小时为1分钟...

f("12:59") = "It is currently 🕛 with 1 minutes until 🕐."

您不必从复数更改为单数。


使用军事时间的案例(是的,您必须处理)...

f("23:30:30") = "It is currently 🕚 with 29 minutes and 30 seconds until 🕛."

无效的案件...

f("PPCG") = This cannot occur, you are guaranteed a valid format by the definition of the problem.
f(66:66:66) = This cannot occur, you are guaranteed valid numbers by the definition of the problem.
f(24:60:60) = This cannot occur, you are guaranteed valid numbers by the definition of the problem.

对于无效的案例,您不必遵循任何输出样式,可以使用错误。


总体而言,挑战是相当简单的,但在我看来,它似乎足够动态以至于很有趣。这里最短的代码是赢家,因为除了长度以外,代码没有太多可变的方面。



这应该是一个完整的程序还是一个函数/ lambda是否足够?
devRicher

2
我认为不是的0 < hh < 240 < mm < 60而且0 < ss < 60,你的意思是0 ≤ hh ≤ 230 ≤ mm ≤ 590 ≤ ss ≤ 59
暴民埃里克

2
是否允许使用特定于语言的Date / DateTime结构作为输入?
devRicher

2
@carcusocomputing您指定代码必须处理24小时,代码必须处理AM还是PM标记?
泰勒·斯科特

Answers:


3

Befunge,256 250字节

>&~85+`v
8~-&"<"_00v`+5
0v%\-&"<<"_
v>:00p!!-"<"%10p65++:66+%0" yltnerruc si tI">:#,_$"Hu 5x"2*,3*,+,2*+,10g00g+
_".",@,".",+*2,+,*3,*2"x5 uH"%+66+1$_,#!>#:<v0
" litnu  htiw ",,,,,,10g:>#v_$"sdnoces"00g.^>
_>,,,,,,,>" dna ">,,,,,00^ >."setunim"00g!#^

在线尝试!

结果编码为utf-8,因为它最适合TIO,但如果在本地进行测试,则可能需要调整系统的默认代码页才能正确看到时钟面。否则,只需将输出重定向到文件,然后在与utf-8兼容的编辑器中将其打开。

说明

前三行从stdin读取小时和分钟,然后在每个值之后检查EOF或换行,并用零代替输入中缺少的组件。在第四行,如果秒不为零,我们将调整分钟值,将小时值转换为0到11的范围(以匹配每个小时的相应unicode字符),并写出输出的初始部分,包括第一个钟面。

在这一点上,我们需要遵循不同的分支,具体取决于哪些组件为非零。第五行开始的第一个测试只是检查分钟和秒是否均为零。如果是这样,我们写出一个决赛.并退出。否则,第6和第7行处理其余情况-在路径全部在第5行再次组合以写出最终时钟面(从右到左执行)之前,写出适当的文本和值。


3

JavaScript(ES6),201

t=>(T=h=>String.fromCodePoint(128336+h%12),[h,m,s]=t.match(/\d+/g),'It is currently '+T(h-=~10)+((m-=-!!-s)?` with ${60-m?60-m+' minutes'+(-s?' and ':''):''}${-s?60-s+' seconds':''} until `+T(-~h):''))

少打高尔夫球

t=>(
  T=h=>String.fromCodePoint(128336+h%12),
  [h,m,s]=t.match(/\d+/g),
  'It is currently '+T(h-=~10)
   +( 
      // if seconds is not 0, increment m else just convert to number
      // have to use '- -' to force conversion to number 
     (m -= - !!-s) 
-s?++m:m)
      ? ` with ${60-m ? 60-m+' minutes'+(-s?' and ':''):''}${-s?60-s+' seconds':''} until `+T(-~h)
      : ''
    )
)

测试

F=
t=>(T=h=>String.fromCodePoint(128336+h%12),[h,m,s]=t.match(/\d+/g),'It is currently '+T(h-=~10)+((m-=-!!-s)?` with ${60-m?60-m+' minutes'+(-s?' and ':''):''}${-s?60-s+' seconds':''} until `+T(-~h):'')
)


var tid=0

function getTime(t)
{
  var a=t.match(/\d+/g)
  if (a) {
    var [h,m,s]=a
    h|=0, s|=0, m|=0
    if(h>=0 & h<24 & m>=0 & m<60 & s>=0 & s<60) 
      return [h,m,s]
  }
  return null
}      

function update()
{
  clearTimeout(tid)
  var t=I.value, a=getTime(t)
  if (a) {
    O.textContent = F(t)
    tid = setTimeout(again,5000)
  }
  else {
    O.textContent = 'invalid ' + t
  }
}
function again()
{      
  var t=I.value, a=getTime(t)
  if (a) {
    var [h,m,s]=a
    ++s>59?(s=0,++m>59?(m=0,++h):0):0
    h%=24
    s<10?s='0'+s:0
    m<10?m='0'+m:0
    t = h+(-m-s?':'+m+(-s?':'+s:''):'')
    I.value = t
    O.textContent=F(t)
    tid = setTimeout(again, 1000)
  }
}

update()
#O { font-size:16px }
Time <input id=I value='12' oninput='update()' onkeydown='update()'>
(modify current time as you wish - but use valid values)
<pre id=O></pre>


我不知道如何为此选择一个赢家,你们两个人都在2分钟之内发布了201字节的相同语言。
魔术章鱼缸

@carusocomputing当然应该选择我。我。我我我!...
edc65

@carusocomputing,否则您可以选择投票数较少(没有理由)的答案仅仅是为了恢复平衡
edc65

或者,您也可以将String代码中的单词替换为""空字符串,以节省4个字节:)。啊,胡扯,他也可以。
魔术章鱼缸

显示It is currently 🕛 with 60 minutes until 🕐。我认为它应该It is currently 🕛.
罗马格拉夫

2

JavaScript(ES6),201字节

(i,[h,m,s]=i.split`:`,c=n=>String.fromCodePoint(128336+(n+11)%12))=>`It is currently ${c(+h)}${m|s?` with ${(m=59+!+s-m)?m+` minutes`:``}${+s&&m?` and `:``}${+s?60-s+` seconds`:``} until `+c(-~h):``}.`

如果考虑复数,则为226个字节:

f=
(i,[h,m,s]=i.split`:`,c=n=>String.fromCodePoint(128336+(n+11)%12))=>`It is currently ${c(+h)}${m|s?` with ${(m=59+!+s-m)?m+` minute`+(m-1?`s`:``):``}${+s&&m?` and `:``}${+s?60-s+` second`+(59-s?`s`:``):``} until `+c(-~h):``}.`
<input oninput=o.textContent=f(this.value)><div id=o>


1

PowerShell中250个 243字节

$h,$m,$s=$args-split':'
$f={[char]::ConvertFromUtf32(128336+(11+$args[0])%12)}
$u=(60-$s)%60
$v=(59-$m+!$u)%60
"It is currently $(&$f $h;"with $(("$v minutes"|?{$v}),("$u seconds"|?{$u})-match'.'-join' and ') until $(&$f (1+$h))"|?{$u-or$v})."

在线尝试!


1

C,241字节

将UTF-8写入stdout。

#define p printf(
c(v,h){p"%s \xf0\x9f\x95%c",v,144+h%12);}f(t){int h=0,m=0,s=0;sscanf(t,"%d:%d:%d",&h,&m,&s);m=(59-m+!s)%60;c("It is currently",h-1);m&&p" with %d minutes",m);s&&p" %s %d seconds",m?"and":"with",60-s);m|s&&c(" to",h);p".");}

在线尝试!

带空格的代码:

#define p printf(

c(v, h) {
    p"%s \xf0\x9f\x95%c", v, 144 + h % 12);
}

f(t) {
    int h = 0, m = 0, s = 0;

    sscanf(t, "%d:%d:%d", &h, &m, &s);
    c("It is currently", h - 1);
    m = (59 - m + !s) % 60;
    m && p" with %d minutes", m);
    s && p" %s %d seconds", m ? "and" : "with", 60 - s);
    m | s && c(" to", h);
    p".");
}
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.