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 1505 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, (削除) 12 (削除ここまで) 10 bytes

ẋ2~ṣ0‘ḌṂṙ@

Try it online! or verify all test cases.

Background

Say the input is 51379#97.

By repeating the string twice (51379#9751379#97), we can make sure that it will contain a contiguous representation of the number.

Next, we apply bitwise NOT to all characters. This attempts to cast to int, so '1' gets evaluated to 1, then mapped to ~1 = -2. On failure (#), it returns 0.

For our example, this gives

[-6, -2, -4, -8, -10, 0, -10, -8, -6, -2, -4, -8, -10, 0, -10, -8]

Next, we split at zeroes to separate the part that encodes the number from the rest.

[[-6, -2, -4, -8, -10], [-10, -8, -6, -2, -4, -8, -10], [-10, -8]]

Bitwise NOT maps n to -n - 1, so we increment each to obtain -n.

[[-5, -1, -3, -7, -9], [-9, -7, -5, -1, -3, -7, -9], [-9, -7]]

Next, we convert each list from base 10 to integer.

[-51379, -9751379, -97]

The lowest number is the negative of the one we're searching for. Since Jelly list rotation atom rotates to the left, this avoid multiplying by -1 to rotate to the right.

How it works

ẋ2~ṣ0‘ḌṂṙ@ Main link. Input: S (string)
ẋ2 Repeat the string twice.
 ~ Apply bitwise NOT to all characters.
 This maps 'n' to ~n = -(n+1) and '# to 0.
 ṣ0 Split at occurrences of zeroes.
 ‘ Increment all single-digit numbers.
 Ḍ Convert each list from base 10 to integer.
 Ṃ Take the minimum.
 ṙ@ Rotate S that many places to the left.

Jelly, (削除) 12 (削除ここまで) 10 bytes

ẋ2~ṣ0‘ḌṂṙ@

Try it online! or verify all test cases.

Jelly, (削除) 12 (削除ここまで) 10 bytes

ẋ2~ṣ0‘ḌṂṙ@

Try it online! or verify all test cases.

Background

Say the input is 51379#97.

By repeating the string twice (51379#9751379#97), we can make sure that it will contain a contiguous representation of the number.

Next, we apply bitwise NOT to all characters. This attempts to cast to int, so '1' gets evaluated to 1, then mapped to ~1 = -2. On failure (#), it returns 0.

For our example, this gives

[-6, -2, -4, -8, -10, 0, -10, -8, -6, -2, -4, -8, -10, 0, -10, -8]

Next, we split at zeroes to separate the part that encodes the number from the rest.

[[-6, -2, -4, -8, -10], [-10, -8, -6, -2, -4, -8, -10], [-10, -8]]

Bitwise NOT maps n to -n - 1, so we increment each to obtain -n.

[[-5, -1, -3, -7, -9], [-9, -7, -5, -1, -3, -7, -9], [-9, -7]]

Next, we convert each list from base 10 to integer.

[-51379, -9751379, -97]

The lowest number is the negative of the one we're searching for. Since Jelly list rotation atom rotates to the left, this avoid multiplying by -1 to rotate to the right.

How it works

ẋ2~ṣ0‘ḌṂṙ@ Main link. Input: S (string)
ẋ2 Repeat the string twice.
 ~ Apply bitwise NOT to all characters.
 This maps 'n' to ~n = -(n+1) and '# to 0.
 ṣ0 Split at occurrences of zeroes.
 ‘ Increment all single-digit numbers.
 Ḍ Convert each list from base 10 to integer.
 Ṃ Take the minimum.
 ṙ@ Rotate S that many places to the left.
added 10 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 12(削除) 12 (削除ここまで) 10 bytes

ṣ"#ṙ1|0FḌNṙ@ẋ2~ṣ0‘ḌṂṙ@

Try it online! Try it online! or verify all test cases verify all test cases.

Jelly, 12 bytes

ṣ"#ṙ1|0FḌNṙ@

Try it online! or verify all test cases.

Jelly, (削除) 12 (削除ここまで) 10 bytes

ẋ2~ṣ0‘ḌṂṙ@

Try it online! or verify all test cases.

added 752 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 12 bytes

ṣ"#ṙ1|0FḌNṙ@

Try it online! or verify all test cases .

Jelly, 12 bytes

ṣ"#ṙ1|0FḌNṙ@

Try it online!

Jelly, 12 bytes

ṣ"#ṙ1|0FḌNṙ@

Try it online! or verify all test cases .

Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading

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