Skip to content

Instantly share code, notes, and snippets.

@Cryolitia
Created March 19, 2025 18:28
Show Gist options
  • Select an option

  • Save Cryolitia/619a561253f3f31493dfb69f5ae41d44 to your computer and use it in GitHub Desktop.

Select an option

Save Cryolitia/619a561253f3f31493dfb69f5ae41d44 to your computer and use it in GitHub Desktop.
#! /usr/bin/python3
resistance = [1,1,1,1.2,1.3,1.5,1.6,1.8,2,2.2,2.4,2.7,3,3.2,3.3,3.6,3.9,4.3,4.7,5.1,5.6,6.2,6.8,7.5,8.2,9.1,10,11,12,13,15,16,18]
target_voltage = 8.4
result = {}
def output_voltage(r1, r2):
return ((r1/r2)+1)*1.222
if __name__ == '__main__':
for r1 in resistance:
for r2 in resistance:
result[(r1, r2)] = output_voltage(r1, r2)
sorted_result = sorted(result.items(), key=lambda x: abs(x[1]-target_voltage))
for i in range(10):
print(sorted_result[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment