ABC problem: Difference between revisions
Content added Content deleted
(Updated to conform with FB 7.0.23 and newer) |
|||
Line 4,752: | Line 4,752: | ||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
Here are two FutureBasic solutions for the "ABC Problem" task. The first is a straightforward function based on CFStrings, giving the standard YES or NO response. |
|||
The second is based on Pascal Strings, and offers a unique graphic presentation of the results, all in 18 lines of code. It accepts a word list delimited by spaces, commas, and/or semicolons. |
|||
'''FIRST SOLUTION:''' |
|||
Requires FB 7.0.23 or later |
Requires FB 7.0.23 or later |
||
<syntaxhighlight lang="futurebasic"> |
<syntaxhighlight lang="futurebasic"> |
||
include "NSLog.incl" |
|||
local fn CanBlocksSpell( w as CFStringRef ) as CFStringRef |
local fn CanBlocksSpell( w as CFStringRef ) as CFStringRef |
||
NSUInteger i, j |
NSUInteger i, j |
||
Line 4,780: | Line 4,788: | ||
NSLog( @"%@", fn WindowPrintViewString( 1 ) ) |
NSLog( @"%@", fn WindowPrintViewString( 1 ) ) |
||
HandleEvents |
HandleEvents |
||
Line 4,797: | Line 4,804: | ||
Can blocks spell aUtO : YES |
Can blocks spell aUtO : YES |
||
</pre> |
</pre> |
||
'''SECOND SOLUTION:''' |
|||
<syntaxhighlight lang="futurebasic"> |
|||
local fn blocks( wordList as str255 ) |
|||
sint16 found, r, x = 3, y = -9 : str63 ch, blocks : ch = " " : blocks = " " |
|||
for r = 1 to len$( wordList ) +1 |
|||
found = instr$( 1, blocks, ch ) |
|||
select found |
|||
case > 3: mid$( blocks, found and -2, 2 ) = "__" : text , , fn Colorblue |
|||
rect fill ( x, y + 5.5, 15, 15 ), fn ColorWithRGB( .98, .85, .52, .75 ) |
|||
case 0: text , , fn ColorWithRGB( 0, 0, .4, .3 ) |
|||
case < 4: blocks=" ,;BOXKDQCPNAGTRETGQDFSJWHUVIANOBERFSLYPCZM": x=3: y+=26: ch="" |
|||
end select |
|||
text @"Courier New Bold", 16 : print %( x + 2.5, y ) ch : x += 17 |
|||
ch = ucase$( mid$( wordList, r, 1 ) ) |
|||
next |
|||
end fn |
|||
window 1, @"ABC problem in FutureBasic", ( 0, 0, 300, 300 ) |
|||
fn blocks( "a baRk booK;treat;COMMON;squad;Confused;comparable,incomparable,nondeductibles" ) |
|||
handleevents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
[[File:FB output for ABC problem.png]] |
|||
=={{header|Gambas}}== |
=={{header|Gambas}}== |