|
Post by bluatigro on Jan 15, 2019 12:33:53 GMT
you have a stack of rails left and right 30degrees create al tracks that are a circuit
'' bluatigro 16 jan 2019 '' railway circuit [ 2 rails ] global pi pi = atn( 1 ) * 4
call zoek 12
end sub zoek length tel = 0 for i = 0 to 2 ^ length - 1 track$ = bin$( i , length ) if istrack( track$ ) then print track$ tel = tel + 1 end if next i print tel ; " tracks of " ; length ; " coners fount ." end sub function istrack( track$ ) x = 0 y = 0 dx = 1 dy = 0 for i = 1 to len( track$ ) if mid$( track$ , i , 1 ) = "+" then call rotate dx , dy , 30 else call rotate dx , dy , -30 end if x = x + dx y = y + dy next i istrack = near( 0 , x , 1e-9 ) and near( 0 , y , 1e-9 ) end function function bin$( no , length ) for i = 0 to length - 1 if no and 2 ^ i then uit$ = uit$ + "+" else uit$ = uit$ + "-" end if next i bin$ = uit$ end function sub rotate byref k , byref l , deg s = sin( deg * pi / 180 ) c = cos( deg * pi / 180 ) hk = k * c - l * s hl = k * s + l * c k = hk l = hl end sub function near( a , b , c ) near = abs( a - b ) < c end function
|
|
|
Post by bluatigro on Jan 15, 2019 13:17:10 GMT
update : my gonio was not good
[/p][p]'' bluatigro 16 jan 2019 '' railway circuit [ 2 rails ] global pi pi = atn( 1 ) * 4
call zoek 12
end sub zoek length tel = 0 for i = 0 to 2 ^ length - 1 track$ = bin$( i , length ) if istrack( track$ ) then print track$ tel = tel + 1 end if next i print tel ; " tracks of " ; length ; " coners fount ." end sub function istrack( track$ ) x = 0 y = 0 dxl = 1 - cos( rad( 30 ) ) dyl = sin( rad( 30 ) ) dxr = 1 - cos( rad( 30 ) ) dyr = sin( rad( 30 ) ) for i = 1 to len( track$ ) if mid$( track$ , i , 1 ) = "+" then x = x + dxl y = y + dyl call rotate dxl , dyl , 30 call rotate dxr , dyr , 30 else x = x + dxr y = y + dyr call rotate dxl , dyl , -30 call rotate dxr , dyr , -30 end if next i istrack = near( 0 , x , 1e-9 ) and near( 0 , y , 1e-9 ) end function function rad( x ) rad = x * pi / 180 end function function bin$( no , length ) for i = 0 to length - 1 if no and 2 ^ i then uit$ = uit$ + "+" else uit$ = uit$ + "-" end if next i bin$ = uit$ end function sub rotate byref k , byref l , deg s = sin( deg * pi / 180 ) c = cos( deg * pi / 180 ) hk = k * c - l * s hl = k * s + l * c k = hk l = hl end sub function near( a , b , c ) near = abs( a - b ) < c end function [/p][p]
|
|
|
Post by B+ on Jan 15, 2019 21:50:19 GMT
Is there a link available that explains this problem in English? or is anyone familiar with this problem that could help explain?
|
|
|
Post by cundo on Jan 15, 2019 23:15:27 GMT
|
|
|
Post by B+ on Jan 15, 2019 23:29:52 GMT
Thanks Yes! I think that's it!
|
|
|
Post by bluatigro on Jan 16, 2019 9:45:41 GMT
@ cundo & B+ : whit [RC] i ment indeed the rosetta code site this was so on the old LB forum
|
|