4
\$\begingroup\$

At the Code-Golf™ Psychological Society, you are delighted to present a new method of measuring mental age: Abstract Capacity™.

To get the Abstract Capacity of a person, you take their actual age divided by 4, take their IQ divided by 9, then add the two values together. Then, round this sum down to find the Abstract Capacity.

Challenge

Write a program, given an actual age A and an IQ of I, produces the Abstract Capacity using those values. The program should also print how older (age) or how smarter (IQ) someone should be in order to raise their Abstract Capacity by 1.

An input will always look something like

A I

and an output will always look something like

AC A' I'

where AC, A' and I' respectively denote the Abstract Capacity, how older someone has to be to raise their Abstract Capacity, and how smarter someone has to be to raise their Abstract Capacity.

Examples

Input

13 43 

Output

8 4 9

Input

92 5 

Output

23 2 4

Input

40 17 

Output

11 1 1

Rules

Your code must be able to find the Abstract Capacity for any given A and I when 1 < A,I < 400.

This is . Shortest answer in bytes wins!

\$\endgroup\$
9
  • 17
    \$\begingroup\$ You can only use one of the languages commonly pre-installed on Mac such as C, C++, Java, PhP, Perl, Python (2 or 3), Ruby, and Swift. - I strongly suggest allowing any language to compete. \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 27, 2017 at 8:56
  • 3
    \$\begingroup\$ Also, some more test cases would be helpful in order to test our submissions. \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 27, 2017 at 9:09
  • \$\begingroup\$ If I am not wrong, by increasing 43 by 7, you get 14/4+50/9 which is higher than 9 (i.e. 9.0(5)). If the expected result is always int(a/4+i/9 + 1), then the whole answer would be [int(a/4+i/9),4,9] for all cases. \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 27, 2017 at 9:24
  • \$\begingroup\$ @Mr.Xcoder You put 14/4 instead of 13/4. I can confirm that 13/4+50/9>9. Also, I've edited the question in line with your previous suggestions. \$\endgroup\$
    – user73767
    Commented Aug 27, 2017 at 9:45
  • \$\begingroup\$ Now that you have removed the restriction, I upvoted this challenge \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 27, 2017 at 9:48

8 Answers 8

2
\$\begingroup\$

Python 2, 61 bytes

def f(a,i):r=a*9+i*4;print r/36,(r+44-i*4)/9-a,(r+39-a*9)/4-i

Try it online!

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

Python 2, 50 bytes

-1 byte thanks to Mr. Xcoder (print instead of return).

def f(a,i):x=a*9+i*4;m=x%36;print x/36,4-m/9,9-m/4

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ Switch to print to save 1 byte? \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 27, 2017 at 10:04
  • \$\begingroup\$ Oh yeah - I always assumed we could only print the result if it is a full program, while a function must actually yield the result. Do you know if there is a consensus? \$\endgroup\$ Commented Aug 27, 2017 at 10:06
  • 1
    \$\begingroup\$ I have used it many times without problems. I don't know if there is any consensus. \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 27, 2017 at 10:07
  • \$\begingroup\$ Here's the consensus. \$\endgroup\$ Commented Aug 27, 2017 at 12:13
  • \$\begingroup\$ Ah cool, thanks @totallyhuman! \$\endgroup\$ Commented Aug 27, 2017 at 12:14
1
\$\begingroup\$

Pyth, 26 bytes

/K+*9Q*4E36-4/J%K36 9-9/J4

Try it here!

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

JavaScript (ES6), 67 50 bytes

f=
(a,i,r=a*9+i*4)=>[r/36|0,4-(r%36/9|0),9-(r%36>>2)]
<div oninput=[ac.textContent,ea.textContent,ei.textContent]=f(a.value,i.value)>Age: <input type=number id=a><br>IQ: <input type=number id=i><br>Abstract Capacity: <span id=ac></span><br>Extra age needed: <span id=ea></span><br>Extra IQ needed: <span id=ei>

Edit: Although originally I was trying to verify @Mr.Xcoder's comment I ended up verifying @JonathanAllan's answer instead.

\$\endgroup\$
1
  • \$\begingroup\$ 61 bytes: (a,i,r=(a*9+i*4))=>[r/36|0,(r+44-i*4)/9-a|0,(r+39-a*9)/4-i|0]. Not 100% sure it is correct, but I believe it is \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 27, 2017 at 9:59
1
\$\begingroup\$

05AB1E, 21 19 18 bytes

94S©*O36‰RĆÁ®÷®RαÁ

Try it online!

Explanation

Example for input = [92, 5]

94                   # push the number 94
  S©                 # split to a list of digits and store a copy in register
                     # STACK: [9,4]
    *                # element-wise multiplication with input
                     # STACK: [828, 20]
     O               # sum
                     # STACK: 848
      36‰            # divmod 36
                     # STACK: [23, 20]
         R           # reverse
          Ć          # append the head (the mod result)
           Á         # rotate right
                     # STACK: [20, 20, 23]
            ®÷       # element-wise integer division with the register
                     # STACK: [2, 5, 23]
              ®Rα    # absolute difference with the register reversed
                     # STACK: [2, 4, 23]
                 Á   # rotate right
\$\endgroup\$
1
\$\begingroup\$

MATL, 25 22 bytes

K9hGy/sktQ3M1YS-b*XkG-

-3 bytes thanks to @LuisMendo

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ [4 9] can be shortened to K9h, and tGw to Gy: K9hGy/sktQ3M1YS-b*XkG- \$\endgroup\$
    – Luis Mendo
    Commented Sep 3, 2017 at 19:27
  • \$\begingroup\$ @LuisMendo Thanks! \$\endgroup\$
    – Cinaski
    Commented Sep 4, 2017 at 6:55
0
\$\begingroup\$

Excel, 89 bytes

=INT(A2/4+B2/9)&" "&ROUNDUP(4-MOD(A2*9+B2*4,36)/9,0)&" "&ROUNDUP(9-MOD(A2*9+B2*4,36)/4,0)

Using @Jonathan Allan's approach.

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

Java 8, 77 67 bytes

Nicked from @JonathanAllan

a->i->System.out.printf("%d %d %d",(i=a*9+i*4)/36,4-i/9%4,9-i/4%9);
\$\endgroup\$
1
  • \$\begingroup\$ 67 bytes: a->i->System.out.printf("%d %d %d",(i=a*9+i*4)/36,4-i/9%4,9-i/4%9);. \$\endgroup\$
    – Nevay
    Commented Sep 4, 2017 at 14:16

Your Answer

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