This site is supported by donations to The OEIS Foundation.

Template:GCD/test

From OeisWiki
Jump to: navigation, search
This is the testing template for the {{GCD}} mathematical function template.

Valid input

One or two integers, not all 0, as parameters.

Test

Tests with valid input (returns )

code result
{{GCD|6}} 6
{{GCD|0|6}} 6
{{GCD|6|0}} 6
{{GCD|16|6}} 2
{{GCD|16|32}} 16
{{GCD|25|625}} 25
{{GCD|544|119}} 17
{{GCD|119|544}} 17
{{GCD|-544|119}} 17
{{GCD|544|-119}} 17
{{GCD|-544|-119}} 17
{{GCD|2089|3571}} 1
{{GCD|3571|2089}} 1
{{GCD|{{Fibonacci|12}}|{{Fibonacci|11}}}} = {{GCD|144|89}} 1
{{GCD|{{Fibonacci|13}}|{{Fibonacci|12}}}} = {{GCD|233|144}} 1
{{GCD|{{Fibonacci|14}}|{{Fibonacci|13}}}} = {{GCD|377|233}} 1
{{GCD|{{Fibonacci|15}}|{{Fibonacci|14}}}} = {{GCD|610|377}} 1
{{GCD|{{Fibonacci|16}}|{{Fibonacci|15}}}} = {{GCD|987|610}} Expression error: Unrecognized punctuation character "{".
{{GCD|{{Fibonacci|17}}|{{Fibonacci|16}}}} = {{GCD|1597|987}} Expression error: Unrecognized punctuation character "{".
{{GCD|{{Fibonacci|18}}|{{Fibonacci|17}}}} = {{GCD|2584|1597}} Expression error: Unrecognized punctuation character "{".
{{GCD|{{Fibonacci|19}}|{{Fibonacci|18}}}} = {{GCD|4181|2584}} Expression error: Unrecognized punctuation character "{".
{{GCD|{{Fibonacci|20}}|{{Fibonacci|19}}}} = {{GCD|6765|4181}} Expression error: Unrecognized punctuation character "{".
{{GCD|20891|35713}} 1
{{GCD|{{expr|2*3*5*7*11*13*17*19}}|{{expr|7*17*101*113}}}} 119

Examples with invalid input (returns an error message)

code result
{{GCD|ten|fifteen}} GCD error: One or two integers as arguments are required.
{{GCD|6.74|9}} GCD error: One or two integers as arguments are required.
{{GCD|2/3|4/9}} GCD error: One or two integers as arguments are required.
{{GCD}} GCD error: One or two integers as arguments are required.
{{GCD|0}} 0
{{GCD|0|0}} 0

Code

GCD code

This code returns the GCD of one or two integers, not all 0, as a positive integer.

{{ifint| {{{1|0}}} 
| {{ifint| {{{2|0}}} 
  | {{#ifexpr: abs ( {{{1|0}}} ) + abs ( {{{2|0}}} ) = 0 
    | {{error| GCD Error: Arguments cannot all be zero }}
    | {{#ifexpr: abs ( {{{1|0}}} * {{{2|0}}} ) = 0 
        | {{#expr: abs ( {{{1|0}}} + {{{2|0}}} ) }} 
        | {{#ifexpr: abs {{{1|0}}} > abs {{{2|0}}} 
            | {{~GCD| {{#expr: abs {{{1|0}}} }} | {{#expr: abs {{{2|0}}} }} }} 
            | {{~GCD| {{#expr: abs {{{2|0}}} }} | {{#expr: abs {{{1|0}}} }} }}
          }}
      }}
    }}
  | {{error| GCD error: Arguments must be integers }}
  }}
| {{error| GCD error: Arguments must be integers }}
}}

~GCD core code

The current GCD code allows for up to 10 iterations (each starting over from scratch, yuk!) of the Euclidean algorithm. As you can see, this code is horrendously inefficient, since it has no local variables and recalculates everything for each iteration! :-( Is it the best that can be done, with the currently installed parser functions extensions to the MediaWiki server, to implement {{GCD}}?

Templates do not allow (unless the required parser functions extensions to the MediaWiki server are installed) any of

  • local variables
  • iteration (loops)
  • recursion
<!-- start iteration 0 -->

{{#ifexpr: {{{2|0}}} = 0 
| {{{1|0}}} <!-- returns 0 if both 0 --> 

| <!-- start iteration 1 -->

  {{#ifexpr: 
    (
      {{{1}}} 
      mod <!-- divisor 1 --> 
      {{{2}}}
    ) = 0 
  | <!-- return divisor 1 -->
    {{{2}}} 

  | <!-- start iteration 2 -->

    {{#ifexpr: 
      ( {{{2}}} 
        mod <!-- divisor 2 --> 
        (
          {{{1}}} mod {{{2}}}
        )
      ) = 0 
    | {{#expr: <!-- return divisor 2 --> 
        {{{1}}} mod {{{2}}} 
      }} 

    | <!-- start iteration 3 -->

      {{#ifexpr: 
        ( 
          ( 
            {{{1}}} mod {{{2}}} 
          ) 
          mod <!-- divisor 3 --> 
          ( {{{2}}} mod 
            ( 
              {{{1}}} mod {{{2}}} 
            ) 
          )
        ) = 0 
      | {{#expr: <!-- return divisor 3 --> 
          {{{2}}} mod 
          ( 
            {{{1}}} mod {{{2}}} 
          ) 
        }} 

      | <!-- start iteration 4 -->

<!--4-->{{#ifexpr: 
          ( 
            ( {{{2}}} mod 
              ( 
                {{{1}}} mod {{{2}}} 
              ) 
            ) 
            mod <!-- divisor 4 --> 
            (
              ( 
                {{{1}}} mod {{{2}}}
              ) mod 
              ( {{{2}}} mod 
                (
                  {{{1}}} mod {{{2}}}
                )
              )
            )
          ) = 0 
<!--4-->| {{#expr: <!-- return divisor 4 --> 
            (
              {{{1}}} mod {{{2}}}
            ) mod 
            (
              {{{2}}} mod 
              (
                {{{1}}} mod {{{2}}}
              )
            ) 
          }} 

<!--4-->| <!-- start iteration 5 -->

<!-- 5 -->{{#ifexpr: 
            (
              (
                ( 
                  {{{1}}} mod {{{2}}} 
                ) mod 
                ( {{{2}}} mod 
                  (
                    {{{1}}} mod {{{2}}} 
                  )
                )
              ) 
              mod <!-- divisor 5 --> 
              (
                ( {{{2}}} mod 
                  ( 
                    {{{1}}} mod {{{2}}} 
                  )
                ) mod 
                ( 
                  ( 
                    {{{1}}} mod {{{2}}} 
                  ) mod 
                  ( {{{2}}} mod 
                    ( 
                      {{{1}}} mod {{{2}}} 
                    )
                  )
                )
              )
            ) = 0 
<!-- 5 -->| {{#expr: <!-- return divisor 5 --> 
              ( {{{2}}} mod 
                ( 
                  {{{1}}} mod {{{2}}}
                )
              ) mod 
              (
                (
                  {{{1}}} mod {{{2}}}
                ) mod 
                ( {{{2}}} mod 
                  ( 
                    {{{1}}} mod {{{2}}} 
                  )
                )
              ) 
            }} 

<!-- 5 -->| <!-- start iteration 6 -->

<!--  6  -->{{#ifexpr: 
              (
                (
                  ( {{{2}}} mod 
                    ( 
                      {{{1}}} mod {{{2}}}
                    ) 
                  ) mod 
                  ( 
                    ( 
                      {{{1}}} mod {{{2}}} 
                    ) mod 
                    ( {{{2}}} mod 
                      ( 
                        {{{1}}} mod {{{2}}} 
                      ) 
                    )
                  )
                ) mod <!-- divisor 6 --> 
                (
                  (
                    ( 
                      {{{1}}} mod {{{2}}}
                    ) mod 
                    ( {{{2}}} mod 
                      ( 
                        {{{1}}} mod {{{2}}}
                      )
                    ) 
                  ) mod 
                  ( 
                    ( {{{2}}} mod 
                      ( 
                        {{{1}}} mod {{{2}}}
                      ) 
                    ) mod 
                    ( 
                      ( 
                        {{{1}}} mod {{{2}}} 
                      ) mod 
                      ( {{{2}}} mod 
                        ( 
                          {{{1}}} mod {{{2}}} 
                        )
                      )
                    )
                  )
                )
              ) = 0 
<!--  6  -->| {{#expr: <!-- return divisor 6 --> 
                ( 
                  ( 
                    {{{1}}} mod {{{2}}} 
                  ) mod 
                  ( {{{2}}} mod 
                    ( 
                      {{{1}}} mod {{{2}}} 
                    )
                  )
                ) mod 
                ( 
                  ( {{{2}}} mod 
                    ( 
                      {{{1}}} mod {{{2}}} 
                    )
                  ) mod 
                  ( 
                    ( 
                      {{{1}}} mod {{{2}}} 
                    ) mod 
                    ( {{{2}}} mod 
                      ( 
                        {{{1}}} mod {{{2}}} 
                      )
                    )
                  )
                ) 
              }} 

<!--  6  -->| <!-- start iteration 7 -->
        
<!--   7   -->{{#ifexpr: 
                (
                  (
                    (
                      ( 
                        {{{1}}} mod {{{2}}} 
                      ) mod 
                      ( {{{2}}} mod 
                        ( 
                          {{{1}}} mod {{{2}}}
                        ) 
                      ) 
                    ) mod 
                    (
                      ( {{{2}}} mod 
                        ( 
                          {{{1}}} mod {{{2}}}
                        ) 
                      ) mod 
                      ( 
                        ( 
                          {{{1}}} mod {{{2}}} 
                        ) mod 
                        ( {{{2}}} mod 
                          ( 
                            {{{1}}} mod {{{2}}} 
                          )
                        )
                      )
                    )
                  ) mod 
                  (
                    (
                      ( {{{2}}} mod 
                        ( 
                          {{{1}}} mod {{{2}}} 
                        )
                      ) mod 
                      ( 
                        ( 
                          {{{1}}} mod {{{2}}} 
                        ) mod 
                        ( {{{2}}} mod 
                          ( 
                            {{{1}}} mod {{{2}}} 
                          )
                        )
                      )
                    ) mod 
                    ( 
                      (
                        ( 
                          {{{1}}} mod {{{2}}} 
                        ) mod 
                        ( {{{2}}} mod 
                          ( 
                            {{{1}}} mod {{{2}}} 
                          )
                        )
                      ) mod 
                      ( 
                        ( {{{2}}} mod 
                          ( 
                            {{{1}}} mod {{{2}}} 
                          )
                        ) mod 
                        ( 
                          ( 
                             {{{1}}} mod {{{2}}} 
                          ) mod 
                          ( {{{2}}} mod 
                            ( 
                               {{{1}}} mod {{{2}}} 
                            )
                          )
                        )
                      )
                    )
                  )
                ) = 0 
<!--   7   -->| {{#expr: 
                  (
                    ( {{{2}}} mod 
                      ( 
                        {{{1}}} mod {{{2}}} 
                      )
                    ) mod 
                    (
                      ( 
                        {{{1}}} mod {{{2}}} 
                      ) mod 
                      ( {{{2}}} mod 
                        ( 
                          {{{1}}} mod {{{2}}} 
                        )
                      )
                    )
                  ) mod 
                  ( 
                    (
                      ( 
                        {{{1}}} mod {{{2}}} 
                      ) mod 
                      ( {{{2}}} mod 
                        ( 
                          {{{1}}} mod {{{2}}} 
                        )
                      )
                    ) mod 
                    ( 
                      ( {{{2}}} mod 
                        ( 
                          {{{1}}} mod {{{2}}} 
                        )
                      ) mod 
                      ( 
                        ( 
                          {{{1}}} mod {{{2}}} 
                        ) mod 
                        ( {{{2}}} mod 
                          ( 
                            {{{1}}} mod {{{2}}} 
                          )
                        )
                      )
                    )
                  )
                }} 

<!--   7   -->| <!-- start iteration 8 -->
        
<!--    8    -->{{#ifexpr: 
                  (
                    (
                      (
                        ( {{{2}}} mod 
                          ( 
                            {{{1}}} mod {{{2}}} 
                          )
                        ) mod 
                        ( 
                          ( 
                            {{{1}}} mod {{{2}}} 
                          ) mod 
                          ( {{{2}}} mod 
                            ( 
                              {{{1}}} mod {{{2}}} 
                            )
                          )
                        )
                      ) mod 
                      ( 
                        (
                          ( 
                            {{{1}}} mod {{{2}}} 
                          ) mod 
                          ( {{{2}}} mod 
                            ( 
                              {{{1}}} mod {{{2}}} 
                            )
                          )
                        ) mod 
                        ( 
                          ( {{{2}}} mod 
                            ( 
                              {{{1}}} mod {{{2}}} 
                            )
                          ) mod 
                          ( 
                            ( 
                              {{{1}}} mod {{{2}}} 
                            ) mod 
                            ( {{{2}}} mod 
                              ( 
                                {{{1}}} mod {{{2}}} 
                              )
                            )
                          )
                        )
                      )
                    ) mod 
                    ( 
                      (
                        (
                          ( 
                            {{{1}}} mod {{{2}}} 
                          ) mod 
                          ( {{{2}}} mod 
                            ( 
                              {{{1}}} mod {{{2}}} 
                            )
                          )
                        ) mod 
                        ( 
                          ( {{{2}}} mod 
                            ( 
                              {{{1}}} mod {{{2}}} 
                            )
                          ) mod 
                          ( 
                            ( 
                              {{{1}}} mod {{{2}}} 
                            ) mod 
                            ( {{{2}}} mod 
                              ( 
                                {{{1}}} mod {{{2}}} 
                              )
                            )
                          )
                        )
                      ) mod 
                      ( 
                        (
                          ( {{{2}}} mod 
                            ( 
                              {{{1}}} mod {{{2}}} 
                            )
                          ) mod 
                          (
                            ( 
                              {{{1}}} mod {{{2}}} 
                            ) mod 
                            ( {{{2}}} mod 
                              ( 
                                {{{1}}} mod {{{2}}} 
                              )
                            )
                          )
                        ) mod 
                        (
                          (
                            ( 
                              {{{1}}} mod {{{2}}} 
                            ) mod 
                            ( {{{2}}} mod 
                              ( 
                                {{{1}}} mod {{{2}}} 
                              )
                            )
                          ) mod 
                          (
                            ( {{{2}}} mod 
                              ( 
                                {{{1}}} mod {{{2}}} 
                              )
                            ) mod 
                            (
                              ( 
                                {{{1}}} mod {{{2}}} 
                              ) mod 
                              ( {{{2}}} mod 
                                ( 
                                  {{{1}}} mod {{{2}}} 
                                )
                              )
                            )
                          )
                        )
                      )
                    )
                  ) = 0 
<!--    8    -->| {{#expr: ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))))}} 

<!--    8    -->| <!-- start iteration 9 -->

<!--     9     -->{{#ifexpr: ((((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))))) mod (((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))))) mod (((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))))))) = 0 
<!--     9     -->| {{#expr: ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))))) mod (((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))))))}} 

<!--     9     -->| <!-- start iteration 10 -->

<!--     10      -->{{#ifexpr: ((((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))))) mod (((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))))))) mod ((((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))))) mod (((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))))) mod (((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))))))))) = 0 
<!--     10      -->| {{#expr: (((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))))) mod (((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))))) mod (((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))) mod ((({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}})))) mod ((({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))) mod (({{{2}}} mod ({{{1}}} mod {{{2}}})) mod (({{{1}}} mod {{{2}}}) mod ({{{2}}} mod ({{{1}}} mod {{{2}}}))))))))}} 

<!--     10      -->| <!-- start iteration 11 --> 

<!--      11       -->0 <!-- give up on iteration 11 (needs more than 10 iterations) and return 0 -->
<!--      11       -->    <!-- end iteration 11 -->

<!--     10      -->}} <!-- end iteration 10 -->
<!--     9     -->}} <!-- end iteration 9 -->
<!--    8    -->}} <!-- end iteration 8 -->
<!--   7   -->}} <!-- end iteration 7 -->
<!--  6  -->}} <!-- end iteration 6 -->
<!-- 5 -->}} <!-- end iteration 5 -->
<!--4-->}} <!-- end iteration 4 -->
      }} <!-- end iteration 3 -->
    }} <!-- end iteration 2 -->
  }} <!-- end iteration 1 -->
}}

~GCD core code backup (original code without identations, spaces or comments from Wikipedia)

The code is commented out, visible in edit mode. Essentially the same as the above code, but without any of the added identations, spaces or comments (a big lump of code!)

~GCD core code (recursive)

Templates do not allow

  • local variables (unless the required parser functions extensions are installed in the MediaWiki server)
  • iteration (loops) (unless the required parser functions extensions are installed in the MediaWiki server)
  • recursion (never allowed with templates)
{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD core code (pseudo-recursive)

The {{~GCD}} core function template uses the auxiliary core function template {{~GCD~1}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~1| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~1 auxiliary core code (pseudo-recursive)

The {{~GCD~1}} auxiliary core function template uses the auxiliary core function template {{~GCD~2}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~2| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~2 auxiliary core code (pseudo-recursive)

The {{~GCD~2}} auxiliary core function template uses the auxiliary core function template {{~GCD~3}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~3| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~3 auxiliary core code (pseudo-recursive)

The {{~GCD~3}} auxiliary core function template uses the auxiliary core function template {{~GCD~4}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~4| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~4 auxiliary core code (pseudo-recursive)

The {{~GCD~4}} auxiliary core function template uses the auxiliary core function template {{~GCD~5}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~5| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~5 auxiliary core code (pseudo-recursive)

The {{~GCD~5}} auxiliary core function template uses the auxiliary core function template {{~GCD~6}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~6| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~6 auxiliary core code (pseudo-recursive)

The {{~GCD~6}} auxiliary core function template uses the auxiliary core function template {{~GCD~7}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~7| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~7 auxiliary core code (pseudo-recursive)

The {{~GCD~7}} auxiliary core function template uses the auxiliary core function template {{~GCD~8}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~8| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~8 auxiliary core code (pseudo-recursive)

The {{~GCD~8}} auxiliary core function template uses the auxiliary core function template {{~GCD~9}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~9| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~9 auxiliary core code (pseudo-recursive)

The {{~GCD~9}} auxiliary core function template uses the auxiliary core function template {{~GCD~10}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~10| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~10 auxiliary core code (pseudo-recursive)

The {{~GCD~10}} auxiliary core function template uses the auxiliary core function template {{~GCD~11}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~11| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~11 auxiliary core code (pseudo-recursive)

The {{~GCD~11}} auxiliary core function template uses the auxiliary core function template {{~GCD~12}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~12| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~12 auxiliary core code (pseudo-recursive)

The {{~GCD~12}} auxiliary core function template uses the auxiliary core function template {{~GCD~13}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~13| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~13 auxiliary core code (pseudo-recursive)

The {{~GCD~13}} auxiliary core function template uses the auxiliary core function template {{~GCD~14}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~14| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~14 auxiliary core code (pseudo-recursive)

The {{~GCD~14}} auxiliary core function template uses the auxiliary core function template {{~GCD~15}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~15| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}

~GCD~15 auxiliary core code (pseudo-recursive)

The {{~GCD~15}} auxiliary core function template uses the auxiliary core function template {{~GCD~16}} to implement pseudo-recursion.

{{#ifexpr: {{{1}}} mod {{{2}}} = 0 
  | {{{2}}} 
  | {{~GCD~16| {{{2}}} | {{#expr: {{{1}}} mod {{{2}}} }} }}
}}