calculate fourdigit number with nested for