Programming Contest: Trade

UPDATE: Announcements for members .
UPDATE 2: Intermediate results and announcements .

Hola Company Announces Programming Contest Again! Winners will receive prizes:

  1. First place: 3000 USD.
  2. Second place: 2000 USD.
  3. Third place: 1000 USD.
  4. The jury may award at its discretion a special prize of 400 USD.
  5. If you send someone a link to this contest, putting our address in CC, and this person will take the prize, you will receive half of the prize amount (of course, not to the detriment of the winner’s reward). For one winner, only one person can receive such an award - the one who sent the link first.

Authors of interesting decisions will be invited for interviews.



rules


Competition terms in English are posted on GitHub . Below is a translation into Russian.

Trade


Suppose we have a book, two hats and three balls. You and another member must decide how to divide this good between the two of you. For you, the book has a value of $ 4, each ball is $ 2, and hats have no value. For a partner, the same objects may have a different value, but you know that all the objects together are as valuable to him as they are to you - in this case it is $ 10.

You and your partner in turn offer options for the section of items. In turn, one of you can either accept the previous offer (unless it is the very first turn), or make a counter offer. Negotiations are limited to 5 rounds, in total, both participants can put forward up to 10 proposals. If an agreement is reached during this time, then each of you will receive the total value of the items going to him (each in accordance with their own coefficients of value). If an agreement is not reached, that is, the last word in the last round - a counter offer, not an agreement - then no one gets anything. The same happens if one of the partners interrupts the negotiations.

Here is an example of how negotiations can take place:

  1. You: I want a book and two balls; you get one ball and both hats.
  2. Partner: I do not agree. I want all the balls and one hat; You will get a book and one hat.
  3. You: I do not agree. I want a book and one ball; you will get two balls and both hats.
  4. Partner: I agree.

You did not know this, but for the partner the value of the items was as follows: $ 2 per ball, $ 2 per hat, the book has no value. The agreement brought you $ 6 to you and $ 8 to your partner.

In general, there are two or more object types and a positive integer number of objects of each type. The value of each type of object for each of the partners is a nonnegative integer. The total value of all objects for both partners is the same, although the values ​​of individual objects differ. The section proposal should distribute all objects without partners to the partners; individual objects are not crushed.

Your task is to write a script seeking to make a deal with the highest possible value (for yourself).

Solutions


The solution is a Node.js module without dependencies. The export module must be a class:

module.exports = class {
    constructor(me, counts, values, max_rounds, log){
        ..
    }
    offer(o){
        ...
    }
}

. :


offer , . o — , counts. , . , , o undefined.

offer undefined, ( , o undefined). , counts, , . , o, offer .

1 . , , , , .

, , .

example.js , . , ; , . log.


haggle.js -, . --help, . ( , npm install src.)

, . , , , , , , . . , «» «», , .

: 3 , 6 , $10, 5 . , , .

c3.large (. ) Amazon AWS Ubuntu 14.04 (amd64). .

, ; (). , , , ( --log).


, . -: «», .

(3 , 6 , $10, 5 ). 1 , . :

wss://hola.org/challenges/haggling/arena/standard

haggle.js, - . --id: , . . . «» , .

— . , . - , .

, , -, , UNIX shell:

while true; do node haggle.js --id me@example.com:1234abcd myscript.js wss://hola.org/challenges/haggling/arena/standard; done



. !

, , . , ; , ; CoffeeScript , , . README (-). tar.gz, tar.bz2 zip. , ( JS-, ).

JS- 64 . , , - «» . 64 , , .

, , , .

!

Source: https://habr.com/ru/post/414723/


All Articles