νƒœκ·Έ 보관물: date

date

μ–Όλ§ˆ μ „μž…λ‹ˆκΉŒ? b) μ–Έμ–΄ 별 λ‹Ήμ²¨μž

μ–Όλ§ˆ μ „μž…λ‹ˆκΉŒ?

κ·œμΉ™

  • 각 μ œμΆœλ¬Όμ€ 전체 ν”„λ‘œκ·Έλž¨μ΄μ–΄μ•Όν•©λ‹ˆλ‹€.
  • ν”„λ‘œκ·Έλž¨μ€ 두 개의 μ‰Όν‘œλ‘œ ꡬ뢄 된 λ‚ μ§œλ₯Ό ν˜•μ‹ YYYY-MM-DD으둜 μž…λ ₯ν•˜κ³  였늘이 첫 번째 λ‚ μ§œ 인 κ²ƒμ²˜λŸΌ 두 번째 λ‚ μ§œ 이후 STDOUT에 μ§€λ‚œ 일 수λ₯Ό μΈμ‡„ν•΄μ•Όν•©λ‹ˆλ‹€ (두 번째 λ‚ μ§œκ°€ 미래인 경우 음수)와 선택적인 ν›„ν–‰ 쀄 λ°”κΏˆ 및 κΈ°νƒ€λŠ” μ—†μŠ΅λ‹ˆλ‹€. 두 λ‚ μ§œκ°€ λͺ¨λ‘ 그레고리λ ₯이라고 κ°€μ •ν•©λ‹ˆλ‹€.
  • ν”„λ‘œκ·Έλž¨μ€ STDERR에 아무것도 쓰지 μ•Šμ•„μ•Όν•©λ‹ˆλ‹€.

    μ œμΆœλ¬Όμ„ ν…ŒμŠ€νŠΈν•˜λ €λ©΄ 톡역사가 μžˆμ–΄μ•Όν•©λ‹ˆλ‹€.

  • μ œμΆœμ€ μ μ ˆν•œ (기쑴의) 인코딩, 일반적으둜 (ν•„μš”ν•˜μ§€λŠ” μ•Šμ§€λ§Œ) UTF-8 둜 λ°”μ΄νŠΈ λ‹¨μœ„ 둜 μ μˆ˜κ°€ 맀겨 μ§‘λ‹ˆλ‹€. Folders 와 같은 일뢀 μ–Έμ–΄ λŠ” 점수λ₯Ό μ–»κΈ°κ°€ λ‹€μ†Œ κΉŒλ‹€ λ‘­μŠ΅λ‹ˆλ‹€. μ˜μ‹¬μŠ€λŸ¬μš΄ 경우 Meta에 λ¬Έμ˜ν•˜μ‹­μ‹œμ˜€ .
  • 이것은 κ°€μž₯ 짧은 μ½”λ“œκ°€ μŠΉλ¦¬ν•©λ‹ˆλ‹€.

    예

μž…λ ₯:

2015-12-03,2015-12-01

μ‚°μΆœ:

2

μž…λ ₯:

2015-12-03,2014-12-01

μ‚°μΆœ:

367

μž…λ ₯:

2015-12-03,2013-12-03

μ‚°μΆœ:

730

슀 λ‹ˆνŽ«

이 κ²Œμ‹œλ¬Όμ˜ 맨 μ•„λž˜μ—μžˆλŠ” μŠ€νƒ 슀 λ‹ˆνŽ«μ€ λ‹΅λ³€ a)μ—μ„œ 리더 λ³΄λ“œλ‘œ, b) μ–Έμ–΄ 별 λ‹Ήμ²¨μž λͺ©λ‘μœΌλ‘œ μΉ΄νƒˆλ‘œκ·Έλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.

닡변이 ν‘œμ‹œλ˜λ„λ‘ν•˜λ €λ©΄ λ‹€μŒ 마크 λ‹€μš΄ ν…œν”Œλ¦Ώμ„ μ‚¬μš©ν•˜μ—¬ ν—€λ“œ 라인으둜 닡변을 μ‹œμž‘ν•˜μ‹­μ‹œμ˜€.

## Language Name, N bytes

N제좜물의 ν¬κΈ°λŠ” 어디에 μžˆμŠ΅λ‹ˆκΉŒ ? 당신이 λ‹Ήμ‹ μ˜ 점수λ₯Ό ν–₯μƒμ‹œν‚¬ κ²½μš°μ—, 당신은 ν•  수 μžˆμŠ΅λ‹ˆλ‹€ λ₯Ό 톡해 λˆˆμ— λ„λŠ”μ— μ˜ν•΄, ν—€λ“œ 라인에 였래된 점수λ₯Ό μœ μ§€ν•œλ‹€. 예λ₯Ό λ“€μ–΄ :

## Ruby, <s>104</s> <s>101</s> 96 bytes

헀더에 μ—¬λŸ¬ 숫자λ₯Ό ν¬ν•¨ν•˜λ €λŠ” 경우 (예 : μ μˆ˜κ°€ 두 파일의 ν•©κ³„μ΄κ±°λ‚˜ 인터프리터 ν”Œλž˜κ·Έ νŽ˜λ„ν‹°λ₯Ό λ³„λ„λ‘œ λ‚˜μ—΄ν•˜λ €λŠ” 경우) μ‹€μ œ μ μˆ˜κ°€ 헀더 의 λ§ˆμ§€λ§‰ 숫자 인지 ν™•μΈν•˜μ‹­μ‹œμ˜€ .

## Perl, 43 + 2 (-p flag) = 45 bytes

μ–Έμ–΄ 이름을 링크둜 λ§Œλ“€λ©΄ 슀 λ‹ˆνŽ«μ— ν‘œμ‹œλ©λ‹ˆλ‹€.

## [><>](http://esolangs.org/wiki/Fish), 121 bytes
var QUESTION_ID=65989,OVERRIDE_USER=46167;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?([\d.]+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>


λ‹΅λ³€

ν‹° 슀크립트 , 24 λ°”μ΄νŠΈ

((a=D.parse)Γ—-a(yΒ©/864e5

μš©λ„λŠ” Date.parseλ‹€μŒμ˜μ—κ²Œ 차이와 뢄열을받을 λ‚ μ§œλ₯Ό ꡬ문 λΆ„μ„ν•©λ‹ˆλ‹€.

온라인으둜 μ‚¬μš©ν•΄λ³΄μ‹­μ‹œμ˜€

&& Ungolfed

((a=D.parse)(x)-a(y))/864e5

               // Implicit: x is first date
               // y is second date
(
 (a=D.parse)   // Assign Date.parse to 'a'
 (x)           // Run Date.parse with first date
 -a(y)         // Subtract Date.parse run with second date
)/864e5        // Divide by 86,400,000

λ‹΅λ³€

배쉬 + GNU μœ ν‹Έλ¦¬ν‹°, 37

tr , \\n|date -f- +%s|dc -e??-86400/p

trμ‰Όν‘œλ₯Ό κ°œν–‰ 문자둜 λ°”κΏ‰λ‹ˆλ‹€. date쀄 λ°”κΏˆμœΌλ‘œ ꡬ뢄 된 λ‚ μ§œλ₯Ό 읽고 전달 된 λ‚ μ§œκ°€ λ‚˜νƒ€λ‚΄λŠ” μœ λ‹‰μŠ€ μ‹œλŒ€ μ΄ν›„μ˜ 초 수λ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€. 그런 λ‹€μŒμ΄ 숫자λ₯Ό dcμŠ€νƒμ— λ„£μŠ΅λ‹ˆλ‹€ . 그런 λ‹€μŒ 빼기의 κ°„λ‹¨ν•œ λ¬Έμ œλŠ” (24 * 60 * 60)으둜 λ‚˜λˆ•λ‹ˆλ‹€. 이 경우 dcμŠ€νƒ 기반 RPN μ‚°μˆ  ν‰κ°€λŠ” λ‚˜λˆ—μ…ˆλ³΄λ‹€ λ¨Όμ € κ΄„ν˜Έκ°€ ν•„μš”ν•˜μ§€ μ•ŠκΈ° λ•Œλ¬Έμ— bcλ˜λŠ” bash 보닀 λ‚«μŠ΅λ‹ˆλ‹€ $( ).

STDIN을 ν†΅ν•œ μž…λ ₯ :

$ echo 2015-12-3,2015-12-1 | ./longago.sh
2
$ echo 2015-12-3,2014-12-1 | ./longago.sh
367
$ echo 2015-12-3,2013-12-3 | ./longago.sh
730
$ 

λ‹΅λ³€

쀄리아, 67 λ°”μ΄νŠΈ

print(Int(-diff(map(i->Date(i,"y-m-d"),split(readline(),",")))[1]))

μ–Έ 골프 λ“œ :

# Read a line from STDIN
r = readline()

# Split it into two character dates
s = split(r, ",")

# Convert each to a Date object
d = map(i -> Date(i, "y-m-d"), s)

# Compute the difference in dates (first-second)
f = diff(d)[1]

# Convert the Base.Date.Day object to an integer
# Negate to get second-first
i = Int(-f)

# Print to STDOUT
print(i)

λ‹΅λ³€

슀칼라, 166 (139) 120 (116) 92 λ°”μ΄νŠΈ

print(args(0).replace('-','/').split(",").map(java.util.Date.parse(_)/86400000).reduce(_-_))

μš©λ²•: scala [source filename].scala [date1],[date2]

μ°Έκ³  : μ„Έ 번째 버전 (120 λ°”μ΄νŠΈ) 이상은 더 이상 μ‚¬μš©λ˜μ§€ μ•ŠλŠ” APIλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€. μ—¬μ „νžˆ μ»΄νŒŒμΌν•˜κ³  잘 μž‘λ™ν•©λ‹ˆλ‹€.
μ°Έκ³  2 : μ•„λž˜μ˜ μ£Όμ„κ°€λ“€μ—κ²Œ κ°μ‚¬ν•©λ‹ˆλ‹€.


λ‹΅λ³€

루비, 69 66 65 57 55 λ°”μ΄νŠΈ

a=->l{Time.gm *$F[l,3]};p (a[0]-a[3]).div 86400

λͺ…λ Ή ν–‰ μ˜΅μ…˜μ˜ 경우 47 λ°”μ΄νŠΈ + 8 λ°”μ΄νŠΈ Dane Anderson 덕뢄에 2 λ°”μ΄νŠΈκ°€ μ ˆμ•½λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

57 λ°”μ΄νŠΈ

p (Time.gm(*$F[0,3])-Time.gm(*$F[3,3])).div 86400

λͺ…λ Ή 쀄 μ˜΅μ…˜μ˜ 경우 49 λ°”μ΄νŠΈ μ½”λ“œ + 8 λ°”μ΄νŠΈ manatwork의 μ œμ•ˆμœΌλ‘œ 8 λ°”μ΄νŠΈλ₯Ό μ ˆμ•½ν–ˆμŠ΅λ‹ˆλ‹€.

65 λ°”μ΄νŠΈ

a,b=gets.split(?,).map{|i|Time.gm *i.split(?-)};p (a-b).div 86400

66 λ°”μ΄νŠΈ

a,b=gets.split(?,).map{|i|Time.new *i.split(?-)};p (a-b).div 86400

69 λ°”μ΄νŠΈ

a,b=gets.split(',').map{|i|Time.new *i.split('-')};p (a-b).to_i/86400

온라인 ν…ŒμŠ€νŠΈ

μ–Έ 골프

a = -> l {
  Time.gm *$F[l,3]       # Anonymous method to parse time
}
p (a[0]-a[3]).div 86400  # Subtracts two times and divides by 24*60*60

μš©λ²•:

ruby -naF[,-] -e 'a=->l{Time.gm *$F[l,3]};p (a[0]-a[3]).div 86400' <<< '2015-12-3,2013-12-3'

=> 730

λ‹΅λ³€

Japt , 41 λ°”μ΄νŠΈ

A=K$.parse)(($B=Uq',  g0)-$A($Bg1))/864e5

μ§€κΈˆκΉŒμ§€ 이것은 λͺ¨λ“  λ³€μˆ˜λ‘œ 얻을 μˆ˜μžˆλŠ” μ΅œμ„ μž…λ‹ˆλ‹€. $ 와 κ΄„ν˜Έκ°€ μ‹€μ œλ‘œ λ°”μ΄νŠΈ 수λ₯Ό 죽이기 λ•Œλ¬Έμ— μž…λ‹ˆλ‹€.

온라인으둜 μ‚¬μš©ν•΄λ³΄μ‹­μ‹œμ˜€

μ„€λͺ…

             // Implicit: U is set to input
A=K$.parse)  // Set variable A to date parsing function
(($B=Uq',    // Set B to input split by ,
  g0)        // Get the first date and parse
-            // Subtract...
$A(          // Parse this date...
   $Bg1      // Get's second date
))/864e5     // Divides by 86,400,000

λ‹΅λ³€

MATLAB, 41 31 λ°”μ΄νŠΈ

disp(-diff(datenum(input(''))))
{'2015-12-03', '2014-12-22'}
   346

μž…λ ₯은 μ‰Όν‘œλ‘œ ꡬ뢄 된 μ…€ν˜• λ°°μ—΄μ΄μ–΄μ•Όν•©λ‹ˆλ‹€. datenumμž…λ ₯ 셀을 νƒ€μž„ μŠ€νƒ¬ν”„κ°€μžˆλŠ” 2Γ—1 숫자 ν˜• λ°°μ—΄λ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€. diffλ‘˜ μ‚¬μ΄μ˜ 차이λ₯Ό μ·¨ν•©λ‹ˆλ‹€.


였래된 μ†”λ£¨μ…˜, 41 λ°”μ΄νŠΈ :

disp(-diff(datenum(strsplit(input('')))))

μž…λ ₯은 μ‰Όν‘œλ‘œ ꡬ뢄 된 λ¬Έμžμ—΄μ΄μ–΄μ•Όν•©λ‹ˆλ‹€.

disp(-diff(datenum(strsplit(input('')))))
'2015-12-03, 2014-12-22'
   346

ν˜ΈκΈ°μ‹¬ λ§Žμ€ ν”„λ‘œκ·Έλž˜λ° 방법. μ΄λŠ” 데이터 μœ ν˜• κ°„ MATLAB의 μ•”μ‹œ 적 μΊμŠ€νŒ…μœΌλ‘œ 인해 μž‘λ™ν•©λ‹ˆλ‹€.

의 좜λ ₯ strsplit(input(''))은 λ¬Έμžμ—΄ μ…€μž…λ‹ˆλ‹€. diffμ…€μ—μ„œ μ‚¬μš©ν•  μˆ˜λŠ” μ—†μ§€λ§Œ λ‹€ν–‰νžˆλ„ datenumμž‘λ™ν•˜λ©° μ‹€μ œλ‘œ μ…€ μž…λ ₯을 2Γ—1 숫자 λ°°μ—΄λ‘œ λ‹€μ‹œ μΊμŠ€νŒ…ν•˜μ—¬diff μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

에 λ§Žμ€ ꡬ뢄 기호λ₯Ό 지정할 수 strsplitμžˆμ§€λ§Œ μ‰Όν‘œκ°€ κΈ°λ³Έκ°’μž…λ‹ˆλ‹€. λ˜ν•œ κΈ°λ³Έ μž…λ ₯ datenumν˜•μ‹μ€yyyy-mm-dd μž…λ‹ˆλ‹€. μ΄λŸ¬ν•œ 이유둜 datenum (s, β€˜yyyy-mm-dd’)κ³Ό 같은 λ§Žμ€ 사양을 ν”Όν•¨μœΌλ‘œμ¨ 전체 λ°”μ΄νŠΈλ₯Ό μ ˆμ•½ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λ ˆμ½”λ“œμ˜ 경우 ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•  수 있으면 21 λ°”μ΄νŠΈμž…λ‹ˆλ‹€.

@(s)-diff(datenum(s))