Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
53
Task/24-game-Solve/FutureBasic/24-game-solve.basic
Normal file
53
Task/24-game-Solve/FutureBasic/24-game-solve.basic
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
begin globals
|
||||
Short k
|
||||
end globals
|
||||
|
||||
void local fn eval( t as CFStringRef )
|
||||
CFMutableStringRef s = fn MutableStringNew
|
||||
ExpressionRef x = fn ExpressionWithFormat( t )
|
||||
CFRange r = fn CFRangeMake(0, fn StringLength( t ) )
|
||||
CFNumberRef n = fn ExpressionValueWithObject( x, Null, Null )
|
||||
Float f = dblval( n )
|
||||
if f = 24 // found, so clean up
|
||||
MutableStringSetString( s, t ) // duplicate string and pretend it was integers all along
|
||||
MutableStringReplaceOccurrencesOfString( s, @".000000", @"", Null, r )
|
||||
print s; @" = 24" : k ++
|
||||
end if
|
||||
end fn
|
||||
|
||||
|
||||
clear local fn work( t as CFStringRef )
|
||||
Short a, b, c, d, e, f, g
|
||||
CGFloat n(3)
|
||||
CFStringRef s, os = @"*/+-", o(3)
|
||||
print t, : k = 0
|
||||
// Put digits (as floats) and operators (as strings) in arrays
|
||||
for a = 0 to 3 : s = mid( t, a, 1 ) : n(a) = fn StringFloatValue( s ) : o(a) = mid( os, a, 1 ) : next
|
||||
// Permutions for the digits ...
|
||||
for d = 0 to 3 : for e = 0 to 3 : for f = 0 to 3 : for g = 0 to 3
|
||||
if d != e and d != f and d != g and e != f and e != g and f != g // ... without duplications
|
||||
// Combinations for the operators (3 from 4, with replacement)
|
||||
for a = 0 to 3 : for b = 0 to 3 : for c = 0 to 3
|
||||
fn eval( fn StringWithFormat( @"%f %@ %f %@ %f %@ %f", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"%f %@ ( %f %@ %f ) %@ %f", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"%f %@ %f %@ ( %f %@ %f )", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"%f %@ ( %f %@ %f %@ %f )", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"( %f %@ %f ) %@ %f %@ %f", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"( %f %@ %f %@ %f ) %@ %f", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"%f %@ ( %f %@ ( %f %@ %f ) )", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"( %f %@ %f ) %@ ( %f %@ %f )", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"( %f %@ ( %f %@ %f )) %@ %f", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"( ( %f %@ %f ) %@ %f ) %@ %f", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
fn eval( fn StringWithFormat( @"%f %@ ( ( %f %@ %f ) %@ %f )", n(d), o(a), n(e), o(b), n(f), o(c), n(g) ) ) : if k > 0 then exit fn
|
||||
next : next : next
|
||||
end if
|
||||
next : next : next : next
|
||||
end fn
|
||||
|
||||
|
||||
window 1, @"24 Game", ( 0, 0, 250, 250 )
|
||||
fn work(@"3388")
|
||||
fn work(@"1346")
|
||||
fn work(@"8752")
|
||||
|
||||
handleevents
|
||||
Loading…
Add table
Add a link
Reference in a new issue