Results 1 to 12 of 12

Thread: Pangram Tester

  1. #1

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Pangram Tester

    A pangram is one of those sentences like "The quick brown fox jumps over a lazy dog" which contains every letter of the English alphabet. For all I know they may exist in other languages too. They have a minor practical use: for showing off font examples. There is an art to writing a pangram which is as short as possible but still reads like a proper sentence. See here for more information and examples.

    I was amusing myself trying to invent new pangrams on paper. Checking whether you haven't missed any letters is a bit of a chore. So I made a little program that does that automatically. The program also shows the number of letters in the pangram, and it has a button for saving your pangrams to a text file.

    The form contains two text boxes; the top one is multiline and the second one is read-only. The code is pretty simple:

    Name:  PangramTester.jpg
Views: 2446
Size:  17.3 KB

    Here's the code for the form:
    Code:
    Public Class PangramTesterForm
    
    	Private _Alphabet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    	Private _Punctuation As String = " .,-:;!?'""()[]{}/"
    	Private _Pangram As New System.Text.StringBuilder
    
    	Private Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
    		Dim missingLetters As New System.Text.StringBuilder
    		_Pangram = New System.Text.StringBuilder(TextBox1.Text.ToUpper)
    
    		'Count letters excluding punctuation:
    		For Each ch As Char In _Punctuation
    			_Pangram.Replace(ch, "")
    		Next
    		lblCountLetters.Text = "Total number of letters = " & _Pangram.Length.ToString
    
    		'Check for missing letters:
    		For Each ch As Char In _Alphabet.ToCharArray
    			If Not _Pangram.ToString.Contains(ch) Then
    				missingLetters.Append(ch)
    				missingLetters.Append(" ")
    			End If
    		Next
    		TextBox2.Text = missingLetters.ToString
    
    	End Sub
    
    	Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
    		'Save the pangram to a file.
    		Using sfd As New SaveFileDialog
    			sfd.DefaultExt = "txt"
    			sfd.OverwritePrompt = False
    			If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
    				Using sw As New IO.StreamWriter(sfd.FileName, True)
    					sw.WriteLine(TextBox1.Text)
    				End Using
    			End If
    		End Using
    
    	End Sub
    End Class
    I hope this inspires some amusing new pangrams.

    BB

  2. #2
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Pangram Tester

    Nice code, I'll try and make some interesting ones

    Shouldn't you test punctuation as not being in the alphabet, instead of just a specific range? Or use Char.IsPunctuation? (I could decide to use parentheses, you know )

    (Heh, I love this one: "Dwarf mobs quiz lynx.jpg, kvetch!" Perfect newspaper headline.)
    Last edited by minitech; Jul 4th, 2011 at 04:14 PM.

  3. #3

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Pangram Tester

    Quote Originally Posted by minitech View Post
    Nice code, I'll try and make some interesting ones

    Shouldn't you test punctuation as not being in the alphabet, instead of just a specific range? Or use Char.IsPunctuation? (I could decide to use parentheses, you know )
    Youre right, using Char.IsPunctation or Not Char.IsLetter would probably be a better design. But for now I think I'll just edit the punctuation string to include some brackets and quotation marks. After all, we can't allow just anything, can we?

    (Heh, I love this one: "Dwarf mobs quiz lynx.jpg, kvetch!" Perfect newspaper headline.)
    The ultimate: a 26-letter pangram.

    BB

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Pangram Tester

    I tried...
    VBForums, why? Quick! Tzar, placed a jinxed genie!

  5. #5
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Pangram Tester

    Zany shed of quivering tin jukebox wigwams, I clap!
    That's the best I can do so far. 41, no proper nouns.

    In French:

    Jo Paul, ayant ses cinq klaxons de gaz wolofs, m'a vraiment fait du bien hier.
    60. I didn't do so well, and it's a really... odd use of grammatical elements in the middle that kind of hurts.
    Last edited by minitech; Jul 5th, 2011 at 10:48 AM.

  6. #6

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Pangram Tester

    Quote Originally Posted by ForumAccount View Post
    I tried...
    Nice one, ForumAccount. Special VBForums category pangrams, hm...

    Quote Originally Posted by minitech View Post
    That's the best I can do so far. 41, no proper nouns.
    In French:

    60. I didn't do so well, and it's a really... odd use of grammatical elements in the middle that kind of hurts.
    Quivering tin jukebox wigwams? Pure Dadaist poetry, minitech! I was wondering about les pangrammes in French. Do we have to expand the alphabet to include all the accented letters, so there has to be at least one of each accented letter? Or just ignore accents?

    Anyway, here's my latest creation, 32 letters:
    Powder-crazy hex quits Viking film job.
    Has a certain Hollywood decadence, don't you think?

    BB

  7. #7
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Pangram Tester

    I thought accented letters were mostly the same letter, so I left them out. I'd definitely try to add them if w could be left out, though - it's so hard to fit in.

  8. #8
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Pangram Tester

    Haha! 44:

    Quel veuf misanthrope cajoleur de Kenya. Wagon, boxez!

    It makes absolutely zero sense.

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,698

    Re: Pangram Tester

    I stumbled across your Pangram contribution looking for a different contribution of yours altogether and asked myself whether or not I could make the code more concise, this is what I came up with:
    Code:
    Private Function IsPangram(ByVal input As String) As Boolean
        Return input.ToCharArray().Distinct().Where(Function(c) Char.IsLetter(c)).Count() = 26
    End Function
    Essentially it does the following:
    1. Split up the String into a Char array
    2. Keep only unique values
    3. Keep only letter values
    4. Check if the count equals the length of the alphabet
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  10. #10
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Pangram Tester

    Well, that is part of it.
    Doesn't look like it returns which characters are missing, which is important if you're trying to create a pangram.

  11. #11
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,698

    Re: Pangram Tester

    Quote Originally Posted by passel View Post
    Well, that is part of it.
    Doesn't look like it returns which characters are missing, which is important if you're trying to create a pangram.
    True. Then I give you this:
    Code:
    Private Function IsPanagram(ByVal input As String, ByRef missingChars() As Char) As Boolean
        Dim allLetters() As Char = "abcdefghijklmnopqrstuvwxyz".ToCharArray()
        Dim visibleChars() As Char = input.ToLower().ToCharArray().Distinct().Where(Function(c) Char.IsLetter(c)).ToArray()
        missingChars = allLetters.Where(Function(c) Array.IndexOf(visibleChars, c) = -1).ToArray()
    
        Return missingChars.Length = 0
    End Function
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  12. #12
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Pangram Tester

    I figured you would.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width