From 50b82e356cffc24c048b46e0d4de447e32bd25b4 Mon Sep 17 00:00:00 2001 From: Patrick Jakobsen <97399891+Pallepadehat@users.noreply.github.com> Date: Wed, 13 May 2026 22:51:21 +0200 Subject: [PATCH] New solution --- 2-variables/quadratic-formula/Quadratic.swift | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/2-variables/quadratic-formula/Quadratic.swift b/2-variables/quadratic-formula/Quadratic.swift index 0fb4379..78a33de 100644 --- a/2-variables/quadratic-formula/Quadratic.swift +++ b/2-variables/quadratic-formula/Quadratic.swift @@ -1,19 +1,14 @@ // Quadratic Formula 📈 -// Sonny Li +// Patrick Jakobsen -var a: Double = 6 -var b: Double = -7 -var c: Double = -3 +let a = 6.0 +let b = -7.0 +let c = -3.0 -var root1: Double -var root2: Double +let discriminant = (b * b - 4 * a * c).squareRoot() -// The positive root -root1 = (-b + (b*b - 4*a*c).squareRoot()) / (2*a) +let root1 = (-b + discriminant) / (2 * a) +let root2 = (-b - discriminant) / (2 * a) -// The negative root -root2 = (-b - (b*b - 4*a*c).squareRoot()) / (2*a) - -// Outputting the roots -print("Root 1 is \(root1)") -print("Root 2 is \(root2)") +print("Root 1:", root1) +print("Root 2:", root2)