Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,86 @@
begin globals
NSInteger gLargest
end globals
gLargest = 0
local fn IsColorful( n as NSInteger, base as NSInteger ) as BOOL
NSUInteger i, j, k, temp = n
// A colorful number cannot be greater than 98765432.
if ( n < 0 || n > 98765432 ) then return NO
if ( n >= 0 && n < 10 ) then return YES
CFMutableArrayRef digits = fn MutableArrayNew
while ( n > 0 )
MutableArrayAddObject( digits, @(n % base) )
n /= base
wend
CFSetRef uniqueDigits = fn SetWithArray( digits )
if ( len(uniqueDigits) < len(digits) || fn SetContainsObject( uniqueDigits, @(0) ) || fn SetContainsObject( uniqueDigits, @(1) ) )
return NO
end if
CFMutableSetRef products = fn MutableSetWithArray( digits )
NSUInteger length = len(digits)
for i = 2 to length
for j = 0 to length - i
NSInteger product = 1
for k = j to ( j + i ) -1
product *= fn NumberIntegerValue( digits[k] )
next
if ( fn SetContainsObject( products, @(product) ) )
return NO
end if
MutableSetAddObject( products, @(product) )
next
next
if ( temp > gLargest ) then gLargest = temp
end fn = YES
void local fn TestColorfuls
NSInteger i, j, k, n, x
printf @"Colorful numbers for 1:25, 26:50, 51:75, and 76:100:"
for i = 1 to 100
if ( fn IsColorful( i, 10 ) )
printf @"%5ld \b", (long)i
end if
if ( i % 25 == 0 )
print
end if
next
print
NSInteger csum = 0
for i = 0 to 7
j = ( i == 0 ) ? 0 : fn pow( 10, i )
k = fn pow( 10, i + 1 ) - 1
n = 0
for x = j to k
if ( fn IsColorful( x, 10 ) )
n++
end if
next
csum += n
if i < 7 then printf @"The count of colorful numbers between %ld and %ld is %ld.", (long)j, (long)k, (long)n
next
printf @"\nThe largest possible colorful number is %ld.", (long)gLargest
printf @"The total number of colorful numbers is %ld.", (long)csum
end fn
window 1, @"Colorful Numbers", ( 0, 0, 800, 300 )
CFTimeInterval t : t = fn CACurrentMediaTime
fn TestColorfuls
print : printf @"Compute time: %.3f seconds",(fn CACurrentMediaTime-t)
HandleEvents