Is this considered an elegant and correct solution to a problem in Haskell

I have recently started learning functional programming and Haskell. I have encountered this problem:

“Consider three two-dimensional points a, b, and c. If we look at the angle formed by the line segment from a to b and the line segment from b to c, it either turns left, turns right, or forms a straight line. Define a Direction data type that lets you represent these possibilities. Write a function that calculates the turn made by three 2D points and returns a Direction.”

I have heard that one of the goals of the Haskell language is to create elegant solutions.

This is my solution:

data Direction = LeftTurn | RightTurn | Straight deriving Show

findDirection (x, y) (x1, y1) (x2, y2) 
    | (x, y) == (x1, y1)          = Straight
    | (x1, y1) == (x2, y2)        = Straight
    | (x, y) == (x2, y2)          = Straight
    | x == x1 && x1 == x2         = Straight
    | x1 == x && y1 > y && x2 > x = RightTurn
    | x1 == x && y1 > y && x2 < x = LeftTurn
    | x1 == x && y1 < y && x2 < x = RightTurn
    | x1 == x && y1 < y && x2 > x = LeftTurn
    | x1 > x && y2 > y_on_line    = LeftTurn
    | x1 > x && y2 < y_on_line    = RightTurn
    | x1 > x && y2 == y_on_line   = Straight
    | x1 < x && y2 > y_on_line    = RightTurn
    | x1 < x && y2 < y_on_line    = LeftTurn
    | x1 < x && y2 == y_on_line   = Straight
   where y_on_line   = slope * x2 + y_intercept
         slope       = (y1 - y) / (x1 - x)
         y_intercept = y - slope * x

This looks like it is too long to be considered an elegant solution.

Do all consensus algorithms aim to solve the Byzantine generals problem?

Can I clarify my understanding:

Byzantine Fault Tolerance is a characteristic of a system to tolerate a class of failures belonging to the byzantine generals problem.

Byzantine Fault tolerance is also the name of the consensus algorithm that solves the byzantine generals problem?

I see Ripple as being BFT. Does it mean it uses some custom algorithm, that solves BFT?

I also see Stellar uses BFT, does this mean that Stellar and Ripple Both use different algorithms that solve BFT?


Can all Proof of Insert word algorithms be seen to be a part of BFT? Because POW uses a probabilistic model to solve the generals problem, but it is not seen as BFT.

Does this Dental X-ray indicate problem with Jaw [on hold]

Does this X-ray indicate a problem with jaw joints. To be there seems to be some asymmetry, but is this indicative of an issue. This X-ray offers users of this site the chance to view and understand an x-ray, and as such is not only of interest to myself the poster, nor is a derailed medical record required to simply analyse the xray.

enter image description here

Very specific video stuttering problem in skyrim

I use a mod called “Camera Scripter”. It uses skse and is largely a compiled dll.

As time goes on over the span of several days, video during scripted movements becomes more and more stuttered. However, the steam-overlay framerate stays normal and normal in-game activity remains fluid.

Here’s a couple of videos to display the problem. I created a script, ran it with record, rebooted, then ran it again with record.

  • Before reboot
  • After reboot

You can see the framerate in the upper left remains consistently 50-60.

This isn’t a critical or showstopping problem, but it leads to rebooting much more often than normal. If I ignore this problem, I go long enough between reboots that I forget the last time I rebooted.

Any thoughts on what might be the cause here?

Problem with addWebsiteFilter and addStoreFilter

I am working on my product collection query. I used “addWebsiteFilter” and “addStoreFilter” in my collection query. The problem is addWebsiteFilter supports array of website ids but addStoreFilter not supporting array of store ids so my query return error. Is any other method which supports array of store id for filtering product collection.

$collection_new = Mage::getModel('catalog/product')                          
->addAttributeToFilter('status', 1);

WeightedData Problem

I have two lists, the first one containing energies the second corresponding weights, which I want to combine into a weighted data set by using WeightedData.

    emu =     {6.07554,6.75035,6.01235,2.64212,1.20845,0.467369,0.38045,7.17174,2.60847,6.8873,1.29288,3.46793,0.724271,8.8205,8.42026,2.89836,2.01046,7.80828,3.2274,10.2535,2.23425,2.5784,2.23205,5.60826, [CenterEllipsis]39372[CenterEllipsis] ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

   w =        {0.000187777,6.6735*10^-7,0.0000141254,0.00029926,0.000187454,0.000198866,0.000028403,0.000225412,0.0000410494,4.83498*10^-7,4.90761*10^-8,0.000188634,0.000175243,0.000277206,0.000922494,0.0000276259,0.0000296997,0.0000281182,0.0000585339,0.000261283,0.000159857,0.0000141163,3.93197*10^-6,0.0000918486,3.02746*10^-8,0.0000943955,6.51029*10^-8,0.0000591572,0.000102857,-0.0000190349,0.0000449394,0.0000234642,0.0000112653,0.000387695,0.000152116, [CenterEllipsis]39350[CenterEllipsis] ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

Then I say
ew = WeightedData[emu, w]
and get an error message:

WeightedData::wtmsg: The argument {0.000187777,6.6735*10^-7,0.0000141254,0.00029926,0.000187454,0.000198866,0.000028403,0.000225412,0.0000410494,4.83498*10^-7,<<31>>,0.000210445,0.0000179127,0.0000806435,0.000426889,0.0000355587,0.000556132,0.0000220848,1.30042*10^-7,0.000421571,<<39370>>} is not a valid weight specification.

What is going wrong?