119k views
4 votes
I'm doing a task which involves magic v's, a maths pattern which has the rule of having the same total on each side. For e.g.

6 5
3 4
2
Is a magic v because each side adds up to 11. I need to make magic V's with the number 2-6 and 3-7. There are 24 possibilities for each number set.

1 Answer

5 votes

Answer:

--1-- (of set 23456)

2 4

5 3

6

--2-- (of set 23456)

2 3

5 4

6

--3-- (of set 23456)

2 5

6 3

4

--4-- (of set 23456)

2 3

6 5

4

--5-- (of set 23456)

3 5

4 2

6

--6-- (of set 23456)

3 2

4 5

6

--7-- (of set 23456)

3 6

5 2

4

--8-- (of set 23456)

3 2

5 6

4

--9-- (of set 23456)

3 5

6 4

2

--10-- (of set 23456)

3 4

6 5

2

--11-- (of set 23456)

4 5

3 2

6

--12-- (of set 23456)

4 2

3 5

6

--13-- (of set 23456)

4 6

5 3

2

--14-- (of set 23456)

4 3

5 6

2

--15-- (of set 23456)

5 4

2 3

6

--16-- (of set 23456)

5 3

2 4

6

--17-- (of set 23456)

5 6

3 2

4

--18-- (of set 23456)

5 2

3 6

4

--19-- (of set 23456)

5 6

4 3

2

--20-- (of set 23456)

5 3

4 6

2

--21-- (of set 23456)

6 5

2 3

4

--22-- (of set 23456)

6 3

2 5

4

--23-- (of set 23456)

6 5

3 4

2

--24-- (of set 23456)

6 4

3 5

2

--1-- (of set 34567)

3 5

6 4

7

--2-- (of set 34567)

3 4

6 5

7

--3-- (of set 34567)

3 6

7 4

5

--4-- (of set 34567)

3 4

7 6

5

--5-- (of set 34567)

4 6

5 3

7

--6-- (of set 34567)

4 3

5 6

7

--7-- (of set 34567)

4 7

6 3

5

--8-- (of set 34567)

4 3

6 7

5

--9-- (of set 34567)

4 6

7 5

3

--10-- (of set 34567)

4 5

7 6

3

--11-- (of set 34567)

5 6

4 3

7

--12-- (of set 34567)

5 3

4 6

7

--13-- (of set 34567)

5 7

6 4

3

--14-- (of set 34567)

5 4

6 7

3

--15-- (of set 34567)

6 5

3 4

7

--16-- (of set 34567)

6 4

3 5

7

--17-- (of set 34567)

6 7

4 3

5

--18-- (of set 34567)

6 3

4 7

5

--19-- (of set 34567)

6 7

5 4

3

--20-- (of set 34567)

6 4

5 7

3

--21-- (of set 34567)

7 6

3 4

5

--22-- (of set 34567)

7 4

3 6

5

--23-- (of set 34567)

7 6

4 5

3

--24-- (of set 34567)

7 5

4 6

3

Explanation:

This javascript code is extremely brute-force, but it does the job:

function checkIfInSet(i, set) {

return i.toString().split('').sort().join('') === set;

}

function checkIfMagic(s) {

return (parseInt(s[0]) + parseInt(s[1]) == parseInt(s[3]) + parseInt(s[4]))

}

function printMagic(s) {

console.log(`${s[0]} ${s[4]}`);

console.log(` ${s[1]} ${s[3]}`);

console.log(` ${s[2]}\\`);

}

function checkSet(set) {

let counter = 1;

for(let i=1; i<99999; i++) {

if (checkIfInSet(i, set) && checkIfMagic(i.toString())) {

console.log(`--${counter++}-- (of set ${set})`);

printMagic(i.toString());

}

}

}

checkSet('23456');

checkSet('34567');

User Oana
by
7.7k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories