<![CDATA[Programmer's Town - Etudes for Programmers]]>
http://www.progtown.com/
Fri, 01 Sep 2017 07:10:00 +0000PunBB<![CDATA[Re: Pioneers and vodka]]>
http://www.progtown.com/topic2067504-re-pioneers-and-vodka.html
Hello, Kodt, you wrote: the Question: to what strategy the leader should adhere to maximize the advantage a minus costs? Well and accordingly, what pioneers should undertake? About scorings of pioneers from successful drinking in different places you did not tell. I think that for the leader there will be optimal a casual choice of a place of check. The probability of a choice of each place should be different. It is possible to minimize both average and maximum losses from loss.]]>Fri, 01 Sep 2017 07:10:00 +0000http://www.progtown.com/topic2067504-re-pioneers-and-vodka.html<![CDATA[Swap]]>
http://www.progtown.com/topic2067505-swap.html
The task simple, I write it here, that not in other subject: http://rsdn.org/forum/job/6878320.1 the Author: Titus Date: 19.08 11:40 There I I did not ask to solve this task, and asked absolutely about other, but for some reason there write the candidate solutions of this task, and do not write that is required on a subject. Anybody there while and did not offer the simple correct decision. Its canonical form: two whole variables an and b Are given. To make a program fragment after which execution of value of variables would exchange in places. We enter a variable c. c=a; a=b; b=c; solve the previous task, without using an additional variable.]]>Tue, 29 Aug 2017 14:39:00 +0000http://www.progtown.com/topic2067505-swap.html<![CDATA[To find the plane equation minimum remote from a cloud.]]>
http://www.progtown.com/topic2065657-to-find-the-plane-equation-minimum-remote-from-a-cloud.html
There is a cloud of points in 3D. It is necessary to find the plane equation the total distance from which to all points would be minimum. There is a pair of ideas how to make, but who offers that? Or can eat generally on computing geometry. But it is not interesting, it would be desirable variants of algorithms .]]>Sun, 02 Jul 2017 04:13:00 +0000http://www.progtown.com/topic2065657-to-find-the-plane-equation-minimum-remote-from-a-cloud.html<![CDATA[volatile-only lock]]>
http://www.progtown.com/topic2065658-volatileonly-lock.html
To write synchronization between flows, using only volatile variables (at which only a read and write, but not modification)]]>Fri, 30 Jun 2017 06:36:00 +0000http://www.progtown.com/topic2065658-volatileonly-lock.html<![CDATA[Problem on probability theory]]>
http://www.progtown.com/topic2065659-problem-on-probability-theory.html
All greetings! The problem from last year's entrance examination in interested: are Abreast allocated m subjects. Are casually selected k subjects, k <m. The Random variable X is equal to an amount of such subjects i that i is selected, and all its neighbors are not selected. To find mathematical expectation X. I twist some days, there should be rather simple decision, but I it do not see. Tried to build allocation X explicitly, but for this purpose it is necessary to find number of methods to select k subjects so that exactly X from the selected had no selected neighbors. For this amount of methods the difficult recursion is visible only, with explicit expression there are problems. Counted for different k and m statistically, saw that dependence from k well lays down on a cubic parabola... Found it on several points in a general view. But it did not approach me to the analytical decision. If who has ideas, share!]]>Thu, 29 Jun 2017 08:51:00 +0000http://www.progtown.com/topic2065659-problem-on-probability-theory.html<![CDATA[Re: Correction of brackets]]>
http://www.progtown.com/topic2064534-re-correction-of-brackets.html
Hello, Kodt, you wrote: the Problem with , a head to itself broke, - how to make gracefully. It is given: a line, in which there are brackets (one type - round) and other characters. Brackets, probably, unbalanced. It is necessary: to delete the minimum quantity of brackets so that to recover balance. (Well it is simple). And to deduce all possible decisions. For example, "(a) ()) ())) ((b (b)" - three superfluous ")" and two superfluous "("> (a (())) b (b) (a (())) (bb) (a () ()) b (b) (a () ()) (bb) (a ()) () b (b) (a ()) () (bb) (a) (()) b (b) (a) (()) (bb) (a) () () b (b) (a) () () (bb) Quickly somehow so #include <stdio.h> #include <string.h> #include <set> #include <string> using std:: string; struct Check {const char *text; int len; char* mask; typedef std:: set <string> variants_t; typedef variants_t:: iterator variants_it; variants_t variants; int check () {int level=0, rm_close=0, i, r2=0; char c; for (i=0; c=text [i]; i ++) {if (c == ' (') level ++; if (c == ') ') {if (level> 0) level-; else {rm_close ++; mask [i] =c;}}} for (int l2=0; i> =0; i-) {c=text [i]; if (c == ') ') l2 ++; if (c == ' (') {if (l2> 0) l2-; else {r2 ++; mask [i] =c;}}} if (rm_close || level) printf ("\" %s \"- %d superfluous \") \"and %d superfluous \" (\"\n %s\n\n", text, rm_close, level, mask); return rm_close+level;} void insert () {string s; for (int i=0; i <len; i ++) if (text [i]! =mask [i]) s + = text [i]; variants.insert (s);} void right (int pos) {insert (); while (pos> =0 && mask [pos]! = ' (') pos-; if (pos <0) return; char type=mask [pos]; mask [pos] = ' '; for (int i=pos+1; i <len; i ++) {if (mask [i] == ' ' && text [i] == type) {mask [i] =type; right (i-1); mask [i] = ' ';}} mask [pos] =type;} void left (int pos) {right (len-1); while (pos <len && mask [pos]! = ') ') pos ++; if (pos> =len) return; char type=mask [pos]; mask [pos] = ' '; for (int i=pos-1; i> =0; i-) {if (mask [i] == ' ' && text [i] == type) {mask [i] =type; left (pos+1); mask [i] = ' ';}} mask [pos] =type;} void find () {variants.clear (); left (0);} void show_variants () {int i=0; }}; int main (int argc, char ** argv) {enum {mask_max=64}; char mask [mask_max]; const char* list [] = {"(a) ()) ())) ((b (b)", 0}; for (const char ** s=list; *s; s ++) {Check c; c.text =*s; c.len=strlen (*s); c.mask=mask; memset (mask, ' ', c.len); mask [c.len] =0; if (c.check ()) c.show_variants ();} return 0;} "(a) ()) ())) ((b (b)" - 3 superfluous ")" and 2 superfluous "("))) ((1 (a (())) (bb) 2 (a (())) b (b) 3 (a () ()) (bb) 4 (a () ()) b (b) 5 (a ()) () (bb) 6 (a ()) () b (b) 7 (a) (()) (bb) 8 (a) (()) b (b) 9 (a) () () (bb) 10 (a) () () b (b)]]>Mon, 12 Jun 2017 22:50:00 +0000http://www.progtown.com/topic2064534-re-correction-of-brackets.html<![CDATA[How to add in the white list :)]]>
http://www.progtown.com/topic2064535-how-to-add-in-the-white-list.html
Wed, 07 Jun 2017 13:43:00 +0000http://www.progtown.com/topic2064535-how-to-add-in-the-white-list.html<![CDATA[The job from Unified State Examination on computer science]]>
http://www.progtown.com/topic2060427-the-job-from-unified-state-examination-on-computer-science.html
Tue, 30 May 2017 07:45:00 +0000http://www.progtown.com/topic2060427-the-job-from-unified-state-examination-on-computer-science.html<![CDATA[To find all remaining three-digit numbers]]>
http://www.progtown.com/topic2060428-to-find-all-remaining-threedigit-numbers.html
Example. We take, for example, 250 and it is attributed to it 2. We receive 2250. 2250 in 9 times more 250. It is necessary to find all remaining three-digit numbers, at attributing to which in the beginning any digit, the received result would be in 9 times more initial number. Direct search and generally programming do not roll. The common decision is necessary.]]>Thu, 27 Apr 2017 09:29:00 +0000http://www.progtown.com/topic2060428-to-find-all-remaining-threedigit-numbers.html<![CDATA[Output path]]>
http://www.progtown.com/topic2056974-output-path.html
Greetings to all! Once for a long time heard such task: someone appeared in wood without any navigation instruments and he needs to come out of the wood. On what path it needs to move, that is guaranteed to come out of the wood and also that it was an optimal path. Something such seems... Precisely I do not remember. Who knows this task prompt as it what its strict mathematical decision, is precisely formulated also!]]>Sat, 08 Apr 2017 15:28:00 +0000http://www.progtown.com/topic2056974-output-path.html<![CDATA[Rational numbers]]>
http://www.progtown.com/topic2056975-rational-numbers.html
Let S is the least set of rational numbers containing number 0 and satisfying condition: * If numbers p and q belong S, and |p-q | <1 the number (p+q+1)/2 also belongs S. To write the program which accepts a rational number and defines, whether it belongs to set S.]]>Fri, 07 Apr 2017 06:24:00 +0000http://www.progtown.com/topic2056975-rational-numbers.html<![CDATA[Superfluous equalities]]>
http://www.progtown.com/topic2056976-superfluous-equalities.html
The task of the second class, seemed interesting, to us such for some reason did not set (and it is a pity). Underline "superfluous" equality: 7*7 - 22 = 27 4*4 - 11 = 5 8*8 - 44 = 20 29 - 2*2 = 25 6*6 - 21 = 15 8*5 - 23 = 17 Actually, it was necessary to find at first values of expressions, and then already to search for "superfluous". It is required to find one superfluous, but the teacher allows to find some "superfluous". All variants of "superfluous" equalities now are just interesting to us. Variants "in studio". P.S. I think, it is clear that such equality which possesses some property is superfluous, thus others do not possess it.]]>Thu, 06 Apr 2017 03:19:00 +0000http://www.progtown.com/topic2056976-superfluous-equalities.html<![CDATA[To relieve the person from BigData by means of 5 lines of the code]]>
http://www.progtown.com/topic2056977-to-relieve-the-person-from-bigdata-by-means-of-5-lines-of-the-code.html
Subject a bit cheerful, on it not in algorithms. Particulars: https://habrahabr.ru/post/324772/it is short. It is necessary for the person ID-shki in format XX000000, where XX - two letters of the Latin alphabet, 0 - number from 0 to 9. A principal condition - that damned competitors could not ID calculate under number how many all clients in basis. Competitors can do records on purpose to receive n ID, going successively. For the person the task seemed mega-difficult, what even it was necessary to attract this terrible BigData which neither the friend nor the enemy in the person does not know. I.e. sorted out all possible variants, mixed, saved in one big = on 20 and then long optimized basis quickly to select these ID. How by means of the genius of engineering thought and 5-10 lines on the pseudocode to relieve the person from big and BigData?]]>Tue, 04 Apr 2017 22:53:00 +0000http://www.progtown.com/topic2056977-to-relieve-the-person-from-bigdata-by-means-of-5-lines-of-the-code.html<![CDATA[Optimization of search of anagrams]]>
http://www.progtown.com/topic2056978-optimization-of-search-of-anagrams.html
Received recently curious job for interview. Here the job text: Anagrams are defined as words with the same length and same number of characters in any order. Eg: bat/tab/abt are anagrams aabb/baba/bbaa/abab - anagrams abcd/abce - are not anagrams (different characters) aaab, aabb - are not anagrams (different character count) Given a list of words - {abcd, bbb, abc, bat, cat, yyyyxxxx, tab, atb, rat, cab, xxyyxxyyxx, atb} Print out the anagram pairs - {{abc, cab}, {bat, tab, atb, atb}} Assuming that the input is of type [a-z], can you optimize the solution. With anagrams all is simple - they easily are if to compare the sorted copies of lines. And here with optimization I and did not understand. I so understand, sense there in generation unique for every line but how to make identical to the different lines containing the same dial-up of letters, I yet did not understand. The colleague looked and told supposedly "about, here all is simple - it is necessary to use prime numbers". If I correctly understand, it is necessary to select prime numbers from this variant from 2 and more (and can and from 3, it is not assured) and to take result of multiplication. But 26 prime number in this variant will be 101, i.e. for everyone ' z ' we need to multiply on 101. Then 6. 7 letters ' z ' give which gets out for limits 64 bit. Prompt, what here would be the correct algorithm? And, what is more interesting - prompt, it is necessary to look at what else useful methods of hash coding better to understand this subject?]]>Tue, 04 Apr 2017 08:48:00 +0000http://www.progtown.com/topic2056978-optimization-of-search-of-anagrams.html<![CDATA[Coloring of a surface of a cube]]>
http://www.progtown.com/topic2056979-coloring-of-a-surface-of-a-cube.html
The daughter from the Olympic Games brought: There is a white cube with the side of 3 cells. Surface cells (54 pieces) can be painted over in black color but so that no two painted over cells adjoined on the side (including lying on different edges). What maximum number of cells can be painted over? The answer is quickly, and here to prove why it maximum - was necessary to break a head. Probably, someone from you finds more simple proof.]]>Fri, 31 Mar 2017 13:32:00 +0000http://www.progtown.com/topic2056979-coloring-of-a-surface-of-a-cube.html