Commander Posted October 15, 2019 Share Posted October 15, 2019 There is a four-digit number ABCD, where A, B, C, D each represents a different digit from 1 to 9. ABCD is divisible by 13, BCDA is divisible by 11, CDAB is divisible by 9, and DABC is divisible by 7. Can you find the original number ABCD ? Link to comment Share on other sites More sharing options...
Ghideon Posted October 15, 2019 Share Posted October 15, 2019 9 hours ago, Commander said: Can you find the original number ABCD ? Spoiler Answer: ABCD=3861 3861/13=297 8613/11=783 6138/9=558 1386/7=198 1 Link to comment Share on other sites More sharing options...
Commander Posted October 16, 2019 Author Share Posted October 16, 2019 16 hours ago, Ghideon said: Ghideon : Absolutely Right ! Well done !! Link to comment Share on other sites More sharing options...
Ghideon Posted October 16, 2019 Share Posted October 16, 2019 1 hour ago, Commander said: Well done !! Thanks! Below is a hint if someone should be interested: Spoiler CDAB is divisible by 9 means that ABCD, BCDA and DABC are also divisible by 9. 13, 11 and 7 are primes so: ABCD is divisible by 13x9, BCDA is divisible by 11x9 and DABC is divisible by 7x9. Link to comment Share on other sites More sharing options...
Sensei Posted October 16, 2019 Share Posted October 16, 2019 On 10/15/2019 at 12:26 PM, Commander said: There is a four-digit number ABCD, where A, B, C, D each represents a different digit from 1 to 9. Since original puzzle has been solved, I have puzzle for you Commander: what four-digit number will be solution, if any digit might be used multiple times. Link to comment Share on other sites More sharing options...
Commander Posted October 16, 2019 Author Share Posted October 16, 2019 (edited) Sensei : only 7722 will make it ! Which is also double of 3861 Edited October 16, 2019 by Commander To add value 1 Link to comment Share on other sites More sharing options...
Sensei Posted October 17, 2019 Share Posted October 17, 2019 (edited) 14 hours ago, Commander said: Sensei : only 7722 will make it ! Which is also double of 3861 Correct answer. Test.zip #include <stdio.h> int get( int i, int j ) { j = 3 - j; for( ; j > 0; j-- ) i /= 10; return( i % 10 ); } int swap( int i, int a, int b, int c, int d ) { int result; result = get( i, a ) * 1000; result += get( i, b ) * 100; result += get( i, c ) * 10; result += get( i, d ) * 1; return( result ); } bool check( int i, bool verbose = false ) { if( get( i, 0 ) == 0 ) return( false ); if( get( i, 1 ) == 0 ) return( false ); if( get( i, 2 ) == 0 ) return( false ); if( get( i, 3 ) == 0 ) return( false ); int j; j = swap( i, 0, 1, 2, 3 ); if( verbose ) printf( "ABCD %d\n", j ); if( ( i % 13 ) != 0 ) return( false ); j = swap( i, 1, 2, 3, 0 ); if( verbose ) printf( "BCDA %d\n", j ); if( ( j % 11 ) != 0 ) return( false ); j = swap( i, 2, 3, 0, 1 ); if( verbose ) printf( "CDAB %d\n", j ); if( ( j % 9 ) != 0 ) return( false ); j = swap( i, 3, 0, 1, 2 ); if( verbose ) printf( "DABC %d\n", j ); if( ( j % 7 ) != 0 ) return( false ); return( true ); } int main() { for( int i = 0; i < 10000; i++ ) { if( check( i ) ) { printf( "Result %d\n", i ); check( i, true ); } } } Edited October 17, 2019 by Sensei 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now