Skip to main content
deleted 1 character in body; added 7 characters in body
Source Link
KIKO Software
  • 17.5k
  • 3
  • 33
  • 54

I wrote some basic code in PHP to do this challenge:

<?php

$json = file_get_contents("List of 1000 strings.json");
$list = json_decode($json);

$nonPangram     = 0;
$normalPangram  = 0;
$perfectPangram = 0;

foreach ($list as $item) {
    $lowercase = strtolower($item));
    $alfabet = array_intersect(str_split($lowercase), range("a", "z"));
    $counts = array_count_values($alfabet);
    if (count($counts) == 26) {
        if (array_sum($counts) == 26) {
            $perfectPangram++;
        } else {
            $normalPangram++;
        }
    } else {
        $nonPangram++;
    }
}

echo "This list contains $nonPangram non-pangrams, $normalPangram normal pangrams and $perfectPangram perfect pangrams.";

The output is:

This list contains 819 non-pangrams, 132 normal pangrams and 49 perfect pangrams.

I leave it to the reader to infer that there are a total of 181 pangrams, normal and perfect.

This was not a hard challenge for me, although I hope I got the answer right. I tried to look for things like accents, but didn't see them. If they are there my results would not be right, but that could be easily corrected.

The algorithm is:

  • Turn everything into lower case characters.

  • Turn the string into an array of characters, excluding everything except the [a - z] set.

  • Use the PHP function array_count_values Toto count the values.

  • Then evaluate the result.

I spent most of my time replacing the line with the regular expression, I had at first, by something more PHP-like. So I used an array intersect:

$alfabet = array_intersect(str_split($lowercase), range("a", "z"));

instead of a regular expression:

$alfabet = str_split(preg_replace("/[^a-z]+/", "", $lowercase));

The reason, for me, is that I find most regular expressions are inscrutable. Sure, I can use something like regex101.com and work it out, but it's always an effort. Of course, in this case the regular expression is quite simple, so it could behave been used.

I wrote some basic code in PHP to do this challenge:

<?php

$json = file_get_contents("List of 1000 strings.json");
$list = json_decode($json);

$nonPangram     = 0;
$normalPangram  = 0;
$perfectPangram = 0;

foreach ($list as $item) {
    $lowercase = strtolower($item));
    $alfabet = array_intersect(str_split($lowercase), range("a", "z"));
    $counts = array_count_values($alfabet);
    if (count($counts) == 26) {
        if (array_sum($counts) == 26) {
            $perfectPangram++;
        } else {
            $normalPangram++;
        }
    } else {
        $nonPangram++;
    }
}

echo "This list contains $nonPangram non-pangrams, $normalPangram normal pangrams and $perfectPangram perfect pangrams.";

The output is:

This list contains 819 non-pangrams, 132 normal pangrams and 49 perfect pangrams.

I leave it to the reader to infer that there are a total of 181 pangrams, normal and perfect.

This was not a hard challenge for me, although I hope I got the answer right. I tried to look for things like accents, but didn't see them. If they are there my results would not be right, but that could be easily corrected.

The algorithm is:

  • Turn everything into lower case characters.

  • Turn the string into an array of characters, excluding everything except the [a - z] set.

  • Use the PHP function array_count_values To count the values.

  • Then evaluate the result.

I spent most of my time replacing the line with the regular expression by something more PHP-like. So I used an array intersect:

$alfabet = array_intersect(str_split($lowercase), range("a", "z"));

instead of a regular expression:

$alfabet = str_split(preg_replace("/[^a-z]+/", "", $lowercase));

The reason, for me, is that I find most regular expressions are inscrutable. Sure, I can use something like regex101.com and work it out, but it's always an effort. Of course, in this case the regular expression is quite simple, so it could be used.

I wrote some basic code in PHP to do this challenge:

<?php

$json = file_get_contents("List of 1000 strings.json");
$list = json_decode($json);

$nonPangram     = 0;
$normalPangram  = 0;
$perfectPangram = 0;

foreach ($list as $item) {
    $lowercase = strtolower($item));
    $alfabet = array_intersect(str_split($lowercase), range("a", "z"));
    $counts = array_count_values($alfabet);
    if (count($counts) == 26) {
        if (array_sum($counts) == 26) {
            $perfectPangram++;
        } else {
            $normalPangram++;
        }
    } else {
        $nonPangram++;
    }
}

echo "This list contains $nonPangram non-pangrams, $normalPangram normal pangrams and $perfectPangram perfect pangrams.";

The output is:

This list contains 819 non-pangrams, 132 normal pangrams and 49 perfect pangrams.

I leave it to the reader to infer that there are a total of 181 pangrams, normal and perfect.

This was not a hard challenge for me, although I hope I got the answer right. I tried to look for things like accents, but didn't see them. If they are there my results would not be right, but that could be easily corrected.

The algorithm is:

  • Turn everything into lower case characters.

  • Turn the string into an array of characters, excluding everything except the [a - z] set.

  • Use the PHP function array_count_values to count the values.

  • Then evaluate the result.

I spent most of my time replacing the regular expression, I had at first, by something more PHP-like. So I used an array intersect:

$alfabet = array_intersect(str_split($lowercase), range("a", "z"));

instead of a regular expression:

$alfabet = str_split(preg_replace("/[^a-z]+/", "", $lowercase));

The reason, for me, is that I find most regular expressions inscrutable. Sure, I can use something like regex101.com and work it out, but it's always an effort. Of course, in this case the regular expression is quite simple, so it could have been used.

Source Link
KIKO Software
  • 17.5k
  • 3
  • 33
  • 54

I wrote some basic code in PHP to do this challenge:

<?php

$json = file_get_contents("List of 1000 strings.json");
$list = json_decode($json);

$nonPangram     = 0;
$normalPangram  = 0;
$perfectPangram = 0;

foreach ($list as $item) {
    $lowercase = strtolower($item));
    $alfabet = array_intersect(str_split($lowercase), range("a", "z"));
    $counts = array_count_values($alfabet);
    if (count($counts) == 26) {
        if (array_sum($counts) == 26) {
            $perfectPangram++;
        } else {
            $normalPangram++;
        }
    } else {
        $nonPangram++;
    }
}

echo "This list contains $nonPangram non-pangrams, $normalPangram normal pangrams and $perfectPangram perfect pangrams.";

The output is:

This list contains 819 non-pangrams, 132 normal pangrams and 49 perfect pangrams.

I leave it to the reader to infer that there are a total of 181 pangrams, normal and perfect.

This was not a hard challenge for me, although I hope I got the answer right. I tried to look for things like accents, but didn't see them. If they are there my results would not be right, but that could be easily corrected.

The algorithm is:

  • Turn everything into lower case characters.

  • Turn the string into an array of characters, excluding everything except the [a - z] set.

  • Use the PHP function array_count_values To count the values.

  • Then evaluate the result.

I spent most of my time replacing the line with the regular expression by something more PHP-like. So I used an array intersect:

$alfabet = array_intersect(str_split($lowercase), range("a", "z"));

instead of a regular expression:

$alfabet = str_split(preg_replace("/[^a-z]+/", "", $lowercase));

The reason, for me, is that I find most regular expressions are inscrutable. Sure, I can use something like regex101.com and work it out, but it's always an effort. Of course, in this case the regular expression is quite simple, so it could be used.