就業日カウントダウン


17

ワークライフをより簡単にするための天才的なアイデアがありました-就業日のみをカウントする特定の日付へのカウントダウン。


基本的なタスクは、カウントダウンに就業日のみを含む特定の日付までのカウントダウンを作成することです。

就業日は月曜日火曜日水曜日木曜日金曜日にカウントされます。

入力は「非公式」ヨーロッパ標準形式の特定の日付であるdd.MM.yyyy必要があり、今日または将来の日付でなければなりません。

出力は、残りの日数のみである必要があります。

それのよう最短コード勝ち。


テストケース:

  Today    |   Input    | Output
10.12.2018 | 17.12.2018 |    5
02.10.2018 | 16.10.2018 |   10

私が質問でいくつかのことを逃した場合、私を許してください-それは私の最初の質問です:)

編集:

  • <-のfalse代わりに出力として使用できますが、0 美しくありません
  • DSTを尊重する必要はありません

9
この「非公式な」ヨーロッパ入力形式の背後にある特定の理由はありますか?私たちのコンセンサスは、可能な限り柔軟な入力を許可することです。
アーナルド

6
処理が難しい日付形式の「余分な課題」を追加することには、本当にポイントがありますか?それは、柔軟な日付形式を持つ不公平なWRT言語のように思えます
...-Quintec

3
@Hille私はそれが「ハード」だとは言いませんでした。特にコードゴルフでは不必要な面倒です...上記のArnouldのリンクに注意してください...一般的に柔軟な入力が標準です...
Quintec

6
ところで、これはあなたの最初の挑戦であることに注意してください。mainにチャレンジを投稿する前に、The Sandboxを使用して改良してください。それ以外の場合は、すてきな仕事、そして私はあなたからいくつかを見て楽しみます!
ジュゼッペ

7
厳密な入力形式には本当に感心しませんでしたが、それ以外は良い挑戦です。
エルペドロ

回答:


18

05AB1E130の 128 133 131 124 123 バイト

žežfžg)V0[Y`UÐ3‹12*+>13*5÷s3‹Xα©т%D4÷®т÷©4÷®·()ćsO7%2@+Y`т‰0Kθ4ÖUD2Qi\28X+ë<7%É31α}‹iY¬>0ëY1¾ǝDÅsD12‹i>1ë\1Dǝ¤>2}}ǝVYI'.¡Q#

気が狂いました。

ゴルフの言語05AB1Eにとっては、入力しているかどうかは全く問題ではありません.-。ただし、05AB1Eには、Dateオブジェクトまたは計算用の組み込み機能はありません。日付に関する唯一の組み込みは、今日の年/月/日/時間/分/秒/マイクロ秒です。

そのため、表示されるコードのほとんどは、翌日に移動して曜日を計算するための手動計算です。

Zellerの式で忘れていた部分のために+5バイト(1月と2月の場合は年1)

オンラインそれを試してみたり「今日のエミュレートされた自己指定した日付とオンラインそれを試してみてください

説明:

着信テキストの壁。

一般に、コードは次の擬似コードに従います。

1   Date currentDate = today;
2   Integer counter = 0;
3   Start an infinite loop:
4*    If(currentDate is NOT a Saturday and currentDate is NOT a Sunday):
5       Counter += 1;
6*    currentDate += 1; // Set currentDate to the next day in line
7     If(currentDate == parsed input-string):
8       Stop the infinite loop, and output the counter

1)Date currentDate = today;05AB1Eプログラムのこの部分:

že          # Push today's day
  žf        # Push today's month
    žg      # Push today's year
      )     # Wrap them into a single list
       V    # Pop and store this list in variable `Y`

2)Integer counter = 0;および3)Start an infinite loop:は、05AB1Eプログラムでは簡単です。

0     # Push 0 to the stack
 [    # Start an infinite loop

4)If(currentDate is NOT a Saturday and currentDate is NOT a Sunday):手動計算の最初の難しい部分です。05AB1Eには日付が組み込まれていないため、曜日を手動で計算する必要があります。

これを行う一般的な式は次のとおりです。

h=(q+13(m+1)5+K+K4+J42J)mod7,

3月から12月までの期間:

  • qある(月)day[1, 31]
  • mは1から始まる()month[3, 12]
  • Kは世紀の()yearmod100
  • Jは0から始まる世紀です()year100

そして、1月と2月の間:

  • qある(月)day[1, 31]
  • mは1から始まる()month+12[13, 14]
  • Kは前年の世紀の年()(year1)mod100
  • Jは前年の0から始まる世紀です()year1100

結果は曜日になります。0=土曜日、1 =日曜日、...、6 =金曜日です。出典:Zellerの合同h

05AB1Eプログラムのこの部分でこれを確認できます。

Y             # Push variable `Y`
 `            # Push the day, month, and year to the stack
  U           # Pop and save the year in variable `X`
   Ð          # Triplicate the month
    3        # Check if the month is below 3 (Jan. / Feb.),
              # resulting in 1 or 0 for truthy/falsey respectively
      12*     # Multiply this by 12 (either 0 or 12)
         +    # And add it to the month
              # This first part was to make Jan. / Feb. 13 and 14

>             # Month + 1
 13*          # Multiplied by 13
    5÷        # Integer-divided by 5
s3           # Check if the month is below 3 again (resulting in 1 / 0)
   Xα         # Take the absolute difference with the year
     ©        # Store this potentially modified year in the register
      т%      # mYear modulo-100
D4÷           # mYear modulo-100, integer-divided by 4
®т÷©4÷        # mYear integer-divided by 100, and then integer-divided by 4
®·(           # mYear integer-divided by 100, doubled, and then made negative
)             # Wrap the entire stack into a list
 ć            # Extract the head (the counter variable that was also on the stack)
  s           # Swap so the calculated values above are as list at the top
   O          # Take the sum of this entire list
    7%        # And then take modulo-7 to complete the formula,
              # resulting in 0 for Saturday, 1 for Sunday, and [2, 6] for [Monday, Friday]

2@            # Check if the day is greater than or equal to 2 (so a working day)

5)またCounter += 1;簡単です:

     # The >=2 check with `2@` results in either 1 for truthy and 0 for falsey
+    # So just adding it to the counter variable is enough

6)currentDate += 1; // Set currentDate to the next day in line手動で行う必要があるため、ここでも複雑です。したがって、これは次の擬似コードに展開されます。

a   Integer isLeapYear = ...;
b   Integer daysInCurrentMonth = currentDate.month == 2 ?
c                                 28 + isLeapYear
d                                :
e                                 31 - (currentDate.month - 1) % 7 % 2;
f   If(currentDate.day < daysInCurrentMonth):
g     nextDate.day += 1;
h   Else:
i     nextDate.day = 1;
j     If(currentDate.month < 12):
k       nextDate.month += 1;
l     Else:
m       nextDate.month = 1;
n       nextDate.year += 1;

出典:
年がle年かどうかを判断するアルゴリズム。(編集:7バイトを節約したうるう年をチェックする代替方法を使用するため関連性がなくなりました。)
月の日数を決定するアルゴリズム。

6a)Integer isLeapYear = ...;05AB1Eプログラムでは次のように行われます。

Y             # Push variable `Y`
 `            # Push the days, month and year to the stack
  т‰          # Divmod the year by 100
    0K        # Remove all items "00" (or 0 when the year is below 100)
      θ       # Pop the list, and leave the last item
       4Ö     # Check if this number is visible by 4
         U    # Pop and save the result in variable `X`

この私の05AB1E回答でも使用されているため、手順を説明するためにいくつかの例年が追加されています。

6b)currentDate.month == 2 ?と6c)28 + isLeapYearは次のように行われます。

D            # Duplicate the month that is now the top of the stack
 2Q          # Check if it's equal to 2
   i         # And if it is:
    \        #  Remove the duplicated month from the top of the stack
     28X+    #  Add 28 and variable `X` (the isLeapYear) together

6d):と6e)31 - (currentDate.month - 1) % 7 % 2;は次のように行われます。

ë           # Else:
 <          #  Month - 1
  7%        #  Modulo-7
    É       #  Is odd (shortcut for %2)
     31     #  Push 31
       α    #  Absolute difference between both
}           # Close the if-else

6f)If(currentDate.day < daysInCurrentMonth):は次のように行われます。

     # Check if the day that is still on the stack is smaller than the value calculated
 i    # And if it is:

6g)nextDate.day += 1;は次のように行われます。

Y       # Push variable `Y`
 ¬      # Push its head, the days (without popping the list `Y`)
  >     # Day + 1
   0    # Push index 0

        # (This part is done after the if-else clauses to save bytes)
}}      # Close the if-else clauses
  ǝ     # Insert the day + 1 at index 0 in the list `Y`
   V    # Pop and store the updated list in variable `Y` again

6h)Else:および6i)nextDate.day = 1;は次のように行われます。

ë        # Else:
 Y       #  Push variable `Y`
  1      #  Push a 1
   ¾     #  Push index 0
    ǝ    #  Insert 1 at index 0 (days part) in the list `Y`

6j)If(currentDate.month < 12):

D           # Duplicate the list `Y`
 Ås         # Pop and push its middle (the month)
   D12     # Check if the month is below 12
       i    # And if it is:

6k)nextDate.month += 1;

>       # Month + 1
 1      # Push index 1

        # (This part is done after the if-else clauses to save bytes)
}}      # Close the if-else clauses
  ǝ     # Insert the month + 1 at index 1 in the list `Y`
   V    # Pop and store the updated list in variable `Y` again

6l)Else:、6m)nextDate.month = 1;、および6n)nextDate.year += 1;は次のように実行されます。

ë        # Else:
 \       #  Delete the top item on the stack (the duplicated month)
  1      #  Push 1
   D     #  Push index 1 (with a Duplicate)
    ǝ    #  Insert 1 at index 1 (month part) in the list `Y`

 ¤       #  Push its tail, the year (without popping the list `Y`)
  >      #  Year + 1
   2     #  Index 2

         # (This part is done after the if-else clauses to save bytes)
}}       # Close the if-else clauses
  ǝ      # Insert the year + 1 at index 2 in the list `Y`
   V     # Pop and store the updated list in variable `Y` again

そして最後に8)If(currentDate == parsed input-string):と9)でStop the infinite loop, and output the counter

Y          # Push variable `Y`
 I         # Push the input
  '.¡     '# Split it on dots
     Q     # Check if the two lists are equal
      #    # And if they are equal: stop the infinite loop
           # (And output the top of the stack (the counter) implicitly)

5
あなたは狂人です...賛成票を持っています。
AdmBorkBork

1
史上最長の05AB1Eプログラム?
ルイスメンドー

2
@LuisMendo閉じるが、私は私が持っている怖い1 05AB1E答え自分自身にもなったこと、そして1 近すぎるの方法来る.. ;)私はここにあり、いくつかのバイトゴルフにできるだろうと確信して簡素化翌日の擬似コード実装の一部。明日の朝に見えますが、スポーツから戻ってきて、すぐに寝ます。
ケビンクルーイッセン

11

Excel 24バイト

セルA1の入力を想定

=NETWORKDAYS(NOW()+1,A1)

組み込み関数を使用します。残念ながら、関数には今日と終了日の両方が含まれています。OPは今日はカウントしないことを明確にしているので、今日はカウントしないように、NOWに1つ追加します。

数値の形式に関するコメントに対処するには、これもExcelの標準です。 ここに画像の説明を入力してください


これは日付値で機能しますが、前述のとおり入力を取得できません。つまり、(少なくとも米国版では)10.12.2018日付ではなくセルに保持されている場合は文字列です。これを修正するための明らかだが長い解決策は、解決策に変更A1するDATE(RIGHT(A1,4),MID(A1,4,2),LEFT(A1,2))ことです
Taylor Scott

残念ながら、コミュニティは有効にするためにデフォルト設定で言語を実行する必要があることを決定しました(私がこれに見た唯一の例外は言語です-IE、あなたの言語が英語とスペイン語の両方をサポートしている場合、あなたはどちらかをすぐに使用できますが、さらに、OP(@hille)は、形式が柔軟であるとは述べておらず、実際、まったく逆のことを述べています(この質問の2番目のコメントを参照)
Taylor Scott

2
形式は標準ではなく、ロケールに基づいています。Excelは、HKCU\Control Panel\International\sDecimalレジストリ文字列から形式を読み取ります。MM / dd / yyyyのデフォルトの米国Windowsインストール上。ほとんどのEU諸国では、これがデフォルトになります。
エリックA

@luisMendoはい、動作します。明確な説明はありませんでした。代わりに前日をカウントしないことになっていた場合、= NETWORKDAYS(NOW()、A1-1)を使用できます。どの説明であっても、常に同じバイトカウントになることはわかっていました。
キータ-モニカを

嬉しいです。投票を削除しました
ルイスメンドー


8

Java 10、233 232 226バイト

import java.util.*;d->{int r=0;var s=Calendar.getInstance();s.setTime(new Date());var e=s.getInstance();for(e.setTime(new java.text.SimpleDateFormat("dd.MM.yyyy").parse(d));!s.after(e);s.add(5,1))if(s.get(7)%7>1)r++;return r;}

日付は常に、Javaがどれほど冗長であるかを思い出させます。

注:2つの短いのJava(175バイト以下)の答え、今があり、以前のバージョンのJavaから非推奨メソッドのスマートな使用と1によって@LukeStevens、および使用して1 java.time.LocalDateJavaの8以降の新機能のことをすることによって、@OlivierGrégoireが

オンラインでお試しください。

説明:

import java.util.*;            // Required import for both Calendar and Date
d->{                           // Method with String parameter and integer return-type
  int r=0;                     //  Result-integer, starting at 0
  var s=Calendar.getInstance();//  Create a Calendar instance for the start-date
  s.setTime(new Date());       //  Set the start date to today
  var e=s.getInstance();       //  Create a Calendar instance for the end-date
  for(e.setTime(               //  Set the end date to:
        new java.text.SimpleDateFormat("dd.MM.yyyy")
                               //   Create a formatter for the "dd.MM.yyyy" format
         .parse(d));           //   And parse the input-String to a Date
      !s.after(e)              //  Loop as long as we haven't reached the end date yet
      ;                        //    After every iteration:
       s.add(5,1))             //     Increase the start-date by 1 day
    if(s.get(7)%7>1)           //   If the day of the week is NOT a Saturday or Sunday:
                               //   (SUNDAY = 1, MONDAY = 2, ..., SATURDAY = 7)
      r++;                     //    Increase the result-sum by 1
  return r;}                   //  Return the result-sum

できますかe=s.clone()
Quintec

1
することもできますが(Calendar s=Calendar.getInstance(),e=s.getInstance()残念ながら)、これは残念ながらまったく同じ長さになります。
ミシャラブロフ

1
@MishaLavrovああ、C確かに静電気は必要ありません。それは、コードの古い部分からのもので、C他の場所でも使用していました。var s=Calendar.getInstance();var e=s.getInstance();おかげで1バイトゴルフできました。:)
ケビンクルーイッセン

1
150バイト、使用java.time
オリビエグレゴワール

1
できた!バイトで他の答えに非常に近いが、まだそれを負かしていない。
オリヴィエグレゴワール

7

JavaScript(ES6)、116 103バイト

f=(d,n=+new Date)=>(D=new Date(n)).toJSON()<d.split`.`.reverse().join`-`&&(D.getDay()%6>0)+f(d,n+864e5)

オンラインでお試しください!

どうやって?

JavaScriptタイムスタンプは、UNIXエポックから経過したミリ秒数として定義されます。現在のタイムスタンプは変数保持されます。n

各反復で、を使用して日付(JavaScriptオブジェクトとして)生成します。この日付は、メソッドを使用してISO 8601形式に変換されます。nD.toJSON()

YYYY - MM - DD T hhmmss.sss Z

この文字列はで始まるためYYYY-MM-DD、同様の形式の別の文字列と辞書式比較を実行しても安全です。これが、計算された日付を入力文字列形式(辞書式にソートできない)に変換するのではなく、入力文字列を変換する理由です。dYYYY-MM-DDDD.MM.YYYY

d.split`.`.reverse().join`-`

各再帰呼び出しの前にD.getDay()、(日曜日)と(土曜日)のどちらでもない場合、つまり法とする一致しない場合、最終結果をインクリメントします。0606

(D.getDay() % 6 > 0) + f(d, n + 864e5)

翌日に到達するためににミリ秒を追加します。86,400,000n


6

MATL、24バイト

46tQZt24&YO:Z':X-9XO83-z

オンラインでお試しください!

特定のコードのゴルフ言語が大きな利点を得るように、入力形式を持ちたくない

あなたは半分成功しました:-)

説明

46      % Push 46 (ASCII for '.')
tQ      % Duplicate, add 1: gives 47 (ASCII for '/')
Zt      % Implicit input. Replace '.' by '/' in the input string
24&YO   % Convert string with date format 24 ('dd/mm/yyyy') to serial date number.
        % This is an integer representing day starting at Jan-1-0000
:       % Inclusive range from 1 to that
Z'      % Push current date and time as a serial number. Integer part is day;
        % decimal part represents time of the day
:       % Inclusive range from 1 to that
X-      % Set difference. Gives serial numbers of days after today, up to input
9XO     % Convert each number to date format 9, which is a letter for each day
        % of the week: 'M', 'T', 'W', 'T', ' F', 'S', 'S'
83-     % Subtract 83 (ASCII for 'S')
z       % Number of nonzeros. Implicit display

私がチャレンジを正しく理解していれば、日付入力を1つだけ受け取り、それを今日の日付と比較します。例えば、16.10.2018だろう、今日(月曜日01-10-2018)で、結果11、明日10など、
ケビンCruijssen

@KevinCruijssenおっと。ありがとう!今修正
ルイスメンドー

1
そして、同じバイト数で。:)ナイス、私から+1。
ケビンクルーイッセン

6

Wolfram言語(Mathematica)64 56バイト

DayCount[Today,""<>#~StringTake~{{4,6},3,-4},"Weekday"]&

オンラインでお試しください!

DayCount[x,y,"Weekday"]xとの間の平日の数を数えyます。

入力xyは、DateObjectによって返されるような派手なものやToday、形式の文字列(残念ながら)を含む、多くのものmm.dd.yyyyです。

私の以前の試みは、Mathematicaにどのように解析するかを伝えることにより、dd.mm.yyyy入力をに変換しようとしましたDateObject。新しいソリューションは、文字列を単純に並べ替えて、Mathematicaが期待する順序で日と月を配置します。

それの価値が28バイトのソリューションがあることを指摘DayCount[Today,#,"Weekday"]&月-日-年の入力フォーマットのために完璧に動作しますが、また、正しく処理するだけでなく、明確なような日-月-年の入力31.12.2018おそらく「第31回の12日を意味することができませんでしたが、月"。だからそれは時間の60%以上が正しいです:)



5

R、72文字

@ngmが提供する回答のバリエーションで、greplが数文字を保存するのを避け、英語以外のロケールで動作します。

sum(strftime(seq(Sys.Date(),as.Date(scan(,""),"%d.%m.%Y"),1),'%u')<6)+1


1
より短く、より一般的です。素敵な答えと亡命へようこそ。
ngm

1
PPCGへようこそ!TIOリンクを追加できます-それは簡単で、あなたのために答えをフォーマットします:)
JayCe

5

Java(OpenJDK 8)174 166 165バイト

Kevinの回答から少しインスピレーションを得て、廃止されたDate APIを使った古き良きトロールにより、より簡潔なJavaソリューションを手に入れることができました。

Kevinの独創的な正規表現の日付解析による-8バイト

-1バイト、Nevayの賢いビット演算のおかげ

import java.util.*;d->{long r=0,s=new Date().getTime(),e=Date.parse(d.replaceAll("(..).(..).","$2/$1/"));for(;s<=e;s+=864e5)r-=-new Date(s).getDay()%6>>-1;return r;}

オンラインでお試しください!

説明

import java.util.*;                         // Required import for Date 
long r=0,                                   // Initialise result variable
     s=new Date().getTime(),                // Current date in millis
     e=Date.parse(
         d.replaceAll("(..).(..).","$2/$1/")// Use regex to convert to MM/dd/yyyy
     );                                     // Parse date arg using deprecated API
for(;s<=e;                                  // Loop while current millis are less than date arg (e.g. date is before)       
    s+=864e5)                               // Add 86400000 ms to current date (equiv of 1 day)
    r-=-new Date(s).getDay()%6>>-1;        // If day is Sunday (0) or Saturday (6) don't increment, else add 1
return r;                                   // When loop finished return result

1
いい答え!でのvarargsのスマートな使用d=d[0].splitと非推奨の.parseデフォルトのフォーマットMM/dd/yyyyformat。あなたの投稿の1つの小さな間違い、あなたはあなたのコードのimport java.text.*;代わりに、あなたの説明にあります(あなたが使っていなくても)。import java.util.*;// Required import for both Calendar and DateCalendar
ケビンCruijssen

@KevinCruijssenなぜ私がjava.text今修正したのか分かりません!ありがとう!
ルークスティーブンス

1
d=d[0].splitはvarargs が好きでしたが、入力を通常の文字列にd=d[0].split("\\.");変更d[1]+"/"+d[0]+"/"+d[2]し、削除してd.replaceAll("(..).(..).","$2/$1/") 7バイト節約するように変更しました。
ケビンクルーイッセン

1
に変更して、もう1バイト。:)r+=new Date(s).getDay()%6<1?0:1,s+=864e5);s+=864e5)r+=new Date(s).getDay()%6<1?0:1;
ケビンクルーイッセン

1
-1バイト:r-=-new Date(s).getDay()%6>>-1;
Nevay

4

、72バイト

func[a][b: now/date s: 0 until[if b/weekday < 6[s: s + 1]a < b: b + 1]s]

オンラインでお試しください!

日付をdd-mm-yyyy形式で取得します。たとえば、2018年10月10日(2018年10月10日でも機能します)

厳密な入力:

、97バイト

func[a][a: do replace/all a".""-"b: now/date s: 0 until[if b/weekday < 6[s: s + 1]a < b: b + 1]s]

オンラインでお試しください!

ボーナス:

指定した日付までの稼働日の日付/平日のリストを返します。

、235バイト

f: func [ a ] [
    b: now/date
    d: system/locale/days
    collect [ 
        until [ 
            if b/weekday < 6 [ 
                keep/only reduce [ b ":" d/(b/weekday) ]
            ]
            a < b: b + 1
        ]
    ]
]

オンラインでお試しください!


ああ、フェアではない、Pythonでは、このIOフォーマットの処理に約72バイトを費やす必要があります...:P
Quintec

1
通常、私のRedソリューションは最も長いものの1つですが、幸いなことにRedは日付を非常にうまく処理しています:)
ガレンイワノフ

1
pythonを処理するための90バイト...完了しました。より柔軟な入力形式になるまで終了します
。P– Quintec


3

パイソン2163の 156 149 147バイト

lambda s:sum((date.today()+timedelta(x)).weekday()<5for x in range((date(*map(int,(s.split(".")[::-1])))-date.today()).days))
from datetime import*

オンラインでお試しください!

-7 @mypetlionのおかげで

-7 @ovsのおかげでさらに

私は例えば、入力を取った私の以前のコードを投稿する前に私はちょうど気づいた非常に制限入力フォーマットによる30 (2018,11,1):-(


2
これは必要ありません(0,1)[t.weekday()<5]。Pythonブール値はのサブクラスでintありTrue, False、算術演算でとして使用できます1,0。で置き換えてc+=t.weekday()<57バイトを節約します。
-mypetlion

1
ラムダとして149バイト
-ovs

ありがとう@mypetlion。見逃してはいけません。
エルペドロ

ありがとう@ovs。2回目は最近助けました。前回は非常に印象的な-30だった。これをラムダに変換する方法を考えていました。
エルペドロ

3

Java(JDK 10)、171バイト

s->{int c=0;for(var t=java.time.LocalDate.now();!t.parse(s.replaceAll("(..).(..).(.*)","$3-$2-$1")).equals(t);t=t.plusDays(1))c-=t.getDayOfWeek().getValue()/6-1;return c;}

オンラインでお試しください!

クレジット


1
あなたは変更することができます(.*)\\.(.*)\\.(.*)にを(..).(..).(.*)
ケビンクルーッセン

replaceAllしかし、あなたのテクニックを使えば、彼の答えは7バイトでもゴルフできるので、あなたの方はまだ少し長くなります。;)
ケビンクルーイッセン

@KevinCruijssen正規表現をありがとう!心配する必要はありません。回答が長くても構いません;)
オリビエグレゴワール

3

JavaScriptの(Node.jsの)168の 160 139 133バイト

少ないおかげでバイト35 QuintecケビンCruijssen

D=>{var i=D.split('.'),n=0;for(var d=new Date();d<=new Date(i[2],i[1]-1,i[0]);d.setDate(d.getDate()+1))n+=-~d.getDay()%7>1;return n;}

オンラインでお試しください!

D=>{
  var i=D.split('.'),                 // Splits the date string by .
      n=0;                            // Counter variable
  for(var d=new Date();               // For the actual date
      d<=new Date(i[2],i[1]-1,i[0]);      // As long as the date is less or equal the requested date
      d.setDate(d.getDate()+1))           // Count the date one up
    n+=-~d.getDay()%7>1;                // If the date is not a Sunday or Saturday
  return n;                           // Return the counter variable
}

1
ラムダ付き158バイト
Quintec

1
if条件が改善された139バイト
Quintec

1
メソッドは再帰的ではないf=ため、バイトカウントにを追加する必要はありません(TIOではヘッダーに追加できます)。これが@Quintecが141バイトではなく139バイトであると述べた理由です。また、あなたが変更することができますif((d.getDay()+1)%7>1)n++;n+=-~d.getDay()%7>1;にゴルフにそれを133バイト
ケビンクルーッセン


1
将来の参照のためのいくつかのヒント
シャギー

3

Python3およびNumpy、96バイト

退屈な既成のソリューションよりも小さくなりませんでした...

from numpy import*
d=datetime64
lambda s:busday_count(d('today'),d(f'{s[6:]}-{s[3:5]}-{s[:2]}'))

オンラインでお試しください!


Python 3に入る必要があります;)
ElPedro

インポートに基づいて、Python 3ではなくnumpyを使用したPython 3を使用しています。
ジョナサンフレッチ

@JonathanFrechはタイトルに入れるべきですか?pythonには日付または時刻の組み込みデータ型がないため、Pythonを使用する他の人もライブラリを使用しています。
アーロン

1
これはあなたの定義に依存組み込みなどのモジュール- 日時は標準ライブラリモジュールであり、したがって、私はコア言語の一部としてそれらを数えるでしょう。ただし、numpyなどのサードパーティモジュールを使用すると、言語の機能が強化されるため、別の言語と見なされます。
ジョナサンフレッチ

2

PowerShell107 99バイト

Mazzyのおかげで-8バイト

$d,$m,$y=$args-split'\.';for($a=date;$a-lt(date "$y-$m-$d");$a=$a|% *ys 1){$o+=($a|% D*k)-in1..5}$o

オンラインでお試しください!

-split入力$argsで正規表現を実行し、値をそれぞれ$days、$months、および$yearsに保存します。次に、forループに入り、$a今日の日付に初期化します。whileループは継続し$aている-lESS t漢たちの入力目標日。反復ごとに1da ys$aに追加し、現在D*k(の略DayOfWeek)が範囲内1..5(月曜日から金曜日)にあるかどうかを確認します。そのブール結果は累積され$o、ループを抜けるとその値はパイプラインに残り、出力は暗黙的です。


100バイト?$d,$m,$y=$args-split'\.';for($a=date;$a-lt(date "$y-$m-$d");$a=$a|% *ys 1){$o+=($a|% D*k)-in1..5};$o
mazzy

1
@mazzy確かに。プラス、間にセミコロンfor(...){...}とを$o取り外すことができるので、我々は100未満になりましたよ!
AdmBorkBork

2

パイソン2147の 143 141 140バイト

from datetime import*
lambda e,s=date.today():sum((s+timedelta(x+1)).weekday()<5for x in range((date(*map(int,e.split(".")[::-1]))-s).days))

オンラインでお試しください!

「dd.MM.YYYY」の形式で終了日を表す文字列eを受け取ります。オプションで開始日も取得しますが、これはdatetime.dateであると予想されます。

開始日sは、時刻を無視するために、datetime.dateオブジェクトとして今日の日付にデフォルト設定されています。datetime.dateオブジェクトには解析メソッドがなく、日付時刻を日付に追加したり、日付から減算したりできないため、終了時刻はdatetime.datetimeオブジェクトに解析されてから日付に変換されます。(start、end]で毎日反復し、その週の日数が5未満の場合、合計に1を追加します([0-4]は[Mon-Fri]、[5-6]は[Sat-Sun])。

日時の解析は最悪です、皆さん。

編集:ElPedroのmap(int、thing)トリックを盗んで4バイトを節約しました。

編集2:電動ブーガル:それを匿名関数にすることで2バイトを保存しました。(アーロンに感謝!)

編集3:xrange->範囲。(ありがとう、アーロン!)


1
どういたしまして!いい答え:)
ElPedro

1
f=ここからラムダ式を
アーロン

1
「日時の解析は最悪です、皆さん」ハハハハは私の痛みを感じますが、あなたは私が失敗したところに成功しました:P
Quintec

@Aaron複数の関数で問題ないのかインポート文で問題ないのかわかりません、ありがとう!
トリガー測定

1
また、使用することができるrangeのではなく、xrangeそれはまだうまく動作するはずです。
アーロン

2

PHP、66バイト

for($t=time();$t<strtotime($argn);)$r+=date(N,$t+=86400)<6;echo$r;

0;の空の出力 +間に挿入echo$rて修正します。

でパイプとして実行する-nr、オンラインで試してください


単項出力の60バイト:

for($t=time();$t<strtotime($argn);)echo date(N,$t+=86400)<6;


1

IBM / Lotus Notesの式-99バイト

d:=i;c:=0;@While(d>@Today;@Set("c";c+@If(@Weekday(d)=1:7;0;1));@Set("d";@Adjust(d;0;0;-1;0;0;0)));c

日付/時刻フィールドから入力を取得しますi。の入力形式はseparatedにi設定されて.いるため、入力を変換する必要はありません。Notesは、それがどうなるかを前に伝える限り、任意の区切り記号を使用して日付入力を取ることができます(ごまかさないことを願っています!)。数式はo、同じフォームの計算された数値フィールドにあります。

余談興味深い:以来@For@While素晴らしいことでR6(と思う)での式言語に導入したダミアン・カッツのみ、私は彼らのために見つけた使用すると、コードゴルフです。本番アプリで使用したことはありません。

式に使用できるTIOはないため、2018年2月10日に撮影したスクリーンショットを次に示します。

ここに画像の説明を入力してください



1

K4、40バイト

解決:

{+/1<.q.mod[d+!(."."/:|"."\:x)-d:.z.d]7}

説明:

日付の差を計算し、7を法として週末を無視して合計します。

{+/1<.q.mod[d+!(."."/:|"."\:x)-d:.z.d]7} / the solution
     .q.mod[                         ]7  / modulo with 7
                                 .z.d    / UTC date
                               d:        / save as d
                              -          / subtract from
               (             )           / do this together
                       "."\:x            / split input on "."
                      |                  / reverse
                 "."/:                   / join back with "."
                .                        / take the value
              !                          / range 0..the difference
            d+                           / add today's date to range
   1<                                    / is 1 less than the modulo (ie is this mon-fri)?
 +/                                      / sum up

ノート:

  • 日付解析と同じバイト代替: "D"$,/|"."\:x


0

q、52 79バイト

{x:"D"$"."sv reverse"."vs x;i:0;while[x-.z.d;$[2>x mod 7;x-:1;[i+:1;x-:1]]];:i}

qでは、各日付には、千年紀の開始から何日が経過したかに基づいて、基になる整数値があります。これに「mod 7」を適用すると、曜日ごとに一意の値が得られます(土曜日は0、金曜日は6)。したがって、2> x mod 7の場合、週末のカウントを避けるために、カウンターをインクリメントしないでください。

編集:厳密な日付形式の欠落、編集

EDIT2:含まれています


1
私が思いついたのは{sum 1<mod[d+til("D"$x 10 vs 67893401)-d:.z.d]7}、K動詞に頼らずに48バイトだけです。
ストリートスター

リストインデックスの使用は、リバースよりもはるかにエレガントであり、ループを使用するのではなく、リストにmodを適用します。素晴らしい答え+1
Thaufeki
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.