# Puzzle : Find minimum resource allocation on multiple of 10 or 12 only [closed]

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)

• 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. – user12205 May 25 '14 at 9:07
• 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. – user12205 May 25 '14 at 9:20

# Perl, 83

$l=$ARGV;for$i(0..$l){for$j(0..$l){if(10*$i+12*$j==$l){print$i+\$j;exit}}}print-1


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)
1.0
sage: n(12)
1.0
sage: n(5)
-1
sage: n(22)
2.0
sage: n(23)
-1
sage: n(9999999)
-1
sage: n(1<<31)
178956971.0


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.