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

deleted 38 characters in body
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100

Haskell, 82(削除) 82 (削除ここまで) 81 bytes

q=map$read.pure
a#b=or$anyf a=any(>9)<$>scanr.concat.scanr((.(0:)).zipWith(+).(<$>q a).(*))(0<$a)(.q b)

The numbers a taken as strings. Returns False if the numbers are easy to multiply and True otherwise.

Try it online! Try it online!

I think it's different enough from @Laikoni's answer. How it works:

q -- helper function to turn a string into a list of digits
a#b=f a = -- main function, parametersfirst 'a'number andis 'b'parameter 'a' 
 scanr ( .q b) -- fold the following function from the right (and collect
 -- the intermediate results in a list) into the list of
 -- digits of 'b'the second number
 0<$a -- starting with as many 0s as there are digits in 'a'
 -- the function is, translated to non-point free:
 \n c->zipWith(+)((*n)<$>q a)0ドル:c 
 -- 'n': next digit of 'b'; 'c': value so far
 (*n)<$>a -- multiplay each digit in 'a' with 'n'
 0:c -- prepend 'a'a 0 to 'c'
 zipWith(+) -- add both lists element wise
 -- (this shifts out the last digit of 'c' in every step)
 any(>9)<$>  -- check for each lists collected by scanr if any
 concat -- numberflatten isthe >9
collected orlists into a single list
 any(>9) -- check if any of the above valuesnumber is True  >9

Haskell, 82 bytes

q=map$read.pure
a#b=or$any(>9)<$>scanr((.(0:)).zipWith(+).(<$>q a).(*))(0<$a)(q b)

The numbers a taken as strings. Returns False if the numbers are easy to multiply and True otherwise.

Try it online!

I think it's different enough from @Laikoni's answer. How it works:

q -- helper function to turn a string into a list of digits
a#b= -- main function, parameters 'a' and 'b'
 scanr (q b) -- fold the following function from the right (and collect
 -- the intermediate results in a list) into the list of
 -- digits of 'b'
 0<$a -- starting with as many 0s as there are digits in 'a'
 -- the function is, translated to non-point free:
 \n c->zipWith(+)((*n)<$>q a)0ドル:c 
 -- 'n': next digit of 'b'; 'c': value so far
 (*n)<$>a -- multiplay each digit in 'a' with 'n'
 0:c -- prepend 'a' 0 to 'c'
 zipWith(+) -- add both lists element wise
 -- (this shifts out the last digit of 'c' in every step)
 any(>9)<$>  -- check for each lists collected by scanr if any
  -- number is >9
 or -- check if any of the above values is True  

Haskell, (削除) 82 (削除ここまで) 81 bytes

q=map$read.pure
f a=any(>9).concat.scanr((.(0:)).zipWith(+).(<$>q a).(*))(0<$a).q

The numbers a taken as strings. Returns False if the numbers are easy to multiply and True otherwise.

Try it online!

I think it's different enough from @Laikoni's answer. How it works:

q -- helper function to turn a string into a list of digits
f a = -- main function, first number is parameter 'a' 
 scanr  .q -- fold the following function from the right (and collect
 -- the intermediate results in a list) into the list of
 -- digits of the second number
 0<$a -- starting with as many 0s as there are digits in 'a'
 -- the function is, translated to non-point free:
 \n c->zipWith(+)((*n)<$>q a)0ドル:c 
 -- 'n': next digit of 'b'; 'c': value so far
 (*n)<$>a -- multiplay each digit in 'a' with 'n'
 0:c -- prepend a 0 to 'c'
 zipWith(+) -- add both lists element wise
 -- (this shifts out the last digit of 'c' in every step)
 concat -- flatten the collected lists into a single list
 any(>9) -- check if any number is >9
Source Link
nimi
  • 36k
  • 4
  • 35
  • 100

Haskell, 82 bytes

q=map$read.pure
a#b=or$any(>9)<$>scanr((.(0:)).zipWith(+).(<$>q a).(*))(0<$a)(q b)

The numbers a taken as strings. Returns False if the numbers are easy to multiply and True otherwise.

Try it online!

I think it's different enough from @Laikoni's answer. How it works:

q -- helper function to turn a string into a list of digits
a#b= -- main function, parameters 'a' and 'b'
 scanr (q b) -- fold the following function from the right (and collect
 -- the intermediate results in a list) into the list of
 -- digits of 'b'
 0<$a -- starting with as many 0s as there are digits in 'a'
 -- the function is, translated to non-point free:
 \n c->zipWith(+)((*n)<$>q a)0ドル:c 
 -- 'n': next digit of 'b'; 'c': value so far
 (*n)<$>a -- multiplay each digit in 'a' with 'n'
 0:c -- prepend 'a' 0 to 'c'
 zipWith(+) -- add both lists element wise
 -- (this shifts out the last digit of 'c' in every step)
 any(>9)<$> -- check for each lists collected by scanr if any
 -- number is >9
 or -- check if any of the above values is True 

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