Skip to main content
deleted 313 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94

J, 86 62 54 49 47 42 41 4037 bytes

_2&(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#]\)~1<#

Try it online!Try it online!

   f =: _2&(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#]\)~1<#
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
_2&(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#]\)~1<#  Input: x

     array A
                              1<#  Is the input length is# greater than oneLength
                                 ^:  1<   Greater Ifthan true,one?
    _2&(                           ] )~     Execute this if true, else Getreturn xA
 _2                          _2]\   ]\         Split xGet intonon-overlapping sublists of lengthsize 2
 0    0                   |:    |:           Move Transposeaxis it0 to getthe [even-indexend, odd-index]
   equivalent to transpose
                          /@            by movingReduce axis[even-indexed, 0odd-indexed]
 to the end
                    &$:/@                  Call recursively on each list
                #     #                     Get the length of the odd list
             i.@     i.@                      Range from 0 to that length exclusive
                 %#     %#                   Divide each value by thatthe odd length
          _1^     _1^                         Compute (-1)^x for each x in it
         %       ]                          Divide each value inGet the odd list
        ]     %                            Divide byeach ain valuethat inby the previous elementwise
    +     +                                 Add elementwise between the even values
                                           and modified odd values
      -     -                               Subtract elementwise between the even
                                           values and modified odd values
     ,     ,                                Join the two lists and return
                                         Else
                                           Return x (act as identity function)

J, 86 62 54 49 47 42 41 40 bytes

(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#)

Try it online!

   f =: (0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#)
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#) Input: x

                                    1<#  Is the input length is greater than one
                                 ^:      If true,
                               ]           Get x
                           _2]\            Split x into sublists of length 2
 0                       |:                Transpose it to get [even-index, odd-index]
                                           by moving axis 0 to the end
                    &$:/@                  Call recursively on each list
                #                          Get the length of the odd list
             i.@                           Range from 0 to that length exclusive
                 %#                        Divide each value by that length
          _1^                              Compute (-1)^x for each x in it
         %                                 Divide each value in the odd list
        ]                                  by a value in the previous elementwise
    +                                      Add elementwise between the even values
                                           and modified odd values
      -                                    Subtract elementwise between the even
                                           values and modified odd values
     ,                                     Join the two lists and return
                                         Else
                                           Return x (act as identity function)

J, 37 bytes

_2&(0((+,-)]%_1^i.@#%#)&$:/@|:]\)~1<#

Try it online!

   f =: _2&(0((+,-)]%_1^i.@#%#)&$:/@|:]\)~1<#
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
_2&(0((+,-)]%_1^i.@#%#)&$:/@|:]\)~1<#  Input: array A
                                    #  Length
                                  1<   Greater than one?
_2&(                            )~     Execute this if true, else return A
_2                            ]\         Get non-overlapping sublists of size 2
    0                       |:           Move axis 0 to the end, equivalent to transpose
                          /@             Reduce [even-indexed, odd-indexed]
                       &$:               Call recursively on each 
                   #                     Get the length of the odd list
                i.@                      Range from 0 to that length exclusive
                    %#                   Divide each by the odd length
             _1^                         Compute (-1)^x for each x
           ]                             Get the odd list
            %                            Divide each in that by the previous
       +                                 Add the even values and modified odd values
         -                               Subtract the even values and modified odd values
        ,                                Join the two lists and return
deleted 14 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94

J, 86 62 54 49 47 42 4141 40 bytes

(0((+,-)(%_1^i]%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)

Try it online!Try it online!

   f =: (0((+,-)(%_1^i]%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
(0((+,-)(%_1^i]%_1^i.@#%#))&$:/@|:_2]\])^:(1<#) Input: x

                                     1<#  Is the input length is greater than one
                                  ^:      If true,
                                ]           Get x
                            _2]\            Split x into sublists of length 2
 0                        |:                Transpose it to get [even-index, odd-index]
                                            by moving axis 0 to the end
                     &$:/@                  Call recursively on each list
                #                           Get the length of the odd list
             i.@                            Range from 0 to that length exclusive
                 %#                         Divide each value by that length
          _1^                               Compute (-1)^x for each x in it
         %                                  Divide each value in the odd list
          ]                                  by a value in the previous elementwise
    +                                       Add elementwise between the even values
                                            and modified odd values
      -                                     Subtract elementwise between the even
                                            values and modified odd values
     ,                                      Join the two lists and return
                                          Else
                                            Return x (act as identity function)

J, 86 62 54 49 47 42 41 bytes

(0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)

Try it online!

   f =: (0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
(0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#) Input: x

                                     1<#  Is the input length is greater than one
                                  ^:      If true,
                                ]           Get x
                            _2]\            Split x into sublists of length 2
 0                        |:                Transpose it to get [even-index, odd-index]
                                            by moving axis 0 to the end
                     &$:/@                  Call recursively on each list
                #                           Get the length of the odd list
             i.@                            Range from 0 to that length exclusive
                 %#                         Divide each value by that length
          _1^                               Compute (-1)^x for each x in it
         %                                  Divide each value in the odd list
                                            by a value in the previous elementwise
    +                                       Add elementwise between the even values
                                            and modified odd values
      -                                     Subtract elementwise between the even
                                            values and modified odd values
     ,                                      Join the two lists and return
                                          Else
                                            Return x (act as identity function)

J, 86 62 54 49 47 42 41 40 bytes

(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#)

Try it online!

   f =: (0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#)
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#) Input: x

                                    1<#  Is the input length is greater than one
                                 ^:      If true,
                               ]           Get x
                           _2]\            Split x into sublists of length 2
 0                       |:                Transpose it to get [even-index, odd-index]
                                           by moving axis 0 to the end
                    &$:/@                  Call recursively on each list
                #                          Get the length of the odd list
             i.@                           Range from 0 to that length exclusive
                 %#                        Divide each value by that length
          _1^                              Compute (-1)^x for each x in it
         %                                 Divide each value in the odd list
        ]                                  by a value in the previous elementwise
    +                                      Add elementwise between the even values
                                           and modified odd values
      -                                    Subtract elementwise between the even
                                           values and modified odd values
     ,                                     Join the two lists and return
                                         Else
                                           Return x (act as identity function)
added 44 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94

J, 86 62 54 49 47 4242 41 bytes

([:0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)

Try it online!Try it online!

   f =: ([:0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
([:0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#) Input: x

                                      1<#  Is the input length is greater than one
                                   ^:      If true,
                                 ]           Get x
                             _2]\            Split x into sublists of length 2
 [:0                        |:                Transpose it to get [even-index, odd-index]
                                            by moving axis 0 to the end
                     &$:/@                  Call recursively on each list
                 #                           Get the length of the odd list
              i.@                            Range from 0 to that length exclusive
                  %#                         Divide each value by that length
           _1^                               Compute (-1)^x for each x in it
          %                                  Divide each value in the odd list
                                             by a value in the previous elementwise
     +                                       Add elementwise between the even values
                                             and modified odd values
       -                                     Subtract elementwise between the even
                                             values and modified odd values
      ,                                      Join the two lists and return
                                           Else
                                             Return x (act as identity function)

J, 86 62 54 49 47 42 bytes

([:((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)

Try it online!

   f =: ([:((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
([:((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#) Input: x

                                      1<#  Is the input length is greater than one
                                   ^:      If true,
                                 ]           Get x
                             _2]\            Split x into sublists of length 2
 [:                        |:                Transpose it to get [even-index, odd-index]
                      &$:/@                  Call recursively on each list
                 #                           Get the length of the odd list
              i.@                            Range from 0 to that length exclusive
                  %#                         Divide each value by that length
           _1^                               Compute (-1)^x for each x in it
          %                                  Divide each value in the odd list
                                             by a value in the previous elementwise
     +                                       Add elementwise between the even values
                                             and modified odd values
       -                                     Subtract elementwise between the even
                                             values and modified odd values
      ,                                      Join the two lists and return
                                           Else
                                             Return x (act as identity function)

J, 86 62 54 49 47 42 41 bytes

(0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)

Try it online!

   f =: (0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#)
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
(0((+,-)(%_1^i.@#%#))&$:/@|:_2]\])^:(1<#) Input: x

                                     1<#  Is the input length is greater than one
                                  ^:      If true,
                                ]           Get x
                            _2]\            Split x into sublists of length 2
 0                        |:                Transpose it to get [even-index, odd-index]
                                            by moving axis 0 to the end
                     &$:/@                  Call recursively on each list
                #                           Get the length of the odd list
             i.@                            Range from 0 to that length exclusive
                 %#                         Divide each value by that length
          _1^                               Compute (-1)^x for each x in it
         %                                  Divide each value in the odd list
                                            by a value in the previous elementwise
    +                                       Add elementwise between the even values
                                            and modified odd values
      -                                     Subtract elementwise between the even
                                            values and modified odd values
     ,                                      Join the two lists and return
                                          Else
                                            Return x (act as identity function)
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link
Loading
added 234 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
deleted 23 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
added 95 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
added 103 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
added 1591 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
added 4 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
deleted 2 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
deleted 553 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
added 41 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
added 470 characters in body
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading
Source Link
miles
  • 17k
  • 2
  • 30
  • 94
Loading