Sort by

recency

|

140 Discussions

|

  • + 0 comments

    I enjoy the challenge of constructing numbers, especially when it comes to solving puzzles. It reminds me of my time playing Crazy Cattle 3D, where you need to strategically manage your resources. It's fascinating how both activities require critical thinking and planning. When I approach number construction, I feel the same thrill as when I’m maneuvering around obstacles in Crazy Cattle 3D. It’s a fun way to keep my mind sharp!

  • + 0 comments

    A number is only divisible by 3 if the sum of its digits is divisible by 3.

    So make a loop to sum the digits into a variable. You'll only need to check if that one number is divisible by 3. If yes, then any combination of its digits will be divisible by 3.

    def canConstruct(a):
        # A number is only divisible by 3 if the sum of its digits is divisible by 3
        digits_sum = 0
        for i in a:
            str_i = str(i)
            for x in str_i:
                digits_sum += int(x)
        return "Yes" if digits_sum % 3 == 0 else "No"
    
  • + 0 comments

    A number is only divisible by 3 if the sum of its digits is divisible by 3.

    So make a loop to sum the digits into a variable. You'll only need to check if that one number is divisible by 3. If yes, then any combination of its digits will be divisible by 3.

    def canConstruct(a): digits_sum = 0 for i in a: str_i = str(i) for x in str_i: digits_sum += int(x)

  • + 0 comments

    Java 15

    public static String canConstruct(List<Integer> a) {
            int res = 0;
    
            for (Integer i : a) {
                char[] charArray = String.valueOf(i).toCharArray();
                for (char c : charArray) {
                    res += Integer.parseInt(Character.toString(c));
                }
            }
            return (res % 3 == 0)? "Yes" : "No";
        }
    
  • + 0 comments
    def check(n,x):
        s = ''
        for i in range(n):
            t = str(x[i])
            s += t
        s = str(s)
        p = list(permutations(s))
        for q in p:
            digit = int(''.join(q))
            if digit%3 ==0:
                return True
            else:
                return False
                
    from itertools import permutations
    for _ in range(int(input())):
        n = int(input())
        x = list(map(int, input().split()))
        print('Yes' if check(n,x) else 'No')