I have two types of notebook .

  • 10 problems could be solved in one page, in the first notebook.

  • 12 problems could be solved in one page, in the second notebook.

For given n problems I have to use pages in such a way that no space from both notebook should be wasted ever . Taking consideration that I have to use minimum pages also . Output should return number of pages need for solving all problem , if not passible it should return -1.

Example :

Problem count :  10

Output : 1 (one page from first notebook)

Problem Count :12

Output :1 (one page from second notebook)

Problem Count : 5

Output : -1 (Not possible)

Problem Count : 22

Output : 2(one from first notebook + one from second notebook)

Problem Count: 23

Output:-1(not possible)   

closed as off-topic by ace_HongKongIndependence, Martin Ender, Kyle Kanos, Doorknob May 25 '14 at 12:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." – ace_HongKongIndependence, Martin Ender, Kyle Kanos, Doorknob
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    \$\begingroup\$ What is your winning criterion? You've tagged it as [code-challenge] and [popularity-contest], but the two tags are mutually exclusive. Please read their tag excerpts to know what they mean, and decide which tag to use. \$\endgroup\$ – ace_HongKongIndependence May 25 '14 at 9:07
  • 2
    \$\begingroup\$ If your question is a code-challenge you need to specify an objective winning criterion so as to decide the winner. You need to write something like a scoring method, and include it in your post. You can look at other [code-challenge] questions and see what that means. \$\endgroup\$ – ace_HongKongIndependence May 25 '14 at 9:20

Perl, 83


With the lack of clear winning criteria, I've decided to go for golf. I'll probably change that once things are clarified.


Sage, 174 bytes

Golfed because the question does not specify a winning criterion.

def n(k):
 try:return p.solve()
 except:return -1

Brief explanation:

This uses the Sage built-in linear program solver (because why not). MILP(None,0) specifies it to use the default solver for minimization (same as MILP(maximization=False) but shorter). new_variable(0,0,1) is the same as new_variable(integer=True). When there is no solution, the solver will throw an exception: MIPSolverException: 'GLPK : There is no feasible integer solution to this Linear Program', which is caught and -1 is returned.

Sample IO:

sage: n(10)
sage: n(12)
sage: n(5)
sage: n(22)
sage: n(23)
sage: n(9999999)
sage: n(1<<31)

Note that this submission may not work for some very large numbers because of floating point rounding issues.


JavaScript (ES6), 76 bytes

n=k=>{for(i=0;i<=k;i++)for(j=0;j<=k;j++)if(10*i+12*j==k)return i+j;return-1}

A JavaScript inplementation of the Perl answer. Simple for loops, not very interesting.


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