mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort * Fixed doctest error due whitespace * reduce loop times for optimization * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -23,39 +23,39 @@ values = {
|
||||
|
||||
def decimal_to_hexadecimal(decimal):
|
||||
"""
|
||||
take integer decimal value, return hexadecimal representation as str beginning
|
||||
with 0x
|
||||
>>> decimal_to_hexadecimal(5)
|
||||
'0x5'
|
||||
>>> decimal_to_hexadecimal(15)
|
||||
'0xf'
|
||||
>>> decimal_to_hexadecimal(37)
|
||||
'0x25'
|
||||
>>> decimal_to_hexadecimal(255)
|
||||
'0xff'
|
||||
>>> decimal_to_hexadecimal(4096)
|
||||
'0x1000'
|
||||
>>> decimal_to_hexadecimal(999098)
|
||||
'0xf3eba'
|
||||
>>> # negatives work too
|
||||
>>> decimal_to_hexadecimal(-256)
|
||||
'-0x100'
|
||||
>>> # floats are acceptable if equivalent to an int
|
||||
>>> decimal_to_hexadecimal(17.0)
|
||||
'0x11'
|
||||
>>> # other floats will error
|
||||
>>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
AssertionError
|
||||
>>> # strings will error as well
|
||||
>>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
AssertionError
|
||||
>>> # results are the same when compared to Python's default hex function
|
||||
>>> decimal_to_hexadecimal(-256) == hex(-256)
|
||||
True
|
||||
take integer decimal value, return hexadecimal representation as str beginning
|
||||
with 0x
|
||||
>>> decimal_to_hexadecimal(5)
|
||||
'0x5'
|
||||
>>> decimal_to_hexadecimal(15)
|
||||
'0xf'
|
||||
>>> decimal_to_hexadecimal(37)
|
||||
'0x25'
|
||||
>>> decimal_to_hexadecimal(255)
|
||||
'0xff'
|
||||
>>> decimal_to_hexadecimal(4096)
|
||||
'0x1000'
|
||||
>>> decimal_to_hexadecimal(999098)
|
||||
'0xf3eba'
|
||||
>>> # negatives work too
|
||||
>>> decimal_to_hexadecimal(-256)
|
||||
'-0x100'
|
||||
>>> # floats are acceptable if equivalent to an int
|
||||
>>> decimal_to_hexadecimal(17.0)
|
||||
'0x11'
|
||||
>>> # other floats will error
|
||||
>>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
AssertionError
|
||||
>>> # strings will error as well
|
||||
>>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
AssertionError
|
||||
>>> # results are the same when compared to Python's default hex function
|
||||
>>> decimal_to_hexadecimal(-256) == hex(-256)
|
||||
True
|
||||
"""
|
||||
assert type(decimal) in (int, float) and decimal == int(decimal)
|
||||
hexadecimal = ""
|
||||
|
Reference in New Issue
Block a user