ユニコードは何時ですか?


12

次のいずれかの形式の文字列として入力時間指定すると、課題は単純化さます。

hhhh:mmまたはhh:mm:ss0 ≤ hh ≤ 230 ≤ mm ≤ 59そして0 ≤ 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 🕐."

次の1時間まで1分未満で、時間と分があるケース...

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.

無効なケースについては、出力のスタイルに準拠する必要はありません。エラーは問題ありません。


全体として、この挑戦​​はかなり単純化されていますが、私の意見では楽しくなるほど十分に動的であるように思われました。コードの長さ以外の変数の側面はあまりないので、ここで最も短いコードが勝者です。



これはプログラム全体か、関数/ラムダで十分ですか?
devRicher

2
の代わりに0 < hh < 240 < mm < 60そして0 < ss < 60、あなたが意味し0 ≤ hh ≤ 230 ≤ mm ≤ 59そして0 ≤ ss ≤ 59
エリックアウトゴルファー16

2
言語固有のDate / DateTime構造体は入力として許可されていますか?
devRicher

2
@carcusocomputingコードは24時間を処理する必要があることを指定しますが、コードはタグを処理するAM必要がありPMますか?
テイラースコット

回答:


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互換エディターで開きます。

説明

最初の3行は、stdinから時間、分、秒を読み取り、各値の後にEOFまたは改行をチェックし、入力から欠落しているコンポーネントをゼロに置き換えます。4行目では、秒がゼロ以外の場合に分値を調整し、時間値を0〜11の範囲に変換して(各時間の適切なUnicode文字に一致するように)、出力の最初の部分を書き出します。最初の時計の文字盤。

この時点で、ゼロ以外のコンポーネントに応じて異なるブランチをたどる必要があります。5行目の最初のテストでは、分と秒の両方がゼロであるかどうかを確認します。その場合は、最終版を書き出して.終了します。それ以外の場合、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>


私はこのために勝者を選ぶ方法を知りません、あなたは両方とも同じ言語で201バイトで互いに2分以内に投稿しました。
魔法のタコUr

もちろん、@ carusocomputingを選択してください。私。ME ME ME!...
edc65

@carusocomputingまたはそれ以外の場合は、バランスを取り戻すために、投票数が少ない(理由なしで)答えを選択できます
-edc65

またはString、コード内の単語を""空の文字列に置き換えて、4バイト節約できます:)。ああ、くだらない、彼もできます。
魔法のタコUr

ショー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

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".");
}
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.