Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 62 characters in body
Source Link
emanresu A
  • 46.2k
  • 5
  • 111
  • 257

K (oK), (削除) 47 (削除ここまで) 42(削除) 42 (削除ここまで) 41 bytes

f:{[a]ii{$[y;o[x;y-1]+o[x-1;x-y];a x]}'i:!#a:x}

Try it online! Try it online!

A function taking an array of numbers. -5 thanks to ngn. -1 thanks to Razetime.

{[a] // A function taking an argument a, returning...
 { // A function, returning
 $[ // A switch statemnet
 y; // If y (second arg) is nonzero
 o[x;y-1]+o[x-1;x-y]; // Do a recursive call
 a x // Else index x into a
 ] 
 }'i: // Call with the first argument as both arguments
 '!#a:x} // Map this over a range of the same length as the input, which we also assign to a for later use

K (oK), (削除) 47 (削除ここまで) 42 bytes

f:{[a]i{$[y;o[x;y-1]+o[x-1;x-y];a x]}'i:!#a}

Try it online!

A function taking an array of numbers. -5 thanks to ngn.

{[a] // A function taking an argument a, returning...
 { // A function, returning
 $[ // A switch statemnet
 y; // If y (second arg) is nonzero
 o[x;y-1]+o[x-1;x-y]; // Do a recursive call
 a x // Else index x into a
 ] 
 }'i: // Call with the first argument as both arguments
 '!#a} // Map this over a range of the same length as a

K (oK), (削除) 47 (削除ここまで) (削除) 42 (削除ここまで) 41 bytes

f:{i{$[y;o[x;y-1]+o[x-1;x-y];a x]}'i:!#a:x}

Try it online!

A function taking an array of numbers. -5 thanks to ngn. -1 thanks to Razetime.

{ // A function returning...
 { // A function, returning
 $[ // A switch statemnet
 y; // If y (second arg) is nonzero
 o[x;y-1]+o[x-1;x-y]; // Do a recursive call
 a x // Else index x into a
 ] 
 }'i: // Call with the first argument as both arguments
 '!#a:x} // Map this over a range of the same length as the input, which we also assign to a for later use
deleted 201 characters in body
Source Link
emanresu A
  • 46.2k
  • 5
  • 111
  • 257

K (oK), (削除) 47 (削除ここまで) 4542 bytes

{[a]f:{[a]i{$[y;o[x;y-1]+o[x-1;x-y];a x]}/2#x}''i:!#a}

Try it online! Try it online!

A function taking an array of numbers. -25 thanks to ngn.

{[a] // A function taking an argument a, returning...
 { // An anonymous function, returning..
 {  // An anonymousA function, returning...
 $[ // Switch statement
A switch statemnet
 y; // If y (second argumentarg), then...
 is nonzero
 o[x;y-1]+o[x-1;x-y]; // RecursiveDo call
a recursive call
 a x // Else index x into a
 ] // End switch statement
 }2円#x'i:  // Call this function with the first inputargument as arg,both twicearguments
 }'!#a} // Map this to...
 !#a  //over 0...len(a)
}  range of the same //length Closeas functiona

K (oK), (削除) 47 (削除ここまで) 45 bytes

{[a]{{$[y;o[x;y-1]+o[x-1;x-y];a x]}/2#x}'!#a}

Try it online!

A function taking an array of numbers. -2 thanks to ngn.

{[a] // A function taking an argument a, returning...
 { // An anonymous function, returning..
 {  // An anonymous function, returning...
 $[ // Switch statement
 y; // If y (second argument), then...
 o[x;y-1]+o[x-1;x-y]; // Recursive call
 a x // Else index into a
 ] // End switch statement
 }2円#x // Call this function with first input as arg, twice
 }' // Map this to...
 !#a  // 0...len(a)
}  // Close function

K (oK), (削除) 47 (削除ここまで) 42 bytes

f:{[a]i{$[y;o[x;y-1]+o[x-1;x-y];a x]}'i:!#a}

Try it online!

A function taking an array of numbers. -5 thanks to ngn.

{[a] // A function taking an argument a, returning...
 { // A function, returning
 $[ // A switch statemnet
 y; // If y (second arg) is nonzero
 o[x;y-1]+o[x-1;x-y]; // Do a recursive call
 a x // Else index x into a
 ] 
 }'i:  // Call with the first argument as both arguments
 '!#a} // Map this over a range of the same length as a
added 23 characters in body
Source Link
emanresu A
  • 46.2k
  • 5
  • 111
  • 257

K (oK), 47(削除) 47 (削除ここまで) 45 bytes

{[a]{{$[y;o[x;y-1]+o[x-1;x-y];a[x]]y];a x]}[x;x]/2#x}'!#a}

Try it online! Try it online!

A function taking an array of numbers. -2 thanks to ngn.

{[a] // A function taking an argument a, returning...
 { // An anonymous function, returning..
 { // An anonymous function, returning...
 $[ // Switch statement
 y; // If y (second argument), then...
 o[x;y-1]+o[x-1;x-y]; // Recursive call
 a[x]a x  // Else index into a
 ] // End switch statement
 }[x;x]2円#x  // Call this function with first input as arg, twice
 }' // Map this to...
 !#a // 0...len(a)
} // Close function

K (oK), 47 bytes

{[a]{{$[y;o[x;y-1]+o[x-1;x-y];a[x]]}[x;x]}'!#a}

Try it online!

A function taking an array of numbers.

{[a] // A function taking an argument a, returning...
 { // An anonymous function, returning..
 { // An anonymous function, returning...
 $[ // Switch statement
 y; // If y (second argument), then...
 o[x;y-1]+o[x-1;x-y]; // Recursive call
 a[x] // Else index into a
 ] // End switch statement
 }[x;x] // Call this function with first input as arg, twice
 }' // Map this to...
 !#a // 0...len(a)
} // Close function

K (oK), (削除) 47 (削除ここまで) 45 bytes

{[a]{{$[y;o[x;y-1]+o[x-1;x-y];a x]}/2#x}'!#a}

Try it online!

A function taking an array of numbers. -2 thanks to ngn.

{[a] // A function taking an argument a, returning...
 { // An anonymous function, returning..
 { // An anonymous function, returning...
 $[ // Switch statement
 y; // If y (second argument), then...
 o[x;y-1]+o[x-1;x-y]; // Recursive call
 a x  // Else index into a
 ] // End switch statement
 }2円#x  // Call this function with first input as arg, twice
 }' // Map this to...
 !#a // 0...len(a)
} // Close function
Source Link
emanresu A
  • 46.2k
  • 5
  • 111
  • 257
Loading

AltStyle によって変換されたページ (->オリジナル) /