5 deleted 620 characters in body
source | link

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 47 bytes

n=>n.Select((a,i)=>i<1?a:Max(a-n[i-1],0)).Sum()

Try it online!

Old version, with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

Testing code stolen from @someone in his haystack post. UsesI feel like this solution is more elegant than the second value offirst one. It goes through the array with a two-value tuple as a sort of memorystarting value, to accesspicking up values, and stores the value before it in the current onesecond part of the tuple.

Try it online!

Explanation

//Lambda taking one parameter, 'n'
n=>
//Loop over the array
n.Aggregate(
//Using a (int,int) tuple as the seed
//The first part of the tuple is amount of brushstrokes, 
//and the second part is the previous element's value
(0,0),
//Lambda taking in the seed and the current value we are on
(a,b)=>
//The first part of the tuple becomes it's old value
(a.Item1
//Plus zero or the current value minus the tuple's second value, whichever is bigger
+Max(0,b-a.Item2),
//And the tuple's second part becomes the current valye
b))
//And lastly we return the first part
.Item1

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 47 bytes

n=>n.Select((a,i)=>i<1?a:Max(a-n[i-1],0)).Sum()

Try it online!

Old version, with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

Testing code stolen from @someone in his haystack post. Uses the second value of the tuple as a sort of memory, to access the value before the current one.

Try it online!

Explanation

//Lambda taking one parameter, 'n'
n=>
//Loop over the array
n.Aggregate(
//Using a (int,int) tuple as the seed
//The first part of the tuple is amount of brushstrokes, 
//and the second part is the previous element's value
(0,0),
//Lambda taking in the seed and the current value we are on
(a,b)=>
//The first part of the tuple becomes it's old value
(a.Item1
//Plus zero or the current value minus the tuple's second value, whichever is bigger
+Max(0,b-a.Item2),
//And the tuple's second part becomes the current valye
b))
//And lastly we return the first part
.Item1

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 47 bytes

n=>n.Select((a,i)=>i<1?a:Max(a-n[i-1],0)).Sum()

Try it online!

Old version, with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

I feel like this solution is more elegant than the first one. It goes through the array with a two-value tuple as a starting value, picking up values, and stores the value before it in the second part of the tuple.

Try it online!

4 added 688 characters in body
source | link

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 6347 bytes

n=>n.Select((a,i)=>i<1?a:Max(a-n[i-1],0)).Sum()

Try it online!

Old version, with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

Testing code stolen from @someone in his haystack post. Uses the second value of the tuple as a sort of memory, to access the value before the current one.

Try it online!

Explanation

//Lambda taking one parameter, 'n'
n=>
//Loop over the array
n.Aggregate(
//Using a (int,int) tuple as the seed
//The first part of the tuple is amount of brushstrokes, 
//and the second part is the previous element's value
(0,0),
//Lambda taking in the seed and the current value we are on
(a,b)=>
//The first part of the tuple becomes it's old value
(a.Item1
//Plus zero or the current value minus the tuple's second value, whichever is bigger
+Max(0,b-a.Item2),
//And the tuple's second part becomes the current valye
b))
//And lastly we return the first part
.Item1

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

Testing code stolen from @someone in his haystack post. Uses the second value of the tuple as a sort of memory, to access the value before the current one.

Try it online!

Explanation

//Lambda taking one parameter, 'n'
n=>
//Loop over the array
n.Aggregate(
//Using a (int,int) tuple as the seed
//The first part of the tuple is amount of brushstrokes, 
//and the second part is the previous element's value
(0,0),
//Lambda taking in the seed and the current value we are on
(a,b)=>
//The first part of the tuple becomes it's old value
(a.Item1
//Plus zero or the current value minus the tuple's second value, whichever is bigger
+Max(0,b-a.Item2),
//And the tuple's second part becomes the current valye
b))
//And lastly we return the first part
.Item1

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 47 bytes

n=>n.Select((a,i)=>i<1?a:Max(a-n[i-1],0)).Sum()

Try it online!

Old version, with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

Testing code stolen from @someone in his haystack post. Uses the second value of the tuple as a sort of memory, to access the value before the current one.

Try it online!

Explanation

//Lambda taking one parameter, 'n'
n=>
//Loop over the array
n.Aggregate(
//Using a (int,int) tuple as the seed
//The first part of the tuple is amount of brushstrokes, 
//and the second part is the previous element's value
(0,0),
//Lambda taking in the seed and the current value we are on
(a,b)=>
//The first part of the tuple becomes it's old value
(a.Item1
//Plus zero or the current value minus the tuple's second value, whichever is bigger
+Max(0,b-a.Item2),
//And the tuple's second part becomes the current valye
b))
//And lastly we return the first part
.Item1
3 added 102 characters in body
source | link

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

Testing code stolen from @someone in his haystack post. Uses the second value of the tuple as a sort of memory, to access the value before the current one.

Try it online!

Explanation

//Lambda taking one parameter, 'n'
n=>
//Loop over the array
n.Aggregate(
//Using a (int,int) tuple as the seed
//The first part of the tuple is amount of brushstrokes, 
//and the second part is the previous element's value
(0,0),
//Lambda taking in the seed and the current value we are on
(a,b)=>
//The first part of the tuple becomes it's old value
(a.Item1
//Plus zero or the current value minus the tuple's second value, whichever is bigger
+Max(0,b-a.Item2),
//And the tuple's second part becomes the current valye
b))
//And lastly we return the first part
.Item1

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

Testing code stolen from @someone in his haystack post

Try it online!

Explanation

//Lambda taking one parameter, 'n'
n=>
//Loop over the array
n.Aggregate(
//Using a (int,int) tuple as the seed
//The first part of the tuple is amount of brushstrokes, 
//and the second part is the previous element's value
(0,0),
//Lambda taking in the seed and the current value we are on
(a,b)=>
//The first part of the tuple becomes it's old value
(a.Item1
//Plus zero or the current value minus the tuple's second value, whichever is bigger
+Max(0,b-a.Item2),
//And the tuple's second part becomes the current valye
b))
//And lastly we return the first part
.Item1

C# (Visual C# Interactive Compiler) with flag /u:System.Math, 63 bytes

n=>n.Aggregate((0,0),(a,b)=>(a.Item1+Max(0,b-a.Item2),b)).Item1

Testing code stolen from @someone in his haystack post. Uses the second value of the tuple as a sort of memory, to access the value before the current one.

Try it online!

Explanation

//Lambda taking one parameter, 'n'
n=>
//Loop over the array
n.Aggregate(
//Using a (int,int) tuple as the seed
//The first part of the tuple is amount of brushstrokes, 
//and the second part is the previous element's value
(0,0),
//Lambda taking in the seed and the current value we are on
(a,b)=>
//The first part of the tuple becomes it's old value
(a.Item1
//Plus zero or the current value minus the tuple's second value, whichever is bigger
+Max(0,b-a.Item2),
//And the tuple's second part becomes the current valye
b))
//And lastly we return the first part
.Item1
2 added 678 characters in body
source | link
1
source | link