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

Commonmark migration
Source Link

#Husk , (削除) 18 (削除ここまで) 16 bytes

Husk , (削除) 18 (削除ここまで) 16 bytes

!→0+→G(mΣ∂Ṫ*)2∞0

First Husk answer. This took so much longer to complete than I thought it would. I'm glad there is a tutorial with good explanation of how the input-order and super-numbers work, otherwise I had to give up. I never programmed in Haskell, and maybe I'm just too used to the left-to-right stack-based 05AB1E, but Husk isn't exactly straight-forward due to its strong-typed nature and right-to-left execution (including input-arguments) imho..
But, it works, which is what counts in the end. :)

First input-argument is a list of lists of coefficients where index encodes exponent, like the third input example in the challenge description. Second argument is the coefficient integer \$k\$.

Try it online.

Explanation:

 2 # Use the first argument,
 G( ) # and left-reduce it by:
 Ṫ # Apply double-vectorized:
 * # Multiply
 # (This basically results in the multiplication table of the lists)
 ∂ # Take the diagonals of this multiplication table
 m # Map over these diagonal-lists:
 Σ # And sum each together
 → # Only leave the last list after the reduce-by
 ∞0 # Push an infinite list of 0s: [0,0,0,...]
 + # Merge the two lists together
 0 # Push the second argument `k`
 → # Increase it by 1 (since Husk uses 1-based indexing instead of 0-based)
! # And use it to index into the list we created
 # (after which the result is output implicitly)
 
 

#Husk , (削除) 18 (削除ここまで) 16 bytes

!→0+→G(mΣ∂Ṫ*)2∞0

First Husk answer. This took so much longer to complete than I thought it would. I'm glad there is a tutorial with good explanation of how the input-order and super-numbers work, otherwise I had to give up. I never programmed in Haskell, and maybe I'm just too used to the left-to-right stack-based 05AB1E, but Husk isn't exactly straight-forward due to its strong-typed nature and right-to-left execution (including input-arguments) imho..
But, it works, which is what counts in the end. :)

First input-argument is a list of lists of coefficients where index encodes exponent, like the third input example in the challenge description. Second argument is the coefficient integer \$k\$.

Try it online.

Explanation:

 2 # Use the first argument,
 G( ) # and left-reduce it by:
 Ṫ # Apply double-vectorized:
 * # Multiply
 # (This basically results in the multiplication table of the lists)
 ∂ # Take the diagonals of this multiplication table
 m # Map over these diagonal-lists:
 Σ # And sum each together
 → # Only leave the last list after the reduce-by
 ∞0 # Push an infinite list of 0s: [0,0,0,...]
 + # Merge the two lists together
 0 # Push the second argument `k`
 → # Increase it by 1 (since Husk uses 1-based indexing instead of 0-based)
! # And use it to index into the list we created
 # (after which the result is output implicitly)
 
 

Husk , (削除) 18 (削除ここまで) 16 bytes

!→0+→G(mΣ∂Ṫ*)2∞0

First Husk answer. This took so much longer to complete than I thought it would. I'm glad there is a tutorial with good explanation of how the input-order and super-numbers work, otherwise I had to give up. I never programmed in Haskell, and maybe I'm just too used to the left-to-right stack-based 05AB1E, but Husk isn't exactly straight-forward due to its strong-typed nature and right-to-left execution (including input-arguments) imho..
But, it works, which is what counts in the end. :)

First input-argument is a list of lists of coefficients where index encodes exponent, like the third input example in the challenge description. Second argument is the coefficient integer \$k\$.

Try it online.

Explanation:

 2 # Use the first argument,
 G( ) # and left-reduce it by:
 Ṫ # Apply double-vectorized:
 * # Multiply
 # (This basically results in the multiplication table of the lists)
 ∂ # Take the diagonals of this multiplication table
 m # Map over these diagonal-lists:
 Σ # And sum each together
 → # Only leave the last list after the reduce-by
 ∞0 # Push an infinite list of 0s: [0,0,0,...]
 + # Merge the two lists together
 0 # Push the second argument `k`
 → # Increase it by 1 (since Husk uses 1-based indexing instead of 0-based)
! # And use it to index into the list we created
 # (after which the result is output implicitly)
 
 
deleted 3 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#Husk, (削除) 18 (削除ここまで) 16 bytes

!→0+→G(mΣ∂Ṫ*)2*0;02∞0

First Husk answer. This took so much longer to complete than I thought it would. I'm glad there is a tutorial with good explanation of how the input-order and super-numbers work, otherwise I had to give up. I never programmed in Haskell, and maybe I'm just too used to the left-to-right stack-based 05AB1E, but Husk isn't exactly straight-forward due to its strong-typed nature and right-to-left execution (including input-arguments) imho..
But, it works, which is what counts in the end. :)

AFirst input-argument is a list of lists of coefficients where index encodes exponent, like the third input example in the challenge description. Second argument is the coefficient integer \$k\$.

Try it online. Try it online.

Explanation:

 2 # Use the first argument,
 G( ) # and left-reduce it by:
 Ṫ # Apply double-vectorized:
 * # Multiply
 # (This basically results in the multiplication table of the lists)
 ∂ # Take the diagonals of this multiplication table
 m # Map over these diagonal-lists:
 Σ # And sum each together
 → # Only leave the last list after the reduce-by
 ∞0 # Push an infinite list of 0s: [0,0,0,...]
 + # Merge the two lists together
 0 # Push the second argument `k`
 → # Increase it by 1 (since Husk uses 1-based indexing instead of 0-based)
! # And use it to index into the list we created
 # (after which the result is output implicitly)
 
 

#Husk, (削除) 18 (削除ここまで) 16 bytes

!→0+→G(mΣ∂Ṫ*)2*0;0

First Husk answer. This took so much longer to complete than I thought it would. I'm glad there is a tutorial with good explanation of how the input-order and super-numbers work, otherwise I had to give up. I never programmed in Haskell, and maybe I'm just too used to the left-to-right stack-based 05AB1E, but Husk isn't exactly straight-forward due to its strong-typed nature and right-to-left execution (including input-arguments) imho..
But, it works, which is what counts in the end. :)

A list of lists of coefficients where index encodes exponent, like the third input example in the challenge description.

Try it online.

Explanation:

 2 # Use the first argument,
 G( ) # and left-reduce it by:
 Ṫ # Apply double-vectorized:
 * # Multiply
 # (This basically results in the multiplication table of the lists)
 ∂ # Take the diagonals of this multiplication table
 m # Map over these diagonal-lists:
 Σ # And sum each together
 → # Only leave the last list after the reduce-by
 ∞0 # Push an infinite list of 0s: [0,0,0,...]
 + # Merge the two lists together
 0 # Push the second argument `k`
 → # Increase it by 1 (since Husk uses 1-based indexing instead of 0-based)
! # And use it to index into the list we created
 # (after which the result is output implicitly)
 
 

#Husk, (削除) 18 (削除ここまで) 16 bytes

!→0+→G(mΣ∂Ṫ*)2∞0

First Husk answer. This took so much longer to complete than I thought it would. I'm glad there is a tutorial with good explanation of how the input-order and super-numbers work, otherwise I had to give up. I never programmed in Haskell, and maybe I'm just too used to the left-to-right stack-based 05AB1E, but Husk isn't exactly straight-forward due to its strong-typed nature and right-to-left execution (including input-arguments) imho..
But, it works, which is what counts in the end. :)

First input-argument is a list of lists of coefficients where index encodes exponent, like the third input example in the challenge description. Second argument is the coefficient integer \$k\$.

Try it online.

Explanation:

 2 # Use the first argument,
 G( ) # and left-reduce it by:
 Ṫ # Apply double-vectorized:
 * # Multiply
 # (This basically results in the multiplication table of the lists)
 ∂ # Take the diagonals of this multiplication table
 m # Map over these diagonal-lists:
 Σ # And sum each together
 → # Only leave the last list after the reduce-by
 ∞0 # Push an infinite list of 0s: [0,0,0,...]
 + # Merge the two lists together
 0 # Push the second argument `k`
 → # Increase it by 1 (since Husk uses 1-based indexing instead of 0-based)
! # And use it to index into the list we created
 # (after which the result is output implicitly)
 
 
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#Husk, (削除) 18 (削除ここまで) 16 bytes

!→0+→G(mΣ∂Ṫ*)2*0;0

First Husk answer. This took so much longer to complete than I thought it would. I'm glad there is a tutorial with good explanation of how the input-order and super-numbers work, otherwise I had to give up. I never programmed in Haskell, and maybe I'm just too used to the left-to-right stack-based 05AB1E, but Husk isn't exactly straight-forward due to its strong-typed nature and right-to-left execution (including input-arguments) imho..
But, it works, which is what counts in the end. :)

A list of lists of coefficients where index encodes exponent, like the third input example in the challenge description.

Try it online.

Explanation:

 2 # Use the first argument,
 G( ) # and left-reduce it by:
 Ṫ # Apply double-vectorized:
 * # Multiply
 # (This basically results in the multiplication table of the lists)
 ∂ # Take the diagonals of this multiplication table
 m # Map over these diagonal-lists:
 Σ # And sum each together
 → # Only leave the last list after the reduce-by
 ∞0 # Push an infinite list of 0s: [0,0,0,...]
 + # Merge the two lists together
 0 # Push the second argument `k`
 → # Increase it by 1 (since Husk uses 1-based indexing instead of 0-based)
! # And use it to index into the list we created
 # (after which the result is output implicitly)
 
 

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