Jump to content

Can you find the Number ?


Commander

Recommended Posts

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

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

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

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 by Sensei
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.