4
\$\begingroup\$

Imagine a company which award 0.1 holiday per each working day. Working days are from Mon to Fri (each week has 5 working days) regardless of being off. So If I'm off at Monday, I'll earn 0.1 holiday. Write a program that given number of current available holidays, it gives the number of days I can continuously take as off.

Example

As an example, imagine I have 12 off days right now. If I start continuously taking off days, I can take 13 days off (since I'll earn 1.2 holidays during the 12 days off). You should floor the number of holidays, so 1.2 will be 1.

Test Cases

0 => 0
4 => 4
9 => 9
12 => 13
19 => 21
20 => 22
123 => 136
\$\endgroup\$
5
  • 1
    \$\begingroup\$ "imagine I have 12 off days right now ... I can take 13 days off", so what is "off" here mean? Sat and Sun doesn't considered as an "off" here? Or otherwise, won't this lead to 19 days? \$\endgroup\$ Commented 23 hours ago
  • \$\begingroup\$ Why is "123 => 136"? 123+floor(123/10)=135 \$\endgroup\$ Commented 13 hours ago
  • 2
    \$\begingroup\$ My understanding is that 123→136 results from "regardless of being off" and further accumulation. Holidays count as working days and thus earn an additional 0.1 holidays each, and if such additional earned balance exceeds 1, you get yet another day off. So 8→8, 9→9 and 10→11, 18→19 but 19→21, 20→22. 123 holidays gets you 12 days off which get you 1 additional day off, and 123 + 12 + 1 = 136. Weekends are completely ignored. \$\endgroup\$ Commented 10 hours ago
  • \$\begingroup\$ Why is "19 => 21" ? when 19+floor(19/10)=20 or perhaps the formula is 19+round(19/10)=21 \$\endgroup\$ Commented 38 mins ago
  • \$\begingroup\$ @Rosario my take again: 19 holidays get you another 1.9 holidays, which get you an additional 1 day off, and that additional day off gets you another 0.1 days off, so you end up with 19 + 1.9 + 0.1 = 21. When flooring, observe the edge case 0→0. \$\endgroup\$ Commented 5 mins ago

46 Answers 46

3
\$\begingroup\$

R, 22 20 bytes

-2 bytes by porting doubleunary's solution

\(n)trunc(n+(n-1)/9)

Attempt This Online!

\$\endgroup\$
1
  • \$\begingroup\$ the second link is broken \$\endgroup\$ Commented 2 mins ago
2
\$\begingroup\$

05AB1E, 6 4 bytes

<9÷+

Try it online!

How it works:

<9÷+
<     Decrement the implicit input
 9÷   Integer divide that by 9 (note that this integer division rounds towards 0 rather than negative infinity)
   +  Add this result to the implicit input
\$\endgroup\$
2
\$\begingroup\$

Japt, 4 bytes

+´z9

Try it

+´z9     :Implicit input of integer
+        :Add
 ´       :  Decrement
  z9     :  Floor divide by 9
\$\endgroup\$
1
\$\begingroup\$

MathGolf, 6 bytes

┐9/+0╙

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Google Sheets, 19 bytes

=trunc(A1+(A1-1)/9)

screenshot

\$\endgroup\$
1
\$\begingroup\$

Polynomix, 12 bytes

x>x-1/9++x^.x

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Pari/GP, 19 bytes

n->max(n+(n-1)\9,n)

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Excel, 19 bytes

=TRUNC(A1+(A1-1)/9)

The Excel solution

\$\endgroup\$
1
\$\begingroup\$

Whitespace, 47 46 bytes

[S S S  N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_Input_as_Integer][T   T   T   _Retrieve_input][S N
S _Duplicate_input][S S S T N
_Push_1][T  S S S _Add][S S S T S S T   N
_Push_9][T  S T S _Integer_division][T  S S S _Add][T   N
S T _Output_as_number]

-1 (obvious) byte thanks to @TegahDOweh, for reminding me that it's been too long since I last golfed in Whitespace..

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Integer input = Read STDIN as integer
Integer result = (input+1) integer-divided by 9
Print result as integer to STDOUT
\$\endgroup\$
2
  • \$\begingroup\$ Wait... just push 0 instead of pushing 1 to get from the heap like this to save a byte. \$\endgroup\$ Commented 18 hours ago
  • \$\begingroup\$ @TegahDOweh Woops.. It's been too long since I've golfed in Whitespace apparently. 😅 \$\endgroup\$ Commented 15 hours ago
0
\$\begingroup\$

Gol><>, 13 bytes

I:z1kM9,S(++h

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Triangular, 10 bytes

$\:+%d/_9<

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Cubix, 12 bytes

u9(,I:/\p+O@

Try it online

    u 9
    ( ,
I : / \ p + O @
. . . . . . . .
    . .
    . .
\$\endgroup\$
0
\$\begingroup\$

APL+WIN, 14 bytes

Prompts for input.

0⌈n+⌊÷9÷-1-n←⎕

Try it online! Thanks to Dyalog Classic APL

\$\endgroup\$
0
\$\begingroup\$

JavaScript (Node.js), 11 bytes

Expects and returns a Bigint.

n=>n+~-n/9n

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Jelly, 5 bytes

a’:9+

Try it online or verify all test cases!

\$\endgroup\$
0
\$\begingroup\$

Python 2, 21 bytes

lambda n:n and~-n/9+n

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Vyxal 3, 5 bytes

‹9∻+Ġ

Vyxal It Online!

\$\endgroup\$
0
\$\begingroup\$

Python 3.8 (pre-release), 21 bytes

lambda n:int(~-n/9+n)

Try it online!

\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog Extended), 15 bytes

{⌊0⌈9÷⍨¯1+10×⍵}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

J, 16 bytes

>.(+<.@:%&9@:<:)

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Convex, 5 bytes

A*(9/

Try it online!

How it works:

A*(9/
A*     Multiply the implicit input by 10
  (    Decrement it
   9/  Integer divide by 9 (rounding towards 0)
\$\endgroup\$
0
\$\begingroup\$

Decimal, 28 bytes

81D3001101D42D1109D44D41D301

Try it online!

\$\endgroup\$
0
\$\begingroup\$

FALSE, 13 bytes

^1-$$0=~+9/+.

Try it online!

Input is the character with the codepoint of the input integer incremented, because I can't find another way for 0 to be included as an input.

\$\endgroup\$
0
\$\begingroup\$

BQN, 9 bytes

⌊⊢+9÷˜-⟜1

Try it

⌊ ⊢ + 9 ÷˜ -⟜1
           -⟜1   # argument - 1
        ÷˜       # divided by, with reversed arguments
      9          # 9
    +            # added to
  ⊢              # right argument
⌊                # floor
\$\endgroup\$
0
\$\begingroup\$

GolfScript, 9 bytes

~..!(+9/+

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Implicit, 7 bytes

:>0-/9+

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Haxe, 128 bytes

class Main {
 static public function main() {
  var f=function(n:Int):Int{return Std.int(Math.max(n+Std.int((n-1)/9),0));};
 }
}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Jellyfish, 15 bytes

pMm%<*10
 0 9 i

Try it online!

\$\endgroup\$
0
\$\begingroup\$

K (Kona), 11 bytes

{x+(x-1)%9}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Charcoal, 9 bytes

IL…÷⊖×Nχ⁹

Try it online! Link is to verbose version of code. Explanation:

  …         Range from 0 to
      N     Input as a number
     ×      Multiplied by
       χ    Predefined variable `10`
    ⊖       Decremented
   ÷        Integer divided by
        ⁹   Literal integer `9`
 L          Take the length
I           Cast to string
            Implicitly print

Since Charcoal only has Python's floor division and no truncate primitive, I had to find a way to special-case an input of 0, which is done by converting the final integer into a range and taking its length; the length of a negative range is zero, so this works here. Other alternatives would have been longer, e.g. ∧Iθ or ⌊⟦⁰.

\$\endgroup\$

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.