include "NSLog.incl" #plist NSAppTransportSecurity @{NSAllowsArbitraryLoads:YES} void local fn CheckWord( wrd as CFStringRef, txt as CFStringRef, c as ^long, x as ^long ) CFRange range = fn StringRangeOfString( wrd, txt ) while ( range.location != NSNotFound ) if ( range.location > 0 ) select ( fn StringCharacterAtIndex( wrd, range.location-1 ) ) case _"c" *c += 1 case else *x += 1 end select else *x += 1 end if range.location++ range.length = len(wrd) - range.location range = fn StringRangeOfStringWithOptionsInRange( wrd, txt, 0, range ) wend end fn void local fn Doit CFURLRef url = fn URLWithString( @"http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" ) CFStringRef string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL ) CFArrayRef words = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet ) long cei = 0, cie = 0, xei = 0, xie = 0 CFStringRef wrd, result for wrd in words fn CheckWord( wrd, @"ei", @cei, @xei ) fn CheckWord( wrd, @"ie", @cie, @xie ) next NSLog(@"cei: %ld",cei) NSLog(@"cie: %ld",cie) NSLog(@"xei: %ld",xei) NSLog(@"xie: %ld",xie) if 2 * xie <= cie then result = @"not plausible" else result = @"plausible" NSLog( @"\nI before E when not preceded by C: %@.\n¬ There are %ld examples and %ld counter-examples for a ratio of %f.\n", ¬ result, xie, xei, ( ( (float)xie - (float)cie ) / ( (float)xei - (float)cei ) ) ) if 2 * cei <= xei then result = @"not plausible" else result = @"plausible" NSLog( @"E before I when preceded by C: %@.\n¬ There are %ld examples and %ld counter-examples for a ratio of %f.\n", ¬ result, cei, cie, ( (float)cei / (float)cie ) ) end fn fn DoIt HandleEvents