Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 1 character in body
Source Link
totallyhuman
  • 17.4k
  • 3
  • 34
  • 89

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) xs ≡ 0]
 where bound = sum $ abs § lxs

Alternate solution, 44 bytes

Credit to nimi.

f l=[i|i<-[minBound..],foldl1((+).(i*))l==0]

Good luck with trying it online, as this checks every number in an Int's range.

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) xs ≡ 0]
 where bound = sum $ abs § l

Alternate solution, 44 bytes

Credit to nimi.

f l=[i|i<-[minBound..],foldl1((+).(i*))l==0]

Good luck with trying it online, as this checks every number in an Int's range.

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) xs ≡ 0]
 where bound = sum $ abs § xs

Alternate solution, 44 bytes

Credit to nimi.

f l=[i|i<-[minBound..],foldl1((+).(i*))l==0]

Good luck with trying it online, as this checks every number in an Int's range.

added 21 characters in body
Source Link
totallyhuman
  • 17.4k
  • 3
  • 34
  • 89

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) xs ≡ 0]
 where bound = sum $ abs § l

Alternate solution, 44 bytes

Credit to nimi.

f l=[i|i<-[minBound..],foldl1((+).(i*))l==0]

Good luck with trying it online, as this checks every number in an Int's range.

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) xs ≡ 0]
 where bound = sum $ abs § l

Alternate solution, 44 bytes

f l=[i|i<-[minBound..],foldl1((+).(i*))l==0]

Good luck with trying it online, as this checks every number in an Int's range.

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) xs ≡ 0]
 where bound = sum $ abs § l

Alternate solution, 44 bytes

Credit to nimi.

f l=[i|i<-[minBound..],foldl1((+).(i*))l==0]

Good luck with trying it online, as this checks every number in an Int's range.

added 494 characters in body
Source Link
totallyhuman
  • 17.4k
  • 3
  • 34
  • 89

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) lxs ≡ 0]
 where bound = sum $ abs § l

Alternate solution, 44 bytes

f l=[i|i<-[minBound..],foldl1((+).(i*))l==0]

Good luck with trying it online , as this checks every number in an Int's range.

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) l ≡ 0]
 where bound = sum $ abs § l

Haskell, 54 bytes

f l|t<-sum$abs<$>l=[i|i<-[-t..t],foldl1((+).(i*))l==0]

Try it online!

Brute force and synthetic division.

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell
roots ∷ Num a ⇒ [a] → [a]
roots xs = [r | r ← -bound ... bound, foldl1 ((+) ∘ (r ×ばつ)) xs ≡ 0]
 where bound = sum $ abs § l

Alternate solution, 44 bytes

f l=[i|i<-[minBound..],foldl1((+).(i*))l==0]

Good luck with trying it online , as this checks every number in an Int's range.

added 257 characters in body
Source Link
totallyhuman
  • 17.4k
  • 3
  • 34
  • 89
Loading
added 197 characters in body
Source Link
totallyhuman
  • 17.4k
  • 3
  • 34
  • 89
Loading
deleted 10 characters in body
Source Link
totallyhuman
  • 17.4k
  • 3
  • 34
  • 89
Loading
added 39 characters in body
Source Link
totallyhuman
  • 17.4k
  • 3
  • 34
  • 89
Loading
Source Link
totallyhuman
  • 17.4k
  • 3
  • 34
  • 89
Loading

AltStyle によって変換されたページ (->オリジナル) /