Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Example for https://puzzling.stackexchange.com/questions/126002/the-alien-snails-experiment
- from math import *
- def get_log10_str( log10_val ):
- intpow = floor(log10_val)
- frac = 10**( log10_val - intpow )
- while frac < 1.0:
- frac *= 10
- intpow -= 1
- return f"{frac:.4}∙10^{intpow}"
- anne_pos0 = ( 0, 0 )
- bill_pos0 = ( 1e12*cos(radians(-24)), 1e12*sin(radians(-24)) )
- anne_dir = ( 1, 0 )
- bill_dir = ( cos(radians(71)), sin(radians(71)) )
- print("Starting configuration:")
- print(f" Anne pos=⟨ {anne_pos0[0]}, {anne_pos0[1]} ⟩")
- print(f" dir=⟨ {anne_dir[0]}, {anne_dir[1]} ⟩")
- print(f" Bill pos=⟨ {bill_pos0[0]:.3e}, {bill_pos0[1]:.3e} ⟩")
- print(f" dir=⟨ {bill_dir[0]:.4}, {bill_dir[1]:.4} ⟩")
- print(f" Speed (μm/s): {1e6*1/86400:.4}")
- print()
- #Speed described by 1/t, where t the remaining time, so displacement by
- # \int_x^86400 dt/t = ln(86400)-ln(x) = ln(86400/x)
- #For higher precision, if x=c*10^p, then
- # = ln(86400) - ln(c) + p*ln(10)
- # = ln(86400/c) + p*ln(10)
- print("Displacement with time remaining:")
- print(f" t= 60: {log(86400.0/ 60.0):.4}")
- print(f" t= 10: {log(86400.0/ 10.0):.4}")
- print(f" t= 1: {log(86400.0/ 1.0):.4}")
- print(f" t= 1e-3: {log(86400.0/ 1.0e-3):.4}")
- print(f" t= 1e-100: {log(86400.0/1.0e-100):.4}")
- print(f" t=1e-100000: {round( log(86400.0/1.0)+100000*log(10) )}")
- print()
- #Bill crosses x-axis. The elapsed time is
- # \int_x^86400 dt/t = ln(86400)-ln(x) = `param`
- param = -bill_pos0[1] / bill_dir[1]
- cross_pos = ( bill_pos0[0]+param*bill_dir[0], bill_pos0[1]+param*bill_dir[1] )
- ln_tc = log(86400) - param
- log10_tc = log10(e) * ln_tc
- print("Bill crosses the x-axis at:")
- print(f" Location : ⟨ {cross_pos[0]:.3e}, {cross_pos[1]} ⟩")
- print(f" Remaining time: {get_log10_str(log10_tc)}")
- print()
- #Anne finds trail on x-axis and changes speed to 2/t. This happens when Anne's displacement is the
- #crossing point, so:
- # (cross_pos[0]) = \int_x^86400 dt/t => ln(x) = ln(86400) - (cross_pos[0])
- ln_t1 = log(86400) - cross_pos[0]
- log_t1 = log10(e) * ln_t1
- dist = cross_pos[0]
- anne_pos1 = ( dist, 0 )
- bill_pos1 = ( bill_pos0[0]+dist*bill_dir[0], bill_pos0[1]+dist*bill_dir[1] )
- log_v = log10(2) - ln_t1*log10(e)
- separation = hypot( anne_pos1[0]-bill_pos1[0], anne_pos1[1]-bill_pos1[1] )
- print("Anne finds the trail:")
- print(f" Anne's position : ⟨ {anne_pos1[0]:.3e}, {anne_pos1[1]} ⟩")
- print(f" Bill's position : ⟨ {bill_pos1[0]:.3e}, {bill_pos1[1]:.3e} ⟩")
- print(f" Separation : {separation:.3e}")
- print(f" Remaining time : {get_log10_str(log_t1)}")
- print(f" Anne's new speed: {get_log10_str(log_v)}") #the effect of the 2 is not visible at this scale
- print()
- #The relative speed of Anne and Bill is -1/t. They intersect when that speed removes the distance
- #between them. That is:
- # \int_x^exp(`ln_t`) -dt/t = -`separation`
- ln_t2 = ln_t1 - separation
- log_t2 = log10(e) * ln_t2
- log_relvel_by_c = log10(e)*( separation - ln_t1 - log(299792458) )
- param = log(86400) - log_t2
- pos2 = ( bill_pos0[0]+param*bill_dir[0], bill_pos0[1]+param*bill_dir[1] )
- print("Meetup:")
- print(f" Position : ⟨ {pos2[0]:.3e}, {pos2[1]:.3e} ⟩")
- print(f" Remaining time: {get_log10_str(log_t2)}")
- print(f" Relative speed: {get_log10_str(log_relvel_by_c)} ⨯ c")
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement