{"id":6104,"date":"2023-11-18T00:01:58","date_gmt":"2023-11-18T08:01:58","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6104"},"modified":"2023-11-25T08:52:53","modified_gmt":"2023-11-25T16:52:53","slug":"hunting-for-7-character-pangrams","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6104","title":{"rendered":"Hunting for 7-Character Pangrams"},"content":{"rendered":"<p>I&#8217;m a fan of the online game <a href=\"https:\/\/www.nytimes.com\/puzzles\/spelling-bee\" rel=\"noopener\" target=\"_blank\">Spelling Bee<\/a>. In this game, you use a combination of seven letters to spell various words. Each word is at least four-letters long and must contain a special letter, shown in the center of Figure 1. When you create a word that contains all seven letters, you&#8217;ve discovered a <em>pangram<\/em>.<br \/>\n<!--more--><br \/>\n<div id=\"attachment_6105\" style=\"width: 448px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6105\" src=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2023\/11\/1118-figure1.png\" alt=\"\" width=\"438\" height=\"456\" class=\"size-full wp-image-6105\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2023\/11\/1118-figure1.png 438w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2023\/11\/1118-figure1-288x300.png 288w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><p id=\"caption-attachment-6105\" class=\"wp-caption-text\">Figure 1. Seven tiles from the Spelling Bee game. One of the pangrams is WARPING, which uses all seven letters.<\/p><\/div><\/p>\n<p>The Spelling Bee puzzle shown in Figure 1 has 34 correct answers. Each one contains at least four of the shown letters and all include the W, the center tile. It&#8217;s a fun game that inspires me to wonder how many words in English are pangrams?<\/p>\n<p>According to the Spelling Bee rules, the answers cannot be proper nouns. They can occasionally be foreign words, though this rule seems inconsistent. Regardless, I&#8217;m inspired. I cobbled together code from <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6098\">last week&#8217;s Lesson<\/a> to look for 7-letter words. Then I added an update to this <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6093\">month&#8217;s Exercise solution<\/a> to look for unique characters in 7-letter words. Here is the result:<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2023_11_18-Lesson.c\" rel=\"noopener\" target=\"_blank\">2023_11_18-Lesson.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;string.h&gt;\r\n\r\n<span class=\"comments\">\/* this code assumes the following path is valid *\/<\/span>\r\n#define DICTIONARY \"\/usr\/share\/dict\/words\"\r\n#define SIZE 32\r\n#define LENGTH 7\r\n#define TRUE 1\r\n#define FALSE 0\r\n\r\nint char_scan(char *a)\r\n{\r\n    int size,x,y;\r\n\r\n    <span class=\"comments\">\/* obtain size *\/<\/span>\r\n    size = strlen(a) + 1;\r\n    <span class=\"comments\">\/* scan the characters *\/<\/span>\r\n    for( x=0; x&lt;size-2; x++ )\r\n    {\r\n        for( y=x+1; y&lt;size-1; y++ )\r\n        {\r\n            if( a[x] == a[y] )\r\n            {\r\n                <span class=\"comments\">\/* not unique *\/<\/span>\r\n                return(FALSE);\r\n            }\r\n        }\r\n    }\r\n    return(TRUE);\r\n}\r\n\r\nint main()\r\n{\r\n    FILE *dict;\r\n    int unique;\r\n    char word[SIZE],*r;\r\n\r\n    <span class=\"comments\">\/* open the dictionary *\/<\/span>\r\n    dict = fopen(DICTIONARY,\"r\");\r\n    if( dict==NULL )\r\n    {\r\n        fprintf(stderr,\"Unable to open %s\\n\",DICTIONARY);\r\n        exit(1);\r\n    }\r\n\r\n    <span class=\"comments\">\/* scan for LENGTH-letter words *\/<\/span>\r\n    unique = 0;\r\n    while( !feof(dict) )\r\n    {\r\n        memset(word,'\\0',SIZE);        <span class=\"comments\">\/* clear buffer *\/<\/span>\r\n        r = fgets(word,SIZE,dict);    <span class=\"comments\">\/* read a word *\/<\/span>\r\n        if( r==NULL )\r\n            break;\r\n        if( word[LENGTH-2]=='\\'' )            <span class=\"comments\">\/* skip possessives *\/<\/span>\r\n            continue;\r\n        if( word[LENGTH]=='\\n' )            <span class=\"comments\">\/* 7-letter word *\/<\/span>\r\n        {\r\n            if( char_scan(word) )\r\n            {\r\n                printf(\"%s\",word);\r\n                unique++;\r\n            }\r\n        }\r\n    }\r\n    printf(\"I found %d pangrams!\\n\",unique);\r\n\r\n    <span class=\"comments\">\/* close *\/<\/span>\r\n    fclose(dict);\r\n\r\n    return(0);\r\n}<\/pre>\n<p>The <em>char_scan()<\/em> function is an update to <em>digit_scan()<\/em> from this month&#8217;s Exercise solution. The <em>snprintf()<\/em> function isn&#8217;t required as a string (<code>a<\/code>) is passed directly. I retained the <code>size<\/code> variable, though all strings should be 7-characters long. Otherwise, the function works the same as from this month&#8217;s Exercise solution.<\/p>\n<p>The <em>main()<\/em> function scans for <code>LENGTH<\/code> size words, where <code>LENGTH<\/code> is 7 characters. For words of that size, the <em>char_scan()<\/em> function is called and, when TRUE, the pangram word is output and a tally kept.<\/p>\n<p>When I ran the program without checking for pangrams, it reported 11,945 7-letter words in the dictionary file. After adding the <em>char_scan()<\/em> function, the output showed 4,078 pangrams.<\/p>\n<p>The program isn&#8217;t perfect. For example, it flags the word <em>vicu\u00f1a<\/em> as being 7-letters long. It&#8217;s probably interpreting the \u00f1 as two-letters. Further, the Spelling Bee game tries to avoid plurals, where my program makes no such attempt.<\/p>\n<p>All Spelling Bee puzzles have at least one pangram solution. Sometimes the pangrams can be quite long. For <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6112\">next week&#8217;s Lesson<\/a>, I scan the digital dictionary to look for all possible pangram words seven letters or longer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A program can not only find dictionary words of a certain length, but words that contain no repeating letters. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6104\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-6104","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6104"}],"version-history":[{"count":7,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6104\/revisions"}],"predecessor-version":[{"id":6137,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6104\/revisions\/6137"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}