Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,170 members, 8,001,799 topics. Date: Wednesday, 13 November 2024 at 04:17 PM

Funooni's Posts

Nairaland Forum / Funooni's Profile / Funooni's Posts

(1) (of 1 pages)

Education / Re: You Think You're Genius Solve This Problem by funooni: 11:16pm On Sep 06, 2016
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)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.