0
\$\begingroup\$

Task

Take in 3 inputs. The length of the wall, the height of the wall and the coverage of the paint. Output how many tins of paint are required.

Output

Since there's no way to purchase 1/3 tin of paint, you'll need to round the amount of paint tins up to the nearest integer.

Assumptions/Stipulations

  • Only 1 coat of paint is required
  • Round up in terms of paint tins required

Test Cases

Length: 20 meters | Height: 7 meters | Coverage: 12 meters = 12 tins of paint

Input Output
1/1/10 1
5/5/10 3
2/3/8 1
5/8/8 5
45/5/18 13
20/7/12 12
1/1/1 1
200/10/14 143

Current Winners! (28th November 2023)

Jelly - 3 bytes - Jonathan Allan https://codegolf.stackexchange.com/a/267131/91342

Uiua - 3 bytes - chunes https://codegolf.stackexchange.com/a/267109/91342

Vyxal 3 - 3 bytes - Nick Kennedy https://codegolf.stackexchange.com/a/267138/91342

APL - 3 bytes - Tbw https://codegolf.stackexchange.com/a/267134/91342

Vyxal - 3 bytes - Iyxal https://codegolf.stackexchange.com/a/267112/91342

\$\endgroup\$
6
  • 11
    \$\begingroup\$ -1 because this isn’t interesting in the slightest. I really recommend you wait for feedback in the Sandbox before posting a challenge. \$\endgroup\$
    – noodle man
    Nov 27, 2023 at 12:22
  • 1
    \$\begingroup\$ @noodleman Perhaps, but I'm happy with the turnout in terms of answers :-)I thought about making each input be a different unit, so meters, meters squared, feet, inches, miles etc and making them convert but I think it would all boil down to the shortest conversion for all answers so I chose to omit. Let me know you're thoughts! \$\endgroup\$ Nov 27, 2023 at 14:08
  • 6
    \$\begingroup\$ That idea seems to fall into a common challenge-writing trap of combining many not-directly-related sub tasks and just stacking them on top of each other. I can’t think of a more interesting variant of this challenge, but that’s not to say one doesn’t exist. Don’t feel too discouraged if you write a few poorly-received challenges before you write one that clicks; just please wait for feedback in the Sandbox for future ideas. If you don’t get any feedback, you can bring your post up in the site’s chatroom The Nineteenth Byte (see footer) \$\endgroup\$
    – noodle man
    Nov 27, 2023 at 17:56
  • 2
    \$\begingroup\$ @noodleman Appreciate the information, thank you very much :-) I'll make sure to use the sandbox in future to vet questions \$\endgroup\$ Nov 28, 2023 at 9:08
  • 6
    \$\begingroup\$ Showing only the "3 bytes winners" doesn't make much sense. We emphasize competition within each language, and this is what this leaderboard snippet does. \$\endgroup\$
    – Arnauld
    Nov 29, 2023 at 9:01

21 Answers 21

6
\$\begingroup\$

Jelly, 3 bytes

P÷Ċ

A monadic Link that accepts the dimensions on the left and the paint tin coverage on the right and yields the number of tins required.

Try it online!

How?

P÷Ċ - Link: Dimensions, Coverage
P   - product {Dimensions}
 ÷  - divide by {Coverage}
  Ċ - ceiling
\$\endgroup\$
6
\$\begingroup\$

Uiua,  4  3 bytes

⌈×÷

Try it!

-1 thanks to alephalpha

Takes input in the order coverage length height

⌈×÷
  ÷  # divide first two args
 ×   # multiply by third
⌈    # ceiling
\$\endgroup\$
1
  • 2
    \$\begingroup\$ You can do ⌈×÷, and take input in the order coverage length height. \$\endgroup\$
    – alephalpha
    Nov 28, 2023 at 1:53
5
\$\begingroup\$

Vyxal 3, 3 bytes

÷×⌈

Try it Online!

Similar to most other answers. Divide by coverage, multiply by other dimension, take ceiling.

\$\endgroup\$
4
\$\begingroup\$

APL (Dyalog Classic), 3 bytes

⌈÷/

Try it online!

Written as a tacit function that takes a vector with entries length, coverage, and height, in that order.

÷/, read as Divide Reduce, calculates length ÷ coverage ÷ height. Since APL evaluates right to left, this gives length ÷ (coverage ÷ height) = (length × height) ÷ coverage. takes the ceiling of the result.

\$\endgroup\$
3
\$\begingroup\$

APL+WIN, 6 bytes

Prompts for three numbers. Coverage followed by wall dimensions:

⌈⎕×⎕÷⎕

Try it online! Thanks to Dyalog Classic

\$\endgroup\$
3
\$\begingroup\$

Arturo, 15 bytes

$=>[ceil//&*&&]

Try it!

$=>[ceil//&*&&]
$=>[          ]  ; a function
          &*&    ; multiply first arg by second
        //   &   ; divide by third
    ceil         ; ceiling
\$\endgroup\$
3
\$\begingroup\$

Scala 3, 20 bytes

(l,h,c)=>(l*h+c-1)/c

Attempt This Online!

\$\endgroup\$
3
\$\begingroup\$

Charcoal, 8 bytes

I±÷×NN±N

Try it online! Link is to verbose version of code. Explanation: Port of @SevC_10's Python answer.

    N       First input as a number
   ×        Multiplied by
     N      Second input as a number
  ÷         Integer divided by
       N    Third input as a number 
      ±     Negated
 ±          Negated
I           Cast to string
            Implicitly print
\$\endgroup\$
3
\$\begingroup\$

Retina 0.8.2, 39 bytes

.+
$*
1(?=1*¶(1+)¶)
$1
(1+)(?=1*¶1+¶\1)

Try it online! Takes input on separate lines but link is to test suite that splits on commas for convenience. Explanation:

.+
$*

Convert to unary.

1(?=1*¶(1+)¶)
$1

Multiply only the first number by the second.

(1+)(?=1*¶1+¶\1)

Partition the first number into as few values as possible that do not exceed the third number and output the size of the partition.

\$\endgroup\$
3
\$\begingroup\$

JavaScript (Node.js), 22 bytes

(a,b,c)=>(a*b+c-1)/c|0

Try it online!

JavaScript (Node.js), 20 bytes suggested by Arnauld

(x,y,z)=>~-(x*y+z)/z

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ 20 bytes with BigInts. \$\endgroup\$
    – Arnauld
    Nov 27, 2023 at 10:50
  • \$\begingroup\$ x*y-~z wouldn't be the same as x*y+~-z ? \$\endgroup\$ Nov 27, 2023 at 11:39
  • \$\begingroup\$ @NahuelFouilleul We need +z-1 (+~-z), not +z+1 (-~z). \$\endgroup\$
    – Arnauld
    Nov 27, 2023 at 12:55
  • \$\begingroup\$ @NahuelFouilleul As a reminder, -n is ~n + 1 by definition of two's complement. So -~n is n + 1, ~n is -(n + 1) = -n - 1 and ~-n is n - 1. \$\endgroup\$
    – Arnauld
    Nov 28, 2023 at 12:05
  • \$\begingroup\$ @Arnauld, thank you, understood, i thought at first glance that the two symbol could be inverted and some tests were passing but testing with values it was obvious. \$\endgroup\$ Nov 28, 2023 at 12:08
3
\$\begingroup\$

Python 3.8 (pre-release), 25 23 bytes

lambda l,h,c:-(-l*h//c)

Try it online!


Edit

  • -2 bytes thanks to Neil
\$\endgroup\$
2
  • 3
    \$\begingroup\$ I don't think you need the inner set of ()s. \$\endgroup\$
    – Neil
    Nov 27, 2023 at 12:21
  • 2
    \$\begingroup\$ -(...) can be 0-... \$\endgroup\$
    – Sisyphus
    Nov 29, 2023 at 0:31
3
\$\begingroup\$

Japt, 5 bytes

×/V c

Try it here

\$\endgroup\$
3
\$\begingroup\$

sclin, 6 bytes

/ * |^

Try it on scline! Takes input as H L C.

\$\endgroup\$
2
\$\begingroup\$

Vyxal r, 3 bytes

*/⌈

Try it Online!

Hehehehe flag go brrrr

\$\endgroup\$
2
\$\begingroup\$

PowerShell, 40 bytes

param($l,$h,$c)[math]::Ceiling($l*$h/$c)

Try it online!

Thanks Julian!

PowerShell, 47 bytes

$c={param($l,$h,$c)[math]::Ceiling(($l*$h)/$c)}

Try it online!

Thought I'd throw my own suggestion in :-)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can remove the function declaration from the body and remove the parentheses from the multiplication: Try it online! \$\endgroup\$
    – Julian
    Nov 28, 2023 at 3:49
2
\$\begingroup\$

Google Sheets, 18 bytes

=roundup(A1*B1/C1)

Put the input in cells A1:C1.

In Microsoft Excel, roundup() requires a second parameter (19 bytes):

=roundup(A1*B1/C1,)
\$\endgroup\$
1
  • \$\begingroup\$ roundup(X) can also be spelled ceiling(X) or -floor(-X) (which are all exactly the same length) \$\endgroup\$ Nov 28, 2023 at 15:56
2
\$\begingroup\$

ARBLE, 11 bytes

ceil(l*h/c)

Not the most imaginative answer. Arguments as coverage, height, length

Try it online!

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 3 bytes

/*î

Inputs in the order \$coverage,length,height\$.

Try it online or verify all test cases.

Explanation:

/    # Divide the second (implicit) input length by the first (implicit) input coverage
 *   # Multiply it to the third (implicit) input height
  î  # Ceil it
     # (after which the result is output implicitly)
\$\endgroup\$
2
\$\begingroup\$

MathGolf, 3 bytes

*́

Inputs (as floats) in the same order as the challenge description: \$length,height,coverage\$.

Try it online.

Explanation:

*    # Multiply the first two (implicit) inputs: height*length
 ╠   # Divide it by the third (implicit) input: (height*length)/coverage
  ü  # Ceil it
     # (after which the entire stack is output implicitly as result)
\$\endgroup\$
2
\$\begingroup\$

C (gcc), 27 24 bytes

f(l,h,c){l=(l*h+c-1)/c;}

Try it online!

Saved 3 bytes thanks to Sisyphus!!!

\$\endgroup\$
2
  • \$\begingroup\$ integer divison with (l*h+c-1)/c works i think \$\endgroup\$
    – Sisyphus
    Nov 29, 2023 at 0:34
  • \$\begingroup\$ @Sisyphus Nice one - thanks! :D \$\endgroup\$
    – Noodle9
    Nov 29, 2023 at 11:44
1
\$\begingroup\$

Pyth, 34 bytes

K.Q)=+Z*@K0@K1;J0;W>Z0=-Z@K2=+J1;J

Try it online!

I just wanted to try out in Pyth. Unfortunately, Pyth doesn't support float division so, had to use while to do the trick.

Explanation

K.Q) - get input in a newline, as in the question's order and store it as list in K

<Z - used to store the product of length and height i.e area

W>Z0=-Z@K2=+J1 - used to iterate until the area isn't 0 and decrement the area by coverage (@K2); and increment J by 1

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.