This version of the page http://www.rationalplanet.com/?p=2652 (0.0.0.0) stored by archive.org.ua. It represents a snapshot of the page as of 2014-03-14. The original page over time could change.
Triangle at Codility.com - 100/100 PHP Solutions | LAMP Freelancer

Articles Comments Mobile Version

LAMP Freelancer » Coding Tips & How-Toes, PHP, Programming & Freelancing, Programming Testing and Exams » Triangle Demo Task at Codility.com

Triangle Demo Task at Codility.com

Lesson 4 – Sorting - Triangle demo task solution code written in php. Gives 100/100 score at the time of publishing. The description of the problem is copyrighted, so please see the following link for it: https://codility.com/demo/take-sample-test/triangle

Solution in php:

function solution($A) {
    $cnt = count($A);
    if ($cnt < 3){
        return 0;
    }
    $lcnt = $cnt -2;
    sort($A, SORT_NUMERIC);
    for($i = 0; $i < $lcnt; $i++){
        if($A[$i] + $A[$i+1] > $A[$i+2]){
            return 1;
        }
    }
    return 0;
}

Given “AS IS”, can be ported from other languages from solutions found on the internet, please use with care.

Please note: we think that codility.com does not give a correct assessment of your real-world programming skills. For instance, reading the below would bring more understanding why: http://codility-test-questions.blogspot.com/2013/01/my-experience-with-codility-test.html

Written by Alec

Visit Alec's Website

Follow Alec on Twitter

Filed under: Coding Tips & How-Toes, PHP, Programming & Freelancing, Programming Testing and Exams · Tags: 100/100, Codility.com, PHP, Solutions, Triangle

Support this site:

Leave a Reply Cancel reply

*

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>