PHP Developer Challenge – £100 Prize

Written by Ed Genochio on June 21, 2013

We’re looking for the most elegant solution to this programming conundrum.

The provider of the best solution gets a £100 prize – and the chance of a full-time developer job at stickee, too.

Entries must be received by the end of June 2013. (Contact us for full terms and conditions.)

See below:

Wally’s Widget Company is a widget wholesaler.

They sell widgets in a variety of pack sizes:

  • 250 widgets

  • 500 widgets

  • 1,000 widgets

  • 2,000 widgets

  • 5,000 widgets

Their customers can order any number of widgets, but they will always be given complete packs.

The company wants to be able fulfil all orders by according to the following rules:

  1. Only whole packs can be sent. Packs cannot be broken open.

  2. Within the constraints of Rule 1 above, send out no more widgets than necessary to fulfil the order.

  3. Within the constraints of Rules 1 & 2 above, send out as few packs as possible to fulfil each order.

So, for example;

Number of Widgets ordered

Correct packs to send

Incorrect solution(s)

1

250 x 1

500 x 1 (too many widgets)

250

250 x 1

500 x 1 (too many widgets)

251

500 x 1

250 x 2 (too many packs)

501

500 x 1

250 x 1

1,000 x 1 (too many widgets)

250 x 3 (too many packs)

12,001

5,000 x 2

2,000 x 1

250 x 1

5,000 x 3 (too many widgets)

Write a program that will tell Wally’s Widgets what packs to send out, for any given order size.

Keep your program flexible, so that new packs sizes may be added, or existing pack sizes changed or discarded, at a later date with minimal adjustments to your program.

You can check that your program is giving the right answers on this page.

Use PHP, JavaScript, or an alternative solution of your choice suitable for deployment to an online browser-based tool.

Send your answers to us at stickee in Birmingham. Include your name and a contact email
address.