์ผ๋ง ์ ์ ๋๊น?
๊ท์น
- ๊ฐ ์ ์ถ๋ฌผ์ ์ ์ฒด ํ๋ก๊ทธ๋จ์ด์ด์ผํฉ๋๋ค.
- ํ๋ก๊ทธ๋จ์ ๋ ๊ฐ์ ์ผํ๋ก ๊ตฌ๋ถ ๋ ๋ ์ง๋ฅผ ํ์
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))