Skip to main content
Commonmark migration
Source Link

#Mathematica, 49 48 bytes

Mathematica, 49 48 bytes

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]
(* or *)
±2=4;±1=0;±n_:=-Tr@Array[(k=±#)&,n-1]+Tr@Range@k

Uses CP-1252 encoding. Defines function PlusMinus (±). 1-indexed.

#Explanation

Explanation

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

±2=4;±1=0;                                        (* Define ±1 and ±2 *)
          ±n_:=                                   (* ±n equals ... *)
               Tr@Range@±(n-1)                    (* Sum of (1, 2, ..., ±(n-1)) ... *)
                              -Tr@Array[±#&,n-1]  (* Minus the sum of previous terms *)

#Mathematica, 49 48 bytes

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]
(* or *)
±2=4;±1=0;±n_:=-Tr@Array[(k=±#)&,n-1]+Tr@Range@k

Uses CP-1252 encoding. Defines function PlusMinus (±). 1-indexed.

#Explanation

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

±2=4;±1=0;                                        (* Define ±1 and ±2 *)
          ±n_:=                                   (* ±n equals ... *)
               Tr@Range@±(n-1)                    (* Sum of (1, 2, ..., ±(n-1)) ... *)
                              -Tr@Array[±#&,n-1]  (* Minus the sum of previous terms *)

Mathematica, 49 48 bytes

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]
(* or *)
±2=4;±1=0;±n_:=-Tr@Array[(k=±#)&,n-1]+Tr@Range@k

Uses CP-1252 encoding. Defines function PlusMinus (±). 1-indexed.

Explanation

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

±2=4;±1=0;                                        (* Define ±1 and ±2 *)
          ±n_:=                                   (* ±n equals ... *)
               Tr@Range@±(n-1)                    (* Sum of (1, 2, ..., ±(n-1)) ... *)
                              -Tr@Array[±#&,n-1]  (* Minus the sum of previous terms *)
added 70 characters in body
Source Link
JungHwan Min
  • 13.9k
  • 3
  • 23
  • 69

#Mathematica, 49 48 bytes

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]
(* or *)
±2=4;±1=0;±n_:=-Tr@Array[(k=±#)&,n-1]+Tr@Range@k

Uses CP-1252 encoding. Defines function PlusMinus (±). 1-indexed.

#Explanation

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

±2=4;±1=0;                                        (* Define ±1 and ±2 *)
          ±n_:=                                   (* ±n equals ... *)
               Tr@Range@±(n-1)                    (* Sum of (1, 2, ..., ±(n-1)) ... *)
                              -Tr@Array[±#&,n-1]  (* Minus the sum of previous terms *)

#Mathematica, 49 48 bytes

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

Uses CP-1252 encoding. Defines function PlusMinus (±). 1-indexed.

#Explanation

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

±2=4;±1=0;                                        (* Define ±1 and ±2 *)
          ±n_:=                                   (* ±n equals ... *)
               Tr@Range@±(n-1)                    (* Sum of (1, 2, ..., ±(n-1)) ... *)
                              -Tr@Array[±#&,n-1]  (* Minus the sum of previous terms *)

#Mathematica, 49 48 bytes

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]
(* or *)
±2=4;±1=0;±n_:=-Tr@Array[(k=±#)&,n-1]+Tr@Range@k

Uses CP-1252 encoding. Defines function PlusMinus (±). 1-indexed.

#Explanation

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

±2=4;±1=0;                                        (* Define ±1 and ±2 *)
          ±n_:=                                   (* ±n equals ... *)
               Tr@Range@±(n-1)                    (* Sum of (1, 2, ..., ±(n-1)) ... *)
                              -Tr@Array[±#&,n-1]  (* Minus the sum of previous terms *)
matching brackets
Source Link
JungHwan Min
  • 13.9k
  • 3
  • 23
  • 69

#Mathematica, 4949 48 bytes

f@2=4;f@1=0;f@n_±2=4;±1=0;±n_:=Tr@Range@f[n=Tr@Range@±(n-1]1)-Tr@Array[fTr@Array[±#&,n-1]

Uses CP-1252 encoding. Defines function fPlusMinus (±). 1-indexed.

#Explanation

f@2=4;f@1=0;f@n_±2=4;±1=0;±n_:=Tr@Range@f[n=Tr@Range@±(n-1]1)-Tr@Array[fTr@Array[±#&,n-1]

f@2=4;f@1=0;±2=4;±1=0;                                        (* Define f[1]±1 and f[2]±2 *)
            f@n_±n_:=                                   (* f[n]±n equals ... *)
                Tr@Range@±(n-1)  Tr@Range@f[n-1]                  (* Sum of (1, 2, ..., f[n±(n-1]1)) ... *)
                                 -Tr@Array[fTr@Array[±#&,n-1]  (* Minus the sum of previous terms *)

#Mathematica, 49 bytes

f@2=4;f@1=0;f@n_:=Tr@Range@f[n-1]-Tr@Array[f,n-1]

Defines function f. 1-indexed.

#Explanation

f@2=4;f@1=0;f@n_:=Tr@Range@f[n-1]-Tr@Array[f,n-1]

f@2=4;f@1=0;                                       (* Define f[1] and f[2] *)
            f@n_:=                                 (* f[n] equals ... *)
                  Tr@Range@f[n-1]                  (* Sum of (1, 2, ..., f[n-1]) *)
                                 -Tr@Array[f,n-1]  (* Minus the sum of previous terms *)

#Mathematica, 49 48 bytes

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

Uses CP-1252 encoding. Defines function PlusMinus (±). 1-indexed.

#Explanation

±2=4;±1=0;±n_:=Tr@Range@±(n-1)-Tr@Array[±#&,n-1]

±2=4;±1=0;                                        (* Define ±1 and ±2 *)
          ±n_:=                                   (* ±n equals ... *)
               Tr@Range@±(n-1)                    (* Sum of (1, 2, ..., ±(n-1)) ... *)
                              -Tr@Array[±#&,n-1]  (* Minus the sum of previous terms *)
matching brackets
Source Link
JungHwan Min
  • 13.9k
  • 3
  • 23
  • 69
Loading
added 422 characters in body
Source Link
JungHwan Min
  • 13.9k
  • 3
  • 23
  • 69
Loading
Source Link
JungHwan Min
  • 13.9k
  • 3
  • 23
  • 69
Loading