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

#05AB1E , (削除) 26 (削除ここまで) 22 bytes

05AB1E , (削除) 26 (削除ここまで) 22 bytes

#05AB1E , (削除) 26 (削除ここまで) 22 bytes

05AB1E , (削除) 26 (削除ここまで) 22 bytes

added 717 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#05AB1E, 26 (削除) 26 (削除ここまで) 22 bytes

Z©bgL®gãUεVXεYSymεVтLIàgãεYSym}OsN>èåOIyKå}P ̃P

Can definitely be golfedTry it online or verify most test cases in the range [1,999] .

Similar as my old answer below, except that the [1,n] list is hardcoded to [1,100], and it creates the cartesian list twice, once for each input-mapping, which is the main bottleneck in terms of performance.


Old 26 bytes answer that's better for performance:

Z©bgL®gãUεVXεYSym}OsN>èå}P

In this version I traded in some bytes to make the performance a lot better so it can run [1,1000] with ease. Test cases containing numbers in the range [1,9999] are done in about a second on TIO. Test cases in the range [10000,99999] in about 10-15 seconds on TIO. Above that it will timeout.

Z # Push the max of the (implicit) input-list (without popping)
 # i.e. [526,853] → 853
 © # Store it in the register (without popping)
 b # Convert to binary
 # i.e. 853 → 1101010101
 g # Take its length
 # i.e. 1101010101 → 10
 L # Pop and push a list [1, n]
 # i.e. 10 → [1,2,3,4,5,6,7,8,9,10]
 ® # Push the max from the register
 g # Take its length
 # i.e. 853 → 3
 ã # Cartesian product the list that many times
 # i.e. [1,2,3,4,5,6,7,8,9,10] and 3
 # → [[1,1,1],[1,1,2],[1,1,3],...,[10,10,8],[10,10,9],[10,10,10]]
 U # Pop and store it in variable `X`
ε } # Map both values of the input list:
 V # Store the current value in variable `Y`
 Xε } # Map `y` over the numbers of variable `X`
 Y # Push variable `Y`
 S # Convert it to a list of digits
 # i.e. 526 → [5,2,6]
 ym # Take each digit to the power of the current cartesian product sublist
 # i.e. [5,2,6] and [3,9,3] → [125,512,216]
 O # Take the sum of each inner list
 # i.e. [[5,2,6],[5,2,36],[5,2,216],...,[125,512,216],...]
 # → [13,43,223,...,853,...]
 s # Swap so to takepush the (implicit) input
 N> # Push the index + 1
 # i.e. 0 → 1
 è # Index into the input-list (with automatic wraparound)
 # i.e. [526,853] and 1 → 853
 å # Check if it's in the list of sums
 # i.e. [13,43,223,...,853,...] and 853 → 1
 P # Check if it's truthy for both both (and output implicitly)
 # i.e. [1,1] → 1

#05AB1E, 26 bytes

Z©bgL®gãUεVXεYSym}OsN>èå}P

Can definitely be golfed. I traded in some bytes to make the performance a lot better so it can run [1,1000] with ease. Test cases containing numbers in the range [1,9999] are done in about a second on TIO. Test cases in the range [10000,99999] in about 10-15 seconds on TIO. Above that it will timeout.

Z # Push the max of the (implicit) input-list (without popping)
 # i.e. [526,853] → 853
 © # Store it in the register (without popping)
 b # Convert to binary
 # i.e. 853 → 1101010101
 g # Take its length
 # i.e. 1101010101 → 10
 L # Pop and push a list [1, n]
 # i.e. 10 → [1,2,3,4,5,6,7,8,9,10]
 ® # Push the max from the register
 g # Take its length
 # i.e. 853 → 3
 ã # Cartesian product the list that many times
 # i.e. [1,2,3,4,5,6,7,8,9,10] and 3
 # → [[1,1,1],[1,1,2],[1,1,3],...,[10,10,8],[10,10,9],[10,10,10]]
 U # Pop and store it in variable `X`
ε } # Map both values of the input list:
 V # Store the current value in variable `Y`
 Xε } # Map `y` over the numbers of variable `X`
 Y # Push variable `Y`
 S # Convert it to a list of digits
 # i.e. 526 → [5,2,6]
 ym # Take each digit to the power of the current cartesian product sublist
 # i.e. [5,2,6] and [3,9,3] → [125,512,216]
 O # Take the of each inner list
 # i.e. [[5,2,6],[5,2,36],[5,2,216],...,[125,512,216],...]
 # → [13,43,223,...,853,...]
 s # Swap so to take the (implicit) input
 N> # Push the index + 1
 # i.e. 0 → 1
 è # Index into the input-list (with automatic wraparound)
 # i.e. [526,853] and 1 → 853
 å # Check if it's in the list of sums
 # i.e. [13,43,223,...,853,...] and 853 → 1
 P # Check if it's truthy for both both (and output implicitly)
 # i.e. [1,1] → 1

#05AB1E, (削除) 26 (削除ここまで) 22 bytes

εVтLIàgãεYSym}OIyKå} ̃P

Try it online or verify most test cases in the range [1,999] .

Similar as my old answer below, except that the [1,n] list is hardcoded to [1,100], and it creates the cartesian list twice, once for each input-mapping, which is the main bottleneck in terms of performance.


Old 26 bytes answer that's better for performance:

Z©bgL®gãUεVXεYSym}OsN>èå}P

In this version I traded in some bytes to make the performance a lot better so it can run [1,1000] with ease. Test cases containing numbers in the range [1,9999] are done in about a second on TIO. Test cases in the range [10000,99999] in about 10-15 seconds on TIO. Above that it will timeout.

Z # Push the max of the (implicit) input-list (without popping)
 # i.e. [526,853] → 853
 © # Store it in the register (without popping)
 b # Convert to binary
 # i.e. 853 → 1101010101
 g # Take its length
 # i.e. 1101010101 → 10
 L # Pop and push a list [1, n]
 # i.e. 10 → [1,2,3,4,5,6,7,8,9,10]
 ® # Push the max from the register
 g # Take its length
 # i.e. 853 → 3
 ã # Cartesian product the list that many times
 # i.e. [1,2,3,4,5,6,7,8,9,10] and 3
 # → [[1,1,1],[1,1,2],[1,1,3],...,[10,10,8],[10,10,9],[10,10,10]]
 U # Pop and store it in variable `X`
ε } # Map both values of the input list:
 V # Store the current value in variable `Y`
 Xε } # Map `y` over the numbers of variable `X`
 Y # Push variable `Y`
 S # Convert it to a list of digits
 # i.e. 526 → [5,2,6]
 ym # Take each digit to the power of the current cartesian product sublist
 # i.e. [5,2,6] and [3,9,3] → [125,512,216]
 O # Take the sum of each inner list
 # i.e. [[5,2,6],[5,2,36],[5,2,216],...,[125,512,216],...]
 # → [13,43,223,...,853,...]
 s # Swap to push the (implicit) input
 N> # Push the index + 1
 # i.e. 0 → 1
 è # Index into the input-list (with automatic wraparound)
 # i.e. [526,853] and 1 → 853
 å # Check if it's in the list of sums
 # i.e. [13,43,223,...,853,...] and 853 → 1
 P # Check if it's truthy for both both (and output implicitly)
 # i.e. [1,1] → 1
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#05AB1E, 26 bytes

Z©bgL®gãUεVXεYSym}OsN>èå}P

Takes the input as a list (i.e. [526,853]).

Can definitely be golfed. I traded in some bytes to make the performance a lot better so it can run [1,1000] with ease. Test cases containing numbers in the range [1,9999] are done in about a second on TIO. Test cases in the range [10000,99999] in about 10-15 seconds on TIO. Above that it will timeout.

Try it online or verify all test cases with numbers in the range [1,9999].

Explanation:

Z # Push the max of the (implicit) input-list (without popping)
 # i.e. [526,853] → 853
 © # Store it in the register (without popping)
 b # Convert to binary
 # i.e. 853 → 1101010101
 g # Take its length
 # i.e. 1101010101 → 10
 L # Pop and push a list [1, n]
 # i.e. 10 → [1,2,3,4,5,6,7,8,9,10]
 ® # Push the max from the register
 g # Take its length
 # i.e. 853 → 3
 ã # Cartesian product the list that many times
 # i.e. [1,2,3,4,5,6,7,8,9,10] and 3
 # → [[1,1,1],[1,1,2],[1,1,3],...,[10,10,8],[10,10,9],[10,10,10]]
 U # Pop and store it in variable `X`
ε } # Map both values of the input list:
 V # Store the current value in variable `Y`
 Xε } # Map `y` over the numbers of variable `X`
 Y # Push variable `Y`
 S # Convert it to a list of digits
 # i.e. 526 → [5,2,6]
 ym # Take each digit to the power of the current cartesian product sublist
 # i.e. [5,2,6] and [3,9,3] → [125,512,216]
 O # Take the of each inner list
 # i.e. [[5,2,6],[5,2,36],[5,2,216],...,[125,512,216],...]
 # → [13,43,223,...,853,...]
 s # Swap so to take the (implicit) input
 N> # Push the index + 1
 # i.e. 0 → 1
 è # Index into the input-list (with automatic wraparound)
 # i.e. [526,853] and 1 → 853
 å # Check if it's in the list of sums
 # i.e. [13,43,223,...,853,...] and 853 → 1
 P # Check if it's truthy for both both (and output implicitly)
 # i.e. [1,1] → 1

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