Funooni's Posts
Nairaland Forum › Funooni's Profile › Funooni's Posts
1 (of 1 pages)
Hi guys , I thought i could do it easily using Brute Force SQL but it gave a tuff time First i tried with whole numbers but it didnt work but then i found this site (I got the puzzle in a whatsapp group). Once here i saw the answer in decimals. Of course then i solved it easily with Decimal brute force use dba drop table tableA drop table TableAandC create table tableA (a bigint) declare @icount int set @icount = -50000 while @icount < 50000 begin insert into Tablea select @icount set @icount = @icount +1 end select * From tablea a, tablea b, tablea c , tablea d where a.a + b.a = 8 and a.a + c.a = 13 and b.a + d.a = 8 and c.a- d.a = 6 --TRY to do it in parts first find all combinations that can have a+b = 8 and a+ c = 13 then check for the rest two select * From tablea a, tablea c where a.a + c.a = 13 select A.a AS A , C.A as C into TableAandC From tablea a, tablea c where a.a + c.a = 13 --Nothing found with whole numbers -- So lets try with decimals /**SECOND APPROACH ***/ use dba drop table tableA create table tableA (a money , b money,c money,d money) declare @icount money set @icount = -10.00 while @icount < 100.00 begin insert into Tablea select @icount , 8-@icount , 13-@icount , 13-@icount - 6 set @icount = @icount +0.1 end select * From tablea a where a.a + b = 8 and a + c = 13 and b+ d = 8 and c- d = 6 The above query gives correct answer. The code will work in SQL SERVER |
1 (of 1 pages)