Sum square difference

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












The sum of the squares of the first ten natural numbers is,
$1^2 + 2^2 + dots + 10^2 = 385$



The square of the sum of the first ten natural numbers is,



$(1 + 2 + ... + 10)^2 = 55^2 = 3025$



Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is



$3025 − 385 = 2640$



For a given input n, find the difference between the sum of the squares of the first n natural numbers and the square of the sum.



Test cases



1 => 0
2 => 4
3 => 22
10 => 2640
24 => 85100
100 => 25164150


This challenge was first announced at Project Euler #6.



Winning Criteria



  • There are no rules about what should be the behavior with negative or zero input.


  • The shortest answer wins.










share|improve this question























  • A052149
    – Shaggy
    2 hours ago






  • 4




    This challenge needs a winning criterion (e.g. code golf)
    – dylnan
    2 hours ago










  • This is a subset of this question
    – caird coinheringaahing
    1 hour ago














up vote
1
down vote

favorite












The sum of the squares of the first ten natural numbers is,
$1^2 + 2^2 + dots + 10^2 = 385$



The square of the sum of the first ten natural numbers is,



$(1 + 2 + ... + 10)^2 = 55^2 = 3025$



Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is



$3025 − 385 = 2640$



For a given input n, find the difference between the sum of the squares of the first n natural numbers and the square of the sum.



Test cases



1 => 0
2 => 4
3 => 22
10 => 2640
24 => 85100
100 => 25164150


This challenge was first announced at Project Euler #6.



Winning Criteria



  • There are no rules about what should be the behavior with negative or zero input.


  • The shortest answer wins.










share|improve this question























  • A052149
    – Shaggy
    2 hours ago






  • 4




    This challenge needs a winning criterion (e.g. code golf)
    – dylnan
    2 hours ago










  • This is a subset of this question
    – caird coinheringaahing
    1 hour ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











The sum of the squares of the first ten natural numbers is,
$1^2 + 2^2 + dots + 10^2 = 385$



The square of the sum of the first ten natural numbers is,



$(1 + 2 + ... + 10)^2 = 55^2 = 3025$



Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is



$3025 − 385 = 2640$



For a given input n, find the difference between the sum of the squares of the first n natural numbers and the square of the sum.



Test cases



1 => 0
2 => 4
3 => 22
10 => 2640
24 => 85100
100 => 25164150


This challenge was first announced at Project Euler #6.



Winning Criteria



  • There are no rules about what should be the behavior with negative or zero input.


  • The shortest answer wins.










share|improve this question















The sum of the squares of the first ten natural numbers is,
$1^2 + 2^2 + dots + 10^2 = 385$



The square of the sum of the first ten natural numbers is,



$(1 + 2 + ... + 10)^2 = 55^2 = 3025$



Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is



$3025 − 385 = 2640$



For a given input n, find the difference between the sum of the squares of the first n natural numbers and the square of the sum.



Test cases



1 => 0
2 => 4
3 => 22
10 => 2640
24 => 85100
100 => 25164150


This challenge was first announced at Project Euler #6.



Winning Criteria



  • There are no rules about what should be the behavior with negative or zero input.


  • The shortest answer wins.







code-golf math






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









caird coinheringaahing

7,38032985




7,38032985










asked 2 hours ago









Eduardo Hoefel

315




315











  • A052149
    – Shaggy
    2 hours ago






  • 4




    This challenge needs a winning criterion (e.g. code golf)
    – dylnan
    2 hours ago










  • This is a subset of this question
    – caird coinheringaahing
    1 hour ago
















  • A052149
    – Shaggy
    2 hours ago






  • 4




    This challenge needs a winning criterion (e.g. code golf)
    – dylnan
    2 hours ago










  • This is a subset of this question
    – caird coinheringaahing
    1 hour ago















A052149
– Shaggy
2 hours ago




A052149
– Shaggy
2 hours ago




4




4




This challenge needs a winning criterion (e.g. code golf)
– dylnan
2 hours ago




This challenge needs a winning criterion (e.g. code golf)
– dylnan
2 hours ago












This is a subset of this question
– caird coinheringaahing
1 hour ago




This is a subset of this question
– caird coinheringaahing
1 hour ago










9 Answers
9






active

oldest

votes

















up vote
1
down vote














Jelly,  5  4 bytes



Ḋ²ḋṖ


Try it online!



How?



Implements $sum_i=2^n(i^2(i-1))$...



Ḋ²ḋṖ - Link: non-negative integer, n
Ḋ - dequeue (implicit range) [2,3,4,5,...,n]
² - square (vectorises) [4,9,16,25,...,n*n]
Ṗ - pop (implicit range) [1,2,3,4,...,n-1]
ḋ - dot product 4*1+9*2+16*3+25*4+...+n*n*(n-1)





share|improve this answer





























    up vote
    1
    down vote














    Python 3, 28 bytes





    lambda n:n*~-n*-~n*(n/4+1/6)


    Try it online!



    Implements $n(n-1)(n+1)(3n+2)/12$




    Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12






    share|improve this answer





























      up vote
      0
      down vote














      cQuents, 17 bytes



      1$)^2-2$
      ;$
      ;$$


      Try it online!



      Explanation



       1$)^2-2$ First line
      : Implicit (output nth term in sequence)
      1$) Each term in the sequence equals the second line at the current index
      ^2 squared
      -2$ minus the third line at the current index

      ;$ Second line - sum of integers up to n
      ;$$ Third line - sum of squares up to n





      share|improve this answer



























        up vote
        0
        down vote













        JavaScript (ES6), 22 bytes





        n=>n*~-n*-~n*(n/4+1/6)


        Try it online!






        share|improve this answer



























          up vote
          0
          down vote














          SNOBOL4 (CSNOBOL4), 70 bytes



           N =INPUT
          X =(N * N + N) / 2
          OUTPUT =X ^ 2 - X * (2 * N + 1) / 3
          END


          Try it online!






          share|improve this answer



























            up vote
            0
            down vote














            JAEL, 7 chars, 13 bytes



            nàṕĝ¯ĝE


            Try it online!



            Explanation (generated automatically):



            ./jael -u explain 'nàṕĝ¯ĝE'
            ORIGINAL CODE:
            nàṕĝ¯ĝE

            EXPANDING EXPLANATION:
            à => `a
            ṕ => ´p
            ĝ => ^g
            ĝ => ^g
            E => e!

            EXPANDED CODE:
            n`a´p^g¯^ge!

            COMPLETED CODE:
            n`a´p^g¯^ge!

            n push [0...p1]
            ` push 1
            a push p1 + p2
            ´ duplicate p1
            p push the sum of all values of set(p1)
            ^ push 2
            g push p2 ^ p1
            ¯ invert p1 and p2 on the stack
            ^ push 2
            g push p2 ^ p1
            e push p2 - p1
            ! write p1 to the tapehead
            ␄ print machine state





            share|improve this answer



























              up vote
              0
              down vote














              Brain-Flak, 74 72 68 bytes



              ([((([]))(()))(())()]()((()))()(()))


              Try it online!



              Pretty simple way of doing it with a couple of tricky shifts. Hopefully someone will find some more tricks to make this even shorter.






              share|improve this answer





























                up vote
                0
                down vote













                I Could not enjoy this app.
                Is there anyone here to help me?





                share








                New contributor




                user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.
























                  up vote
                  0
                  down vote













                  Japt -x, 9 8 5 4 bytes



                  õ²í*


                  Try it




                  Explanation



                  õ :Range [1,input]
                  ² :Square each
                  í :Interleave with 0-based indices
                  * :Reduce each pair by multiplication
                  :Implicit output of the sum of the resulting array





                  share|improve this answer






















                  • You shouldn't use anything but the value as input. What is that '-x' doing? It should be considered to measure the score.
                    – Eduardo Hoefel
                    1 hour ago










                  • It's a flag, we don't count them.
                    – Shaggy
                    1 hour ago






                  • 3




                    @EduardoHoefel It's a slightly strange quirk of the site that a language + flags is a language in it's own right by meta consensus (hence the title "Japt -x")
                    – Jonathan Allan
                    1 hour ago










                  • How about this ?
                    – Eduardo Hoefel
                    1 hour ago






                  • 1




                    @EduardoHoefel That information is outdated. We don't count flags anymore.
                    – Dennis♦
                    27 mins ago










                  Your Answer





                  StackExchange.ifUsing("editor", function ()
                  return StackExchange.using("mathjaxEditing", function ()
                  StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
                  StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                  );
                  );
                  , "mathjax-editing");

                  StackExchange.ifUsing("editor", function ()
                  StackExchange.using("externalEditor", function ()
                  StackExchange.using("snippets", function ()
                  StackExchange.snippets.init();
                  );
                  );
                  , "code-snippets");

                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "200"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader:
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  ,
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                   

                  draft saved


                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175236%2fsum-square-difference%23new-answer', 'question_page');

                  );

                  Post as a guest






























                  9 Answers
                  9






                  active

                  oldest

                  votes








                  9 Answers
                  9






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  1
                  down vote














                  Jelly,  5  4 bytes



                  Ḋ²ḋṖ


                  Try it online!



                  How?



                  Implements $sum_i=2^n(i^2(i-1))$...



                  Ḋ²ḋṖ - Link: non-negative integer, n
                  Ḋ - dequeue (implicit range) [2,3,4,5,...,n]
                  ² - square (vectorises) [4,9,16,25,...,n*n]
                  Ṗ - pop (implicit range) [1,2,3,4,...,n-1]
                  ḋ - dot product 4*1+9*2+16*3+25*4+...+n*n*(n-1)





                  share|improve this answer


























                    up vote
                    1
                    down vote














                    Jelly,  5  4 bytes



                    Ḋ²ḋṖ


                    Try it online!



                    How?



                    Implements $sum_i=2^n(i^2(i-1))$...



                    Ḋ²ḋṖ - Link: non-negative integer, n
                    Ḋ - dequeue (implicit range) [2,3,4,5,...,n]
                    ² - square (vectorises) [4,9,16,25,...,n*n]
                    Ṗ - pop (implicit range) [1,2,3,4,...,n-1]
                    ḋ - dot product 4*1+9*2+16*3+25*4+...+n*n*(n-1)





                    share|improve this answer
























                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote










                      Jelly,  5  4 bytes



                      Ḋ²ḋṖ


                      Try it online!



                      How?



                      Implements $sum_i=2^n(i^2(i-1))$...



                      Ḋ²ḋṖ - Link: non-negative integer, n
                      Ḋ - dequeue (implicit range) [2,3,4,5,...,n]
                      ² - square (vectorises) [4,9,16,25,...,n*n]
                      Ṗ - pop (implicit range) [1,2,3,4,...,n-1]
                      ḋ - dot product 4*1+9*2+16*3+25*4+...+n*n*(n-1)





                      share|improve this answer















                      Jelly,  5  4 bytes



                      Ḋ²ḋṖ


                      Try it online!



                      How?



                      Implements $sum_i=2^n(i^2(i-1))$...



                      Ḋ²ḋṖ - Link: non-negative integer, n
                      Ḋ - dequeue (implicit range) [2,3,4,5,...,n]
                      ² - square (vectorises) [4,9,16,25,...,n*n]
                      Ṗ - pop (implicit range) [1,2,3,4,...,n-1]
                      ḋ - dot product 4*1+9*2+16*3+25*4+...+n*n*(n-1)






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 32 mins ago

























                      answered 1 hour ago









                      Jonathan Allan

                      49.6k534163




                      49.6k534163




















                          up vote
                          1
                          down vote














                          Python 3, 28 bytes





                          lambda n:n*~-n*-~n*(n/4+1/6)


                          Try it online!



                          Implements $n(n-1)(n+1)(3n+2)/12$




                          Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12






                          share|improve this answer


























                            up vote
                            1
                            down vote














                            Python 3, 28 bytes





                            lambda n:n*~-n*-~n*(n/4+1/6)


                            Try it online!



                            Implements $n(n-1)(n+1)(3n+2)/12$




                            Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12






                            share|improve this answer
























                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote










                              Python 3, 28 bytes





                              lambda n:n*~-n*-~n*(n/4+1/6)


                              Try it online!



                              Implements $n(n-1)(n+1)(3n+2)/12$




                              Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12






                              share|improve this answer















                              Python 3, 28 bytes





                              lambda n:n*~-n*-~n*(n/4+1/6)


                              Try it online!



                              Implements $n(n-1)(n+1)(3n+2)/12$




                              Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 27 mins ago

























                              answered 1 hour ago









                              Jonathan Allan

                              49.6k534163




                              49.6k534163




















                                  up vote
                                  0
                                  down vote














                                  cQuents, 17 bytes



                                  1$)^2-2$
                                  ;$
                                  ;$$


                                  Try it online!



                                  Explanation



                                   1$)^2-2$ First line
                                  : Implicit (output nth term in sequence)
                                  1$) Each term in the sequence equals the second line at the current index
                                  ^2 squared
                                  -2$ minus the third line at the current index

                                  ;$ Second line - sum of integers up to n
                                  ;$$ Third line - sum of squares up to n





                                  share|improve this answer
























                                    up vote
                                    0
                                    down vote














                                    cQuents, 17 bytes



                                    1$)^2-2$
                                    ;$
                                    ;$$


                                    Try it online!



                                    Explanation



                                     1$)^2-2$ First line
                                    : Implicit (output nth term in sequence)
                                    1$) Each term in the sequence equals the second line at the current index
                                    ^2 squared
                                    -2$ minus the third line at the current index

                                    ;$ Second line - sum of integers up to n
                                    ;$$ Third line - sum of squares up to n





                                    share|improve this answer






















                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote










                                      cQuents, 17 bytes



                                      1$)^2-2$
                                      ;$
                                      ;$$


                                      Try it online!



                                      Explanation



                                       1$)^2-2$ First line
                                      : Implicit (output nth term in sequence)
                                      1$) Each term in the sequence equals the second line at the current index
                                      ^2 squared
                                      -2$ minus the third line at the current index

                                      ;$ Second line - sum of integers up to n
                                      ;$$ Third line - sum of squares up to n





                                      share|improve this answer













                                      cQuents, 17 bytes



                                      1$)^2-2$
                                      ;$
                                      ;$$


                                      Try it online!



                                      Explanation



                                       1$)^2-2$ First line
                                      : Implicit (output nth term in sequence)
                                      1$) Each term in the sequence equals the second line at the current index
                                      ^2 squared
                                      -2$ minus the third line at the current index

                                      ;$ Second line - sum of integers up to n
                                      ;$$ Third line - sum of squares up to n






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 2 hours ago









                                      Stephen

                                      7,10822993




                                      7,10822993




















                                          up vote
                                          0
                                          down vote













                                          JavaScript (ES6), 22 bytes





                                          n=>n*~-n*-~n*(n/4+1/6)


                                          Try it online!






                                          share|improve this answer
























                                            up vote
                                            0
                                            down vote













                                            JavaScript (ES6), 22 bytes





                                            n=>n*~-n*-~n*(n/4+1/6)


                                            Try it online!






                                            share|improve this answer






















                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              JavaScript (ES6), 22 bytes





                                              n=>n*~-n*-~n*(n/4+1/6)


                                              Try it online!






                                              share|improve this answer












                                              JavaScript (ES6), 22 bytes





                                              n=>n*~-n*-~n*(n/4+1/6)


                                              Try it online!







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 1 hour ago









                                              Arnauld

                                              67.2k584283




                                              67.2k584283




















                                                  up vote
                                                  0
                                                  down vote














                                                  SNOBOL4 (CSNOBOL4), 70 bytes



                                                   N =INPUT
                                                  X =(N * N + N) / 2
                                                  OUTPUT =X ^ 2 - X * (2 * N + 1) / 3
                                                  END


                                                  Try it online!






                                                  share|improve this answer
























                                                    up vote
                                                    0
                                                    down vote














                                                    SNOBOL4 (CSNOBOL4), 70 bytes



                                                     N =INPUT
                                                    X =(N * N + N) / 2
                                                    OUTPUT =X ^ 2 - X * (2 * N + 1) / 3
                                                    END


                                                    Try it online!






                                                    share|improve this answer






















                                                      up vote
                                                      0
                                                      down vote










                                                      up vote
                                                      0
                                                      down vote










                                                      SNOBOL4 (CSNOBOL4), 70 bytes



                                                       N =INPUT
                                                      X =(N * N + N) / 2
                                                      OUTPUT =X ^ 2 - X * (2 * N + 1) / 3
                                                      END


                                                      Try it online!






                                                      share|improve this answer













                                                      SNOBOL4 (CSNOBOL4), 70 bytes



                                                       N =INPUT
                                                      X =(N * N + N) / 2
                                                      OUTPUT =X ^ 2 - X * (2 * N + 1) / 3
                                                      END


                                                      Try it online!







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered 1 hour ago









                                                      Giuseppe

                                                      15.7k31051




                                                      15.7k31051




















                                                          up vote
                                                          0
                                                          down vote














                                                          JAEL, 7 chars, 13 bytes



                                                          nàṕĝ¯ĝE


                                                          Try it online!



                                                          Explanation (generated automatically):



                                                          ./jael -u explain 'nàṕĝ¯ĝE'
                                                          ORIGINAL CODE:
                                                          nàṕĝ¯ĝE

                                                          EXPANDING EXPLANATION:
                                                          à => `a
                                                          ṕ => ´p
                                                          ĝ => ^g
                                                          ĝ => ^g
                                                          E => e!

                                                          EXPANDED CODE:
                                                          n`a´p^g¯^ge!

                                                          COMPLETED CODE:
                                                          n`a´p^g¯^ge!

                                                          n push [0...p1]
                                                          ` push 1
                                                          a push p1 + p2
                                                          ´ duplicate p1
                                                          p push the sum of all values of set(p1)
                                                          ^ push 2
                                                          g push p2 ^ p1
                                                          ¯ invert p1 and p2 on the stack
                                                          ^ push 2
                                                          g push p2 ^ p1
                                                          e push p2 - p1
                                                          ! write p1 to the tapehead
                                                          ␄ print machine state





                                                          share|improve this answer
























                                                            up vote
                                                            0
                                                            down vote














                                                            JAEL, 7 chars, 13 bytes



                                                            nàṕĝ¯ĝE


                                                            Try it online!



                                                            Explanation (generated automatically):



                                                            ./jael -u explain 'nàṕĝ¯ĝE'
                                                            ORIGINAL CODE:
                                                            nàṕĝ¯ĝE

                                                            EXPANDING EXPLANATION:
                                                            à => `a
                                                            ṕ => ´p
                                                            ĝ => ^g
                                                            ĝ => ^g
                                                            E => e!

                                                            EXPANDED CODE:
                                                            n`a´p^g¯^ge!

                                                            COMPLETED CODE:
                                                            n`a´p^g¯^ge!

                                                            n push [0...p1]
                                                            ` push 1
                                                            a push p1 + p2
                                                            ´ duplicate p1
                                                            p push the sum of all values of set(p1)
                                                            ^ push 2
                                                            g push p2 ^ p1
                                                            ¯ invert p1 and p2 on the stack
                                                            ^ push 2
                                                            g push p2 ^ p1
                                                            e push p2 - p1
                                                            ! write p1 to the tapehead
                                                            ␄ print machine state





                                                            share|improve this answer






















                                                              up vote
                                                              0
                                                              down vote










                                                              up vote
                                                              0
                                                              down vote










                                                              JAEL, 7 chars, 13 bytes



                                                              nàṕĝ¯ĝE


                                                              Try it online!



                                                              Explanation (generated automatically):



                                                              ./jael -u explain 'nàṕĝ¯ĝE'
                                                              ORIGINAL CODE:
                                                              nàṕĝ¯ĝE

                                                              EXPANDING EXPLANATION:
                                                              à => `a
                                                              ṕ => ´p
                                                              ĝ => ^g
                                                              ĝ => ^g
                                                              E => e!

                                                              EXPANDED CODE:
                                                              n`a´p^g¯^ge!

                                                              COMPLETED CODE:
                                                              n`a´p^g¯^ge!

                                                              n push [0...p1]
                                                              ` push 1
                                                              a push p1 + p2
                                                              ´ duplicate p1
                                                              p push the sum of all values of set(p1)
                                                              ^ push 2
                                                              g push p2 ^ p1
                                                              ¯ invert p1 and p2 on the stack
                                                              ^ push 2
                                                              g push p2 ^ p1
                                                              e push p2 - p1
                                                              ! write p1 to the tapehead
                                                              ␄ print machine state





                                                              share|improve this answer













                                                              JAEL, 7 chars, 13 bytes



                                                              nàṕĝ¯ĝE


                                                              Try it online!



                                                              Explanation (generated automatically):



                                                              ./jael -u explain 'nàṕĝ¯ĝE'
                                                              ORIGINAL CODE:
                                                              nàṕĝ¯ĝE

                                                              EXPANDING EXPLANATION:
                                                              à => `a
                                                              ṕ => ´p
                                                              ĝ => ^g
                                                              ĝ => ^g
                                                              E => e!

                                                              EXPANDED CODE:
                                                              n`a´p^g¯^ge!

                                                              COMPLETED CODE:
                                                              n`a´p^g¯^ge!

                                                              n push [0...p1]
                                                              ` push 1
                                                              a push p1 + p2
                                                              ´ duplicate p1
                                                              p push the sum of all values of set(p1)
                                                              ^ push 2
                                                              g push p2 ^ p1
                                                              ¯ invert p1 and p2 on the stack
                                                              ^ push 2
                                                              g push p2 ^ p1
                                                              e push p2 - p1
                                                              ! write p1 to the tapehead
                                                              ␄ print machine state






                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered 1 hour ago









                                                              Eduardo Hoefel

                                                              315




                                                              315




















                                                                  up vote
                                                                  0
                                                                  down vote














                                                                  Brain-Flak, 74 72 68 bytes



                                                                  ([((([]))(()))(())()]()((()))()(()))


                                                                  Try it online!



                                                                  Pretty simple way of doing it with a couple of tricky shifts. Hopefully someone will find some more tricks to make this even shorter.






                                                                  share|improve this answer


























                                                                    up vote
                                                                    0
                                                                    down vote














                                                                    Brain-Flak, 74 72 68 bytes



                                                                    ([((([]))(()))(())()]()((()))()(()))


                                                                    Try it online!



                                                                    Pretty simple way of doing it with a couple of tricky shifts. Hopefully someone will find some more tricks to make this even shorter.






                                                                    share|improve this answer
























                                                                      up vote
                                                                      0
                                                                      down vote










                                                                      up vote
                                                                      0
                                                                      down vote










                                                                      Brain-Flak, 74 72 68 bytes



                                                                      ([((([]))(()))(())()]()((()))()(()))


                                                                      Try it online!



                                                                      Pretty simple way of doing it with a couple of tricky shifts. Hopefully someone will find some more tricks to make this even shorter.






                                                                      share|improve this answer















                                                                      Brain-Flak, 74 72 68 bytes



                                                                      ([((([]))(()))(())()]()((()))()(()))


                                                                      Try it online!



                                                                      Pretty simple way of doing it with a couple of tricky shifts. Hopefully someone will find some more tricks to make this even shorter.







                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited 1 hour ago

























                                                                      answered 2 hours ago









                                                                      Post Left Ghost Hunter

                                                                      34.4k10152361




                                                                      34.4k10152361




















                                                                          up vote
                                                                          0
                                                                          down vote













                                                                          I Could not enjoy this app.
                                                                          Is there anyone here to help me?





                                                                          share








                                                                          New contributor




                                                                          user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                          Check out our Code of Conduct.





















                                                                            up vote
                                                                            0
                                                                            down vote













                                                                            I Could not enjoy this app.
                                                                            Is there anyone here to help me?





                                                                            share








                                                                            New contributor




                                                                            user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                            Check out our Code of Conduct.



















                                                                              up vote
                                                                              0
                                                                              down vote










                                                                              up vote
                                                                              0
                                                                              down vote









                                                                              I Could not enjoy this app.
                                                                              Is there anyone here to help me?





                                                                              share








                                                                              New contributor




                                                                              user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.









                                                                              I Could not enjoy this app.
                                                                              Is there anyone here to help me?






                                                                              share








                                                                              New contributor




                                                                              user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.








                                                                              share


                                                                              share






                                                                              New contributor




                                                                              user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.









                                                                              answered 3 mins ago









                                                                              user322955

                                                                              1




                                                                              1




                                                                              New contributor




                                                                              user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.





                                                                              New contributor





                                                                              user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.






                                                                              user322955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.




















                                                                                  up vote
                                                                                  0
                                                                                  down vote













                                                                                  Japt -x, 9 8 5 4 bytes



                                                                                  õ²í*


                                                                                  Try it




                                                                                  Explanation



                                                                                  õ :Range [1,input]
                                                                                  ² :Square each
                                                                                  í :Interleave with 0-based indices
                                                                                  * :Reduce each pair by multiplication
                                                                                  :Implicit output of the sum of the resulting array





                                                                                  share|improve this answer






















                                                                                  • You shouldn't use anything but the value as input. What is that '-x' doing? It should be considered to measure the score.
                                                                                    – Eduardo Hoefel
                                                                                    1 hour ago










                                                                                  • It's a flag, we don't count them.
                                                                                    – Shaggy
                                                                                    1 hour ago






                                                                                  • 3




                                                                                    @EduardoHoefel It's a slightly strange quirk of the site that a language + flags is a language in it's own right by meta consensus (hence the title "Japt -x")
                                                                                    – Jonathan Allan
                                                                                    1 hour ago










                                                                                  • How about this ?
                                                                                    – Eduardo Hoefel
                                                                                    1 hour ago






                                                                                  • 1




                                                                                    @EduardoHoefel That information is outdated. We don't count flags anymore.
                                                                                    – Dennis♦
                                                                                    27 mins ago














                                                                                  up vote
                                                                                  0
                                                                                  down vote













                                                                                  Japt -x, 9 8 5 4 bytes



                                                                                  õ²í*


                                                                                  Try it




                                                                                  Explanation



                                                                                  õ :Range [1,input]
                                                                                  ² :Square each
                                                                                  í :Interleave with 0-based indices
                                                                                  * :Reduce each pair by multiplication
                                                                                  :Implicit output of the sum of the resulting array





                                                                                  share|improve this answer






















                                                                                  • You shouldn't use anything but the value as input. What is that '-x' doing? It should be considered to measure the score.
                                                                                    – Eduardo Hoefel
                                                                                    1 hour ago










                                                                                  • It's a flag, we don't count them.
                                                                                    – Shaggy
                                                                                    1 hour ago






                                                                                  • 3




                                                                                    @EduardoHoefel It's a slightly strange quirk of the site that a language + flags is a language in it's own right by meta consensus (hence the title "Japt -x")
                                                                                    – Jonathan Allan
                                                                                    1 hour ago










                                                                                  • How about this ?
                                                                                    – Eduardo Hoefel
                                                                                    1 hour ago






                                                                                  • 1




                                                                                    @EduardoHoefel That information is outdated. We don't count flags anymore.
                                                                                    – Dennis♦
                                                                                    27 mins ago












                                                                                  up vote
                                                                                  0
                                                                                  down vote










                                                                                  up vote
                                                                                  0
                                                                                  down vote









                                                                                  Japt -x, 9 8 5 4 bytes



                                                                                  õ²í*


                                                                                  Try it




                                                                                  Explanation



                                                                                  õ :Range [1,input]
                                                                                  ² :Square each
                                                                                  í :Interleave with 0-based indices
                                                                                  * :Reduce each pair by multiplication
                                                                                  :Implicit output of the sum of the resulting array





                                                                                  share|improve this answer














                                                                                  Japt -x, 9 8 5 4 bytes



                                                                                  õ²í*


                                                                                  Try it




                                                                                  Explanation



                                                                                  õ :Range [1,input]
                                                                                  ² :Square each
                                                                                  í :Interleave with 0-based indices
                                                                                  * :Reduce each pair by multiplication
                                                                                  :Implicit output of the sum of the resulting array






                                                                                  share|improve this answer














                                                                                  share|improve this answer



                                                                                  share|improve this answer








                                                                                  edited 1 min ago

























                                                                                  answered 2 hours ago









                                                                                  Shaggy

                                                                                  17.6k21663




                                                                                  17.6k21663











                                                                                  • You shouldn't use anything but the value as input. What is that '-x' doing? It should be considered to measure the score.
                                                                                    – Eduardo Hoefel
                                                                                    1 hour ago










                                                                                  • It's a flag, we don't count them.
                                                                                    – Shaggy
                                                                                    1 hour ago






                                                                                  • 3




                                                                                    @EduardoHoefel It's a slightly strange quirk of the site that a language + flags is a language in it's own right by meta consensus (hence the title "Japt -x")
                                                                                    – Jonathan Allan
                                                                                    1 hour ago










                                                                                  • How about this ?
                                                                                    – Eduardo Hoefel
                                                                                    1 hour ago






                                                                                  • 1




                                                                                    @EduardoHoefel That information is outdated. We don't count flags anymore.
                                                                                    – Dennis♦
                                                                                    27 mins ago
















                                                                                  • You shouldn't use anything but the value as input. What is that '-x' doing? It should be considered to measure the score.
                                                                                    – Eduardo Hoefel
                                                                                    1 hour ago










                                                                                  • It's a flag, we don't count them.
                                                                                    – Shaggy
                                                                                    1 hour ago






                                                                                  • 3




                                                                                    @EduardoHoefel It's a slightly strange quirk of the site that a language + flags is a language in it's own right by meta consensus (hence the title "Japt -x")
                                                                                    – Jonathan Allan
                                                                                    1 hour ago










                                                                                  • How about this ?
                                                                                    – Eduardo Hoefel
                                                                                    1 hour ago






                                                                                  • 1




                                                                                    @EduardoHoefel That information is outdated. We don't count flags anymore.
                                                                                    – Dennis♦
                                                                                    27 mins ago















                                                                                  You shouldn't use anything but the value as input. What is that '-x' doing? It should be considered to measure the score.
                                                                                  – Eduardo Hoefel
                                                                                  1 hour ago




                                                                                  You shouldn't use anything but the value as input. What is that '-x' doing? It should be considered to measure the score.
                                                                                  – Eduardo Hoefel
                                                                                  1 hour ago












                                                                                  It's a flag, we don't count them.
                                                                                  – Shaggy
                                                                                  1 hour ago




                                                                                  It's a flag, we don't count them.
                                                                                  – Shaggy
                                                                                  1 hour ago




                                                                                  3




                                                                                  3




                                                                                  @EduardoHoefel It's a slightly strange quirk of the site that a language + flags is a language in it's own right by meta consensus (hence the title "Japt -x")
                                                                                  – Jonathan Allan
                                                                                  1 hour ago




                                                                                  @EduardoHoefel It's a slightly strange quirk of the site that a language + flags is a language in it's own right by meta consensus (hence the title "Japt -x")
                                                                                  – Jonathan Allan
                                                                                  1 hour ago












                                                                                  How about this ?
                                                                                  – Eduardo Hoefel
                                                                                  1 hour ago




                                                                                  How about this ?
                                                                                  – Eduardo Hoefel
                                                                                  1 hour ago




                                                                                  1




                                                                                  1




                                                                                  @EduardoHoefel That information is outdated. We don't count flags anymore.
                                                                                  – Dennis♦
                                                                                  27 mins ago




                                                                                  @EduardoHoefel That information is outdated. We don't count flags anymore.
                                                                                  – Dennis♦
                                                                                  27 mins ago

















                                                                                   

                                                                                  draft saved


                                                                                  draft discarded















































                                                                                   


                                                                                  draft saved


                                                                                  draft discarded














                                                                                  StackExchange.ready(
                                                                                  function ()
                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175236%2fsum-square-difference%23new-answer', 'question_page');

                                                                                  );

                                                                                  Post as a guest













































































                                                                                  Popular posts from this blog

                                                                                  How to check contact read email or not when send email to Individual?

                                                                                  Bahrain

                                                                                  Postfix configuration issue with fips on centos 7; mailgun relay