時間の管理を手伝ってください


15

私は最近、新年までに物理教科書全体を読むように言われました(残念ながら実話)。毎日どの章を読むべきかを決めるのにあなたの助けが必要です。ここがあなたの出番です。

入力

  • 任意の形式の2つの日付。2番目の日付は常に最初の日付より後です。
  • 章番号のリスト。このコンマ区切りリストには、単一の章(12)または包括的範囲(1-3)を含めることができます。例 1-3,5,6,10-13
  • Monday -> Moスケジュールから除外する曜日のリスト(名前の最初の2文字で表されます)。例 Mo,Tu,Fr

出力

出力は、改行で区切られた日付と章番号のリストになります(以下の形式を参照)。支部は、指定された平日を除き、範囲内のすべての日に均等に分散する必要があります。チャプターが均等に分配されない場合は、期間の終わりにチャプターの量が少ない日があるようにします。出力の日付は、入力とは異なる形式にすることができます。チャプターがない日は省略できますが、単にチャプターがない場合もあります。

例:

入力: 9/17/2015 9/27/2015 1-15 Tu

出力:

9/17/2015: 1 2
9/18/2015: 3 4
9/19/2015: 5 6
9/20/2015: 7 8
9/21/2015: 9 10
9/23/2015: 11
9/24/2015: 12
9/25/2015: 13
9/26/2015: 14
9/27/2015: 15

例の入力は、9/22は火曜日であるため、「9/17/2015 9/27/2015 1-15 Tu」である必要があります。
DavidC

@DavidCarraherあなたは正しいです、私がサンプル入力をしたとき、私は何らかの理由で11月を考えていました。
GamrCorps

7
それが私の場合、最後の日付にはすべての章があります:)
MickyT

@MickyTは、まさにこのチャレンジに対する私のインスピレーションです。
-GamrCorps

物理学がどれほど素晴らしいかがすぐにわかるでしょう。あなたは実際に幸運です。
fcalderan

回答:


2

PowerShellのV4、367 357 323 313 308 307 305 277のバイト

param($a,$b,$c,$d)$e=@();$c=-split('('+($c-replace'-','..'-replace',','),(')+')'|iex|%{$_-join' '});while($a-le$b){if(-join"$($a.DayOfWeek)"[0,1]-notin$d){$e+=$a;$z++}$a=$a.AddDays(1)}$g=,0*$z;$c|%{$g[$c.IndexOf($_)%$z]++};1..$z|%{"$($e[$_-1]): "+$c[$i..($i+=$g[$_-1]-1)];$i++}

編集-明示的な入力フォーマットを使用して28バイトをゴルフしました。

説明:

param($a,$b,$c,$d)    # Parameters, takes our four inputs
$e=@()                # This is our array of valid output dates

$c=-split('('+($c-replace'-','..'-replace',','),(')+')'|iex|%{$_-join' '})
# Ridiculously complex way to turn the input chapters into an int array
# The first part changes "1,5-9,12" into a "(1),(5..9),(12)" format that
# PowerShell understands, then executes that with iex, which creates an 
# array of arrays. Then iterate through each inner array and joins them all
# together with spaces, then finally splits on spaces to create a 1D array

while($a-le$b){       # Until we reach the end day
  if(-join"$($a.DayOfWeek)"[0,1]-notin$d){
    # Not an excluded day of the week
    $e+=$a            # Add it to our list of days
    $z++              # Increment our count of total days
  }
  $a=$a.AddDays(1)    # Move to the next day in the range
}

$g=,0*$z              # Populate a new array with zeroes, same length as $e

$c|%{$g[$c.IndexOf($_)%$z]++}
# This populates $g for how many chapters we need each day

1..$z|%{"$($e[$_-1]): "+$c[$i..($i+=$g[$_-1]-1)];$i++}
# Goes through the days in $e, prints them, and slices $c based on $g

使用法

日付が.NET DateTime形式であることが期待されます。「スキップされた」日が配列(PowerShellに相当するリスト)になることを期待します。

PS C:\Tools\Scripts\golfing> .\help-me-manage-my-time.ps1 (Get-Date '9/17/2015') (Get-Date '9/27/2015') '5,1-3,6,10-13,20-27' @('Su','Tu')
09/17/2015 00:00:00: 5 1 2
09/18/2015 00:00:00: 3 6
09/19/2015 00:00:00: 10 11
09/21/2015 00:00:00: 12 13
09/23/2015 00:00:00: 20 21
09/24/2015 00:00:00: 22 23
09/25/2015 00:00:00: 24 25
09/26/2015 00:00:00: 26 27

3
ここには非常に多くのドル記号があります...これは高価なはずです!:D
kirbyfan64sos

@ kirbyfan64sosここに登場するキャラクターはたったの12%$です...これはPowerShellゴルフでは実際にはかなり平均的なもので、10%から15%程度です(投稿した回答の私自身の非公式の計算に基づく)。
AdmBorkBork

再びあなたに:-)
ウィレム

私もHmm 308 ...-
ウィレム

305でよくやった!300今:-)
ウィレム

3

JavaScript(ES6)、317 310 291バイト

(a,b,c,d)=>{u=0;c.split`,`.map(m=>{p=m[s]`-`;for(q=n=p[0];n<=(p[1]||q);r=++u)c+=","+n++},c="");c=c.split`,`;x=d.map(p=>"SuMoTuWeThFrSa".search(p)/2);for(g=[];a<b;a.setTime(+a+864e5))x.indexOf(a.getDay())<0&&(t=y=g.push(a+" "));return g.map(w=>w+c.slice(u-r+1,u-(r-=r/y--+.99|0)+1)).join`
`}

使用法

f(new Date("2015-09-17"),new Date("2015-09-27"),"5,1-4,6,10-13,20-27",["Su","Tu"])
=> "Thu Sep 17 2015 10:00:00 GMT+1000 (AUS Eastern Standard Time) 5,1,2
Fri Sep 18 2015 10:00:00 GMT+1000 (AUS Eastern Standard Time) 3,4,6
Sat Sep 19 2015 10:00:00 GMT+1000 (AUS Eastern Standard Time) 10,11
Mon Sep 21 2015 10:00:00 GMT+1000 (AUS Eastern Standard Time) 12,13
Wed Sep 23 2015 10:00:00 GMT+1000 (AUS Eastern Standard Time) 20,21
Thu Sep 24 2015 10:00:00 GMT+1000 (AUS Eastern Standard Time) 22,23
Fri Sep 25 2015 10:00:00 GMT+1000 (AUS Eastern Standard Time) 24,25
Sat Sep 26 2015 10:00:00 GMT+1000 (AUS Eastern Standard Time) 26,27"

説明

(a,b,c,d)=>{

  u=0;                                                 // u = total chapters
  c.split`,`.map(m=>{                                  // c = array of each chapter
    p=m[s]`-`;
    for(q=n=p[0];n<=(p[1]||q);r=++u)                   // get each chapter from ranges
      c+=","+n++
  },c="");
  c=c.split`,`;

  x=d.map(p=>"SuMoTuWeThFrSa".search(p)/2);            // x = days to skip
  for(g=[];a<b;a.setTime(+a+864e5))                    // for each day between a and b
    x.indexOf(a.getDay())<0&&                          // if this day is not skipped
      (t=y=g.push(a+" "));                             // add it to the list of days
                                                       // t = total days
                                                       // y = days remaining

  return g.map(w=>w+
    c.slice(u-r+1,u-(r-=r/y--+.99|0)+1)                // add the chapters of the day
  ).join`
`
}

2

パイソン2 - 338 317 308 304 300

ここでボールを転がしに行きます...

def f(a,b,c,d):
 from pandas import*;import numpy as n
 s=str.split;e=n.array([])
 for g in s(c,','):h=s(g,'-');e=n.append(e,range(int(h[0]),int(h[-1])+1))
 k=[t for t in date_range(a,b) if s('Mo Tu We Th Fr Sa Su')[t.weekday()]not in d];j=len(k);e=array_split(e,j)
 for u in range(j):print k[u],e[u]

入力例:

f('9/17/2015','9/27/2015','5,1-3,6,10-13,20-27',['Su','Tu'])

出力例:

2015-09-17 00:00:00 [ 5.  1.  2.]
2015-09-18 00:00:00 [ 3.  6.]
2015-09-19 00:00:00 [ 10.  11.]
2015-09-21 00:00:00 [ 12.  13.]
2015-09-23 00:00:00 [ 20.  21.]
2015-09-24 00:00:00 [ 22.  23.]
2015-09-25 00:00:00 [ 24.  25.]
2015-09-26 00:00:00 [ 26.  27.]
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.