μΌλ§ μ μ λκΉ?
κ·μΉ
- κ° μ μΆλ¬Όμ μ 체 νλ‘κ·Έλ¨μ΄μ΄μΌν©λλ€.
- νλ‘κ·Έλ¨μ λ κ°μ μΌνλ‘ κ΅¬λΆ λ λ μ§λ₯Ό νμ
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))