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.
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(削除) 12 (削除ここまで) 10 bytes
ṣ"#ṙ1|0FḌNṙ@ẋ2~ṣ0‘ḌṂṙ@
Try it online! Try it online! or verify all test cases verify all test cases.