Skip to content

Instantly share code, notes, and snippets.

@FeepingCreature
Created June 26, 2024 00:35
Show Gist options
  • Save FeepingCreature/9923065a35129624b27c8b033dca0575 to your computer and use it in GitHub Desktop.
Save FeepingCreature/9923065a35129624b27c8b033dca0575 to your computer and use it in GitHub Desktop.
import math
def apply_strength(strength: float, steps: int, min_steps: int) -> tuple[int, int]:
start_at_step = round(steps * (1 - strength))
if min_steps and steps - start_at_step < min_steps:
steps = round(min_steps / strength)
start_at_step = steps - min_steps
return steps, start_at_step
def adjust_during_widget_assignment(strength):
return round(strength * 100) / 100
def check_reconstructions(strength_step=0.01):
violations = 0
for strength in [i * strength_step for i in range(1, int(1 / strength_step) + 1)]:
for min_steps in range(3, 5):
for steps in range(min_steps, 100):
# First reconstruction
steps_1, start_at_step_1 = apply_strength(strength, steps, min_steps)
reconstruct_1 = (steps_1 - start_at_step_1) / steps_1
reconstruct_1 = adjust_during_widget_assignment(reconstruct_1)
# Second reconstruction
steps_2, start_at_step_2 = apply_strength(reconstruct_1, steps, min_steps)
reconstruct_2 = (steps_2 - start_at_step_2) / steps_2
reconstruct_2 = adjust_during_widget_assignment(reconstruct_2)
# Check if reconstructions differ
if reconstruct_1 != reconstruct_2:
print(f"Warning: Reconstructions differ for strength={strength:.2f}, steps={steps}, min_steps={min_steps}")
print(f" First reconstruction: {reconstruct_1:.2f} {start_at_step_1, steps_1}")
print(f" Second reconstruction: {reconstruct_2:.2f} {start_at_step_2, steps_2}")
print(f" Difference: {abs(reconstruct_1 - reconstruct_2):.2f}")
print()
violations += 1
print(f"{violations} violations found.")
# Run the check
check_reconstructions()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment