Sort by

recency

|

1279 Discussions

|

  • + 0 comments

    Branded merchandise can creatively incorporate themes like Forming a Magic Square to make promotions unique and engaging. By adding puzzle-inspired designs or interactive elements to products, brands can capture attention while delivering value. Such merchandise not only promotes your logo but also sparks curiosity and conversation. Whether it’s apparel, stationery, or giveaways, blending intellectual fun with branding boosts memorability, making it a smart approach for marketing campaigns that stand out.

  • + 1 comment

    Big Brain Question

    def formingMagicSquare(s):
        lu_1 = [[8,1,6], [3,5,7], [4,9,2]]
        lu_2 = [[6,1,8], [7,5,3], [2,9,4]]
        lu_3 = [[4,9,2], [3,5,7], [8,1,6]]
        lu_4 = [[2,9,4], [7,5,3], [6,1,8]]
        lu_5 = [[8,3,4], [1,5,9], [6,7,2]]
        lu_6 = [[4,3,8], [9,5,1], [2,7,6]]
        lu_7 = [[6,7,2], [1,5,9], [8,3,4]]
        lu_8 = [[2,7,6], [9,5,1], [4,3,8]]
        
        var = [
            lu_1, lu_2, lu_3, lu_4, lu_5, lu_6, lu_7, lu_8
        ]
        diff = []
        for v in var:
            temp = 0
            for v_, s_ in zip(v, s):
                for v__, s__ in zip(v_, s_):
                    if v__ != s__:
                        temp += abs(v__ - s__)
            diff.append(temp)
        
        diff = sorted(diff)
        return diff[0]
    
  • + 0 comments

    How do you do this without looking at solutions??? This is big brain question

  • + 0 comments

    This is my rust solution

    const SQUARES: [[[i32; 3]; 3]; 8] = [
        [[8, 1, 6], [3, 5, 7], [4, 9, 2]],
        [[6, 1, 8], [7, 5, 3], [2, 9, 4]],
        [[4, 9, 2], [3, 5, 7], [8, 1, 6]],
        [[2, 9, 4], [7, 5, 3], [6, 1, 8]],
        [[8, 3, 4], [1, 5, 9], [6, 7, 2]],
        [[4, 3, 8], [9, 5, 1], [2, 7, 6]],
        [[6, 7, 2], [1, 5, 9], [8, 3, 4]],
        [[2, 7, 6], [9, 5, 1], [4, 3, 8]],
    ];
    
    fn forming_magic_square(s: &[Vec<i32>]) -> i32 {
        SQUARES
            .iter()
            .map(|square| {
                square
                    .iter()
                    .zip(s)
                    .map(|(good, input)| {
                        good.iter()
                            .zip(input)
                            .map(|(&x, &y)| (x - y).abs())
                            .sum::<i32>()
                    })
                    .sum::<i32>()
            })
            .min()
            .unwrap()
    }
    
  • + 0 comments

    JAVA15: import java.util.*;

    public class Solution {

    // All 8 possible 3x3 magic squares using numbers 1 to 9
    private static final int[][][] MAGIC_SQUARES = {
        {{8, 1, 6}, {3, 5, 7}, {4, 9, 2}},
        {{6, 1, 8}, {7, 5, 3}, {2, 9, 4}},
        {{4, 9, 2}, {3, 5, 7}, {8, 1, 6}},
        {{2, 9, 4}, {7, 5, 3}, {6, 1, 8}},
        {{8, 3, 4}, {1, 5, 9}, {6, 7, 2}},
        {{4, 3, 8}, {9, 5, 1}, {2, 7, 6}},
        {{6, 7, 2}, {1, 5, 9}, {8, 3, 4}},
        {{2, 7, 6}, {9, 5, 1}, {4, 3, 8}}
    };
    
    public static int formingMagicSquare(int[][] s) {
        int minCost = Integer.MAX_VALUE;
    
        for (int[][] magic : MAGIC_SQUARES) {
            int cost = 0;
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    cost += Math.abs(s[i][j] - magic[i][j]);
                }
            }
            minCost = Math.min(minCost, cost);
        }
    
        return minCost;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] s = new int[3][3];
    
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                s[i][j] = scanner.nextInt();
            }
        }
    
        int result = formingMagicSquare(s);
        System.out.println(result);
    
        scanner.close();
    }
    

    }