<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forex Software — New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
	<link rel="self" href="https://forexsb.com/forum/feed/atom/topic/8150/" />
	<updated>2020-01-01T12:46:06Z</updated>
	<generator>PunBB</generator>
	<id>https://forexsb.com/forum/topic/8150/new-year-challenge-win-ea-studio-or-fsb-pro-license/</id>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58602/#p58602" />
			<content type="html"><![CDATA[<p>Hello and happy New Year to all of you!</p><p>I&#039;m very happy to have found a valid solution to the challenge. I was on a trip to Valencia to visit my wife&#039;s friends and when I saw the post about the New Year Challenge I only had my mobile and an online javascript editor (js.do) to test the codes. I learnt online about &quot;currying&quot; (I didn&#039;t know such a thing existed) and tested some solutions with functions defining and calling functions inside. Finally handling the exceptions (the no arguments usage of the function) with &quot;undefined&quot; was the last part of my try. It is great to have found a valid solution!</p><p>Last year I had my first son and I&#039;ve been quite busy since then. For that reason I don&#039;t write too much in the forum, but I visit it nearly everyday, eagerly waiting for news and improvements of such a great software that it is EA Studio. Thanks a lot, Popov, for having created it and my best wishes for you and your team for the new year!</p><p>Best regards!</p>]]></content>
			<author>
				<name><![CDATA[rjectweb]]></name>
				<uri>https://forexsb.com/forum/user/9830/</uri>
			</author>
			<updated>2020-01-01T12:46:06Z</updated>
			<id>https://forexsb.com/forum/post/58602/#p58602</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58601/#p58601" />
			<content type="html"><![CDATA[<p>Of course, this challenge has only an academical purpose.</p><p>If we want to make a function that sums an arbitrary count of numbers, it is much effective to do it like that:</p><div class="codebox"><pre><code>function sumAll() {
    let sum = 0;

    for (let i = 0; i &lt; arguments.length; i++) {
        sum += arguments[i];
    }

    return sum;
}

sumAll(3, 5, 7); // =&gt; 15</code></pre></div><p>But where are the art and fun?</p><p>Happy new year!!!</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2020-01-01T09:54:06Z</updated>
			<id>https://forexsb.com/forum/post/58601/#p58601</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58600/#p58600" />
			<content type="html"><![CDATA[<p>Let&#039;s explain how the `add` function works.</p><p>As I learned from my students years when we have a math problem, we have to search for clues for the solution in the given conditions.</p><p>Let&#039;s start with the first example:</p><p> add() returns 0</p><p>The function add can be called with one numeric argument or without arguments. In JavaScript, we check if an argument is given by comparing it to `undefined`.</p><div class="codebox"><pre><code>function add(n) {
    if (n === undefined) {
        return 0;
    }
}

add(); // =&gt; 0</code></pre></div><p>Ok, it was easy.</p><p>From the second example `add(1)() = 1`, we see that `add` must return a function in order to be able to call it. let&#039;s call the returned function `adder`:</p><br /><div class="codebox"><pre><code>function add(n) {
    if (n === undefined) {
        return 0;
    }

    function adder(m) {

    }

     return adder;
}</code></pre></div><br /><p>The `adder` also takes one or zero arguments. When it is called without an argument, it must return the number given initially to `add`:</p><br /><div class="codebox"><pre><code>function add(n) {
    if (n === undefined) {
        return 0;
    }

    function adder(m) {
        if (m === undefined) {
            return n;
        }
    }

     return adder;
}

add(7)(); // =&gt; 7</code></pre></div><p>Now that example works ` add(7)() =&gt; 7 `. We called that &quot;closure&quot;. It means that when a function ( `add` ) returns another function ( `adder` ), the returned function &quot;remembers&quot; the arguments from the scope of the outer function. We use that to be able to keep the current sum between the calls. So, `adder` remembers `n` and it is able to return it. </p><p>Only one thing remained - to be able to call `add` in a chain like that: `add(n1)(n2)(n3)...(nt)() =&gt; n1+n2+n3+ ... + nt;`</p><p>We use recursion for that. `adder` calls `add` with the sum of `n` and `m`. </p><div class="codebox"><pre><code>function add(n) {
    if (n === undefined) {
        return 0;
    }

    function adder(m) {
        if (m === undefined) {
            return n;
        }

        return add(n + m);
    }

     return adder;
}

add(7)(0)(7)(); // =&gt; 14</code></pre></div><p>It appears that when we call `add` with a number, it returns `adder` as many times as we continue giving a numeric argument. We show the result when calling without an argument and then `adder` returns the current sum equal to `n`.</p><p>So we used &#039;closure&#039; and &#039;recursion&#039; in that challenge to solve a task, which looks unsolvable. It is a usual example of &#039;closure&#039; to use two separate functions like that:</p><div class="codebox"><pre><code>function makeAdder(n) {
   function adder(m) {
       return m + n;
   } 
   return adder;
}

const adder5 = makeAdder(5);

adder5(7); // =&gt; 12</code></pre></div><p>However, this uses two separate functions, it is limited to adding only two numbers, and the second function can only add 5.</p><p>My challenge was to make it with one function, that is able to sum an arbitrary count of numbers and also to be able to be &quot;reset&quot;. It is almost magic! I was not sure if it was possible at all.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2020-01-01T09:34:15Z</updated>
			<id>https://forexsb.com/forum/post/58600/#p58600</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58599/#p58599" />
			<content type="html"><![CDATA[<p>And some GOOD NEWS for EA Studio</p><p>I measured CPU utlization in Win 10 x64. I have 4x2 cores</p><p>Firefox x64&nbsp; is 20%<br />Chrome x64 is 30%<br />The new Chromiun Edge by Microsoft is 40%. The last one is a very good result!<br />You can have two FAST runs at the same time against 5 SLOW runs!</p><p>I think EA studio can be used also to measure the speed of a browser!!!</p><p>HAPPY NEW YEAR</p>]]></content>
			<author>
				<name><![CDATA[GD]]></name>
				<uri>https://forexsb.com/forum/user/8542/</uri>
			</author>
			<updated>2020-01-01T06:56:53Z</updated>
			<id>https://forexsb.com/forum/post/58599/#p58599</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58594/#p58594" />
			<content type="html"><![CDATA[<p>Happy New Year!</p><p>We have only one correct solution to the challenge sent to me buy @rjectweb. Congratulations!</p><br /><p>Here is the answer:</p><div class="codebox"><pre><code>function add(n) {
    function adder(m) {
        return m === undefined
            ? n
            : add(n + m);
    }

    return n === undefined
        ? 0
        : adder;
}

Example:
add(1)(1)(1)(0)(0)(0)(1)(1)(1)() === 6; // SOS :)</code></pre></div><br /><p>It works with any number of calls. </p><p>The problem can be solved also with anonymous functions and a single expression, but it is not as readable as the previous one:</p><div class="codebox"><pre><code>const add = n =&gt; 
    n === undefined
        ? 0
        : m =&gt; m === undefined
                  ? n
                  : add(n + m);</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2020-01-01T00:01:41Z</updated>
			<id>https://forexsb.com/forum/post/58594/#p58594</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58593/#p58593" />
			<content type="html"><![CDATA[<p>It is very simple.</p><p>I will present you the difficult part, the algorithm! </p><p>Xn= SumXk+(n-1)<br />k=1 to n-1<br />X1=0<br />n=1 to inf</p><p>Xn=X(n)</p><p>For the people who have some degree in mathematics, it is a kind of programming language.<br />Can somebody give me a graph? X vs n? Then we have Functional Mathematics...<br />Matlab is fine! Now you can play...</p><p>HAPPY NEW YEAR BOYS AND GIRLS</p>]]></content>
			<author>
				<name><![CDATA[GD]]></name>
				<uri>https://forexsb.com/forum/user/8542/</uri>
			</author>
			<updated>2019-12-31T16:15:15Z</updated>
			<id>https://forexsb.com/forum/post/58593/#p58593</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58580/#p58580" />
			<content type="html"><![CDATA[<p>Hello Gary,</p><p>The code must be entirely in the `add` function.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2019-12-30T13:06:55Z</updated>
			<id>https://forexsb.com/forum/post/58580/#p58580</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58579/#p58579" />
			<content type="html"><![CDATA[<p>How about this? I use python</p><div class="codebox"><pre><code>class CustomInt(int):
    def __call__(self, v=0):
        return CustomInt(self + v)

def add(v = 0):
    return CustomInt(v)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[gary199233]]></name>
				<uri>https://forexsb.com/forum/user/10554/</uri>
			</author>
			<updated>2019-12-30T12:02:53Z</updated>
			<id>https://forexsb.com/forum/post/58579/#p58579</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58561/#p58561" />
			<content type="html"><![CDATA[<p>@gcm it may not work. </p><p>..</p><p>We already have one correct answer sent to PM. I&#039;m very happy from that!!!</p><p>Please keep trying and send your answer to me via PM or via email.</p><p>Please post them in the public topic on January 1st.</p><p>Happy hacking!</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2019-12-30T00:44:25Z</updated>
			<id>https://forexsb.com/forum/post/58561/#p58561</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58560/#p58560" />
			<content type="html"><![CDATA[<p>Miroslav - haw about the following in function in FORTRAN?</p><p>&nbsp; &nbsp; &nbsp; &nbsp;FUNCTION ADD(N)<br />&nbsp; &nbsp; &nbsp; &nbsp;INTEGER ADD<br />&nbsp; &nbsp; &nbsp; &nbsp;ADD = 0<br />&nbsp; &nbsp; &nbsp; &nbsp;DO i = 0,N<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ADD = ADD + i<br />&nbsp; &nbsp; &nbsp; &nbsp;ENDDO<br />&nbsp; &nbsp; &nbsp; &nbsp;END</p>]]></content>
			<author>
				<name><![CDATA[gcm]]></name>
				<uri>https://forexsb.com/forum/user/11104/</uri>
			</author>
			<updated>2019-12-29T21:16:21Z</updated>
			<id>https://forexsb.com/forum/post/58560/#p58560</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[New Year Challenge! Win EA Studio or FSB Pro license!]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/58558/#p58558" />
			<content type="html"><![CDATA[<p>Hello Dear Traders,</p><p>Merry Christmas to all of you and your families! Success and health in your new year 2020!</p><p>I&#039;m glad to present a little challenge for you. It is a short programming task that can be solved in a few lines of code.</p><p>The solution requires out of the box thinking and I&#039;ll be very happy if some of you manage to solve it.</p><p>I always try to support creative and determined people and will be please to me to reward the winners with free EA Studio or FSB Pro lifetime license.</p><p>Here is the challenge.</p><p>Write a single function called <em>add</em>, which takes either a single numeric argument or zero arguments. When it is called in a row as follows, it must return the sum of the arguments:</p><div class="codebox"><pre><code>function add(n) {
   // Write your code here
  ...
}

console.log( add()             ); // =&gt;  0
console.log( add(1)()          ); // =&gt;  1
console.log( add(1)(2)()       ); // =&gt;  3
console.log( add(1)(2)(3)()    ); // =&gt;  6
console.log( add(1)(2)(3)(4)() ); // =&gt; 10</code></pre></div><p>You may use any programming language. You may not write code out of the <strong>add</strong> function or use global variables.</p><p>I expect your answers by the end of 2019.</p><p>Happy hacking!</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2019-12-29T12:55:00Z</updated>
			<id>https://forexsb.com/forum/post/58558/#p58558</id>
		</entry>
</feed>
