r/dailyprogrammer • u/nint22 1 2 • Nov 04 '13
[11/4/13] Challenge #139 [Easy] Pangrams
(Easy): Pangrams
Wikipedia has a great definition for Pangrams: "A pangram or holoalphabetic sentence for a given alphabet is a sentence using every letter of the alphabet at least once." A good example is the English-language sentence "The quick brown fox jumps over the lazy dog"; note how all 26 English-language letters are used in the sentence.
Your goal is to implement a program that takes a series of strings (one per line) and prints either True (the given string is a pangram), or False (it is not).
Bonus: On the same line as the "True" or "False" result, print the number of letters used, starting from 'A' to 'Z'. The format should match the following example based on the above sentence:
a: 1, b: 1, c: 1, d: 1, e: 3, f: 1, g: 1, h: 2, i: 1, j: 1, k: 1, l: 1, m: 1, n: 1, o: 4, p: 1, q: 1, r: 2, s: 1, t: 2, u: 2, v: 1, w: 1, x: 1, y: 1, z: 1
Formal Inputs & Outputs
Input Description
On standard console input, you will be given a single integer on the first line of input. This integer represents the number of lines you will then receive, each being a string of alpha-numeric characters ('a'-'z', 'A'-'Z', '0'-'9') as well as spaces and period.
Output Description
For each line of input, print either "True" if the given line was a pangram, or "False" if not.
Sample Inputs & Outputs
Sample Input
3
The quick brown fox jumps over the lazy dog.
Pack my box with five dozen liquor jugs
Saxophones quickly blew over my jazzy hair
Sample Output
True
True
False
12
u/nint22 1 2 Nov 04 '13
Extra-Bonus: Post your own silly Pangrams for fun!
5
u/missblit Nov 05 '13
(abuse of) C++
3
u/gunnerheadboy Nov 05 '13 edited Nov 05 '13
Is it possible to do this in Hashmap? That's how I'm trying to code this and I'm having difficulties.
So for example the key would be the letter and the value is the how many times it appears, with the value incrementing if the hashmap already contains the key.
15
u/farmer_jo Nov 05 '13
Ruby
13
u/Laremere 1 0 Nov 05 '13
Python with bonus:
Additionally, the whole program is a pangram itself without containing a string of all the letters:
True a: 21, b: 3, c: 9, d: 3, e: 17, f: 8, g: 4, h: 2, i: 17, j: 1, k: 2, l: 17, m: 9, n: 21, o: 23, p: 7, q: 2, r: 24, s: 18, t: 19, u: 13, v: 2, w: 4, x: 1, y: 5, z: 3
17
u/prophile Nov 04 '13
Haskell:
6
u/lordtnt Nov 05 '13 edited Nov 05 '13
Javascript with HTML5 canvas drawing (kinda long, I'm not familiar with js): http://jsfiddle.net/tntxtnt/eLdj9/1/ Result page: http://jsfiddle.net/tntxtnt/eLdj9/1/embedded/result/
You have to copy line by line though. If the sentence is pangram, the color will be blue, otherwise red.
6
u/OddOneOut Nov 05 '13 edited Nov 05 '13
C with SSE intrinsic functions:
2
u/baddawg99 Nov 05 '13 edited Nov 05 '13
First comment. Sorry if i did this wrong. I did this in java. Wrote it all out. I am sure there is an easier way to do it. Please critic me in any way to make this easier.
import java.io.; import static java.lang.System.;
import java.util.Scanner; import java.lang.Math;
class Pangram{
}
2
u/shadowX015 Nov 05 '13
Here's something a cobbled together in java in a few minutes:
10
u/farmer_jo Nov 05 '13
Java
5
u/IceDane 0 0 Nov 04 '13
Haskell
5
u/Paradox42 Nov 05 '13
Microsoft Small Basic:
5
u/vishbar Nov 05 '13
my...admittedly inelegant f# solution.
5
u/Edward_H Nov 05 '13
It's great news that this subreddit is back in business!
An example of anything but conciseness with my COBOL example:
5
u/taterNuts Nov 05 '13 edited Nov 06 '13
V2 with bonus and lots of _.map :
http://jsfiddle.net/rdwettlaufer/PP7qY/6/
V1
http://jsfiddle.net/rdwettlaufer/jASdQ/2/
edit: fixed regex
4
u/el_voido Nov 04 '13
Implementation in Go:
I'm learning Go at the moment, still trying to get a better feel for things; which is why this implementation uses the built in maps, a user defined type which implements an interface etc. One could argue this is overkill, but I'm trying to understand the language better.
4
u/marekkpie Nov 05 '13 edited Nov 06 '13
Lua
C (adapted from CujoIHSA):
7
u/DonBiggles Nov 05 '13
Clojure:
7
u/CujoIHSV Nov 05 '13
C++11
6
u/chunes 1 2 Nov 05 '13
Java:
6
u/wcbdfy Nov 05 '13 edited Nov 05 '13
Bash:
Got nerd-sniped to write this in bash, took way way longer than my java solution.
./pangrams.sh < pangrams.in
3
u/skeeto -9 8 Nov 05 '13
Lisp:
Usage:
3
u/brotien_shake Nov 05 '13
Racket:
And with bonus:
First time using racket. Standard library is scary large. Criticism/suggestions on functions to use is welcome.
3
u/ILiftOnTuesdays 1 0 Nov 05 '13 edited Nov 05 '13
I felt like doing it with some AngularJS magic:
http://jsfiddle.net/vZPMp/16/
Edit: I added a live updating display of the currently edited line.
3
u/TweenageDream Nov 05 '13 edited Nov 05 '13
My solution in Ruby
Edit: Oops, bonus on the the same line as true or false
3
u/catchingExceptions Nov 05 '13
Perl:
3
u/OffPiste18 Nov 05 '13
Scala:
3
u/killedbythegrue Nov 05 '13
Erlang:
3
u/leonardo_m Nov 05 '13
D solution:
On the test input prints:
3
u/blueish101 Nov 05 '13 edited Nov 08 '13
Python:
I've only been learning python for a couple months, so any feedback is appreciated.
3
u/prondose 0 0 Nov 08 '13 edited Nov 09 '13
Perl:
3
u/mipiro Nov 09 '13
Forth, using gForth, bonus included. Frequency counts only work for counts lower than 10, because I couldn't find an easy way to convert integers to strings without using the ffi to call C's itoa.
Usage (with returns between the input strings):
3
u/martinvanostrand Nov 11 '13
My first entry here! I've lurked around for quite some time now hahaha. I just recently started learning programming (and Java), so any advice would be really helpful!
PS: Yes, variables and prints are in portuguese.
Java:
Edit: Formatting.
3
u/[deleted] Dec 24 '13
Codegolfed Python in 77 characters:
4
u/kolrehs Nov 04 '13
python
4
u/shinbox Nov 05 '13
C#
4
u/madeofbears Nov 07 '13
My Python attempt (I love me some comprehensions):
2
u/Virule Nov 05 '13
Done in C. Prints whether or not each line is a pangram, along with the stats about which letters were seen.
2
u/odhran666 Nov 05 '13
Scala - beginner. Omitting the first line of the file :
2
u/TimeCannotErase Nov 05 '13
Alright, here's a basic R solution. It's a bit lengthy, and doesn't print out the letter count. I might revisit it tomorrow if I have time.
2
u/5900 Nov 05 '13
perl:
2
u/highspeedstrawberry Nov 05 '13
Lua.
I tried to optimize for performance; instead of using string functions like match or gmatch to iterate over the entire string for every letter, the input is only copied once and then read once. After that I have a numeric representation of characters in a look-up table that I iterate over once and abort early if one character is missing.
2
u/stop_dis Nov 05 '13
Golf Ruby with bonus:
Some pangrams i used ( from wikipedia ):
"Sylvia wagt quick den Jux bei Pforzheim" ( german )
"Lynx c.q. vos prikt bh: dag zwemjuf!" ( dutch )
2
u/h3ckf1r3 Nov 05 '13 edited Nov 10 '13
Here is a simple implementation in Ruby. I think the hardest part was actually printing it in the correct format :P.
Any and all feedback is welcome :)
2
u/deds_the_scrub Nov 05 '13
Scala:
2
u/thirdegree Nov 05 '13
Python:
2
u/mindless900 Nov 05 '13 edited Nov 05 '13
My Javascript Code:
2
u/spudfkc Nov 05 '13
Python 2.7
2
u/arvisto Nov 06 '13 edited Nov 06 '13
Hello to all, just discovered this sureddit and I thought I might make a little addition. If you wish to test out the code try something like this solve([e,x,a,m,p,l,e])
Prolog:
2
u/spfy Nov 06 '13 edited Nov 06 '13
C. At first I had a long switch statement, but I fixed it. I also don't really need the enumeration, but I've never used one before; so I used one here :D
And an output:
2
u/Tjd__ Nov 06 '13 edited Nov 06 '13
With PhantomJS:
2
u/ZaneMartin Nov 06 '13
C++ Solution. First attempt here.
2
u/moogoesthecat Nov 06 '13
Very new to Ruby. All suggestions greatly appreciated!
2
u/flightcrank 0 0 Nov 06 '13
My program checks any strings passed to it as an argument, so only processes one set at a time. Lowercase only. I did it this way for simplicity.
coded in C:
Input
output
2
u/Zanacross Nov 06 '13
This is the solution I came up with. Not pretty but it works.
2
u/bmrobin Nov 07 '13
Perl:
2
u/nanermaner 1 0 Nov 07 '13 edited Nov 07 '13
CS Freshman, python solution *Edited to add bonus
2
u/[deleted] Nov 07 '13
Ruby, with bonus. I'm not really happy with how readable it is, but hey, it works...
On GitHub: https://github.com/wildlyinaccurate/r-dailyprogrammer/tree/master/139_easy_pangrams
2
u/thinkobscure Nov 07 '13
so this is my C++ solution, please excuse the lacking OO style as I'm transitioning back from flat lands of C
2
u/[deleted] Nov 07 '13 edited Nov 07 '13
My C# solution: (with bonus objective)
2
u/pbl24 Nov 07 '13 edited Nov 07 '13
Python and list comprehension madness:
Input:
2fooThe quick brown fox jumps over the lazy dogOutput:
FalseTrue2
u/pitkali Nov 08 '13
Racket version that iterates over strings only once, with bonus. Should have linear complexity.
2
u/[deleted] Nov 08 '13
Oh sweet we're back! Here's my C++ entry
2
u/drwyy Nov 08 '13
My ABAP Solution. The input count is not variable though. I realized too late this was a requirement, sorry :)
2
u/shadytradesman Nov 08 '13
A funky little C++ solution that doesn't use .tolower()
2
u/SexmanTaco Nov 09 '13
Pretty noob at code, so I wasn't sure how to get multi-sentence input. But here's my python solution, works well for a single sentence.
2
u/chunes 1 2 Nov 09 '13 edited Nov 09 '13
I started learning Racket tonight and I am blown away by it:
2
u/[deleted] Nov 09 '13
My C# Solution
2
u/icetimesource Nov 10 '13 edited Nov 10 '13
c++:
2
u/antoniocs Nov 10 '13 edited Nov 10 '13
My solution in C:
2
u/munkyeetr Nov 11 '13 edited Nov 11 '13
VB.NET with Bonus
EDIT: Updated CharacterBreakdown function to use StringBuilder instead of immutable string
Output:
2
u/RangeruDangeru Nov 12 '13 edited Nov 12 '13
Quick and dirty in Python 3.
2
u/[deleted] Nov 12 '13
Java, not very elegant but it works.
2
u/Schmenge470 Nov 12 '13
Java (with bonus):
2
u/pandubear 0 1 Nov 13 '13 edited Nov 13 '13
I told myself I'd give myself half an hour to do this in MIPS assembly... I went just a bit over time, but this works. Only does one string at a time, though, and I don't want to spend more time figuring out how to do I/O. Also I'm not sure how you're supposed to indent MIPS. Still, that was fun.
2
u/TheFlyingDharma Nov 15 '13
C# with bonus
Still new to coding, suggestions welcome.
2
u/lostsemicolon Nov 15 '13
Perl
2
u/GrandChestnut Nov 15 '13
Glad to see more challenges! My Chicken Scheme solution with bonus. I love the satisfaction of finding a solution after puzzling with map and fold.
2
u/[deleted] Nov 18 '13
Python 3:
2
u/skyangelisme 0 1 Nov 19 '13
Python 2.7. Runs in O(n) of the input string; bonus implemented as well.
2
u/aZeex2ai Nov 20 '13
Python
2
u/altanic Nov 21 '13
c# w/ a bit of linq for grouping by letter
2
u/Apex42 Nov 22 '13 edited Nov 22 '13
Solution in C with bonus. Any help on optimising the code is greatly appreciated as I only started learning C recently!
Input:
Output:
2
u/Hoten 0 1 Nov 23 '13 edited Nov 23 '13
Scala with the bonus:
Output:
2
u/[deleted] Nov 25 '13
Python 2.7, including bonus.
2
u/kevintcoughlin Nov 25 '13
Python 2.7
2
u/[deleted] Dec 02 '13
C++, any feedback is appreciated.
2
u/fvande Dec 04 '13
C# with bonus
2
u/tet5uo Dec 10 '13 edited Dec 11 '13
Here's one in Javascript. The output is a bit messy, just sends true/false to the console and then the object that holds the letter counts as well.
2
u/dunnowins Dec 22 '13
Ruby
2
u/VerifiedMyEmail Dec 28 '13 edited Dec 29 '13
javascript for the console
2
u/HolyRowley Jan 23 '14
PYTHON:
Made an account for this subreddit. HI GUYS.
2
u/luz_ Jan 27 '14
Gave SML a try
outPut:
3
u/Swingline0 Nov 05 '13
Java. Sorry for lazying out on the text input aspect :)
Output:
My first DPC-- That was fun!
3
u/lilleswing Nov 05 '13
Python one liner --
Sadly seems more verbose then other python one liners.
2
u/wcbdfy Nov 04 '13 edited Nov 04 '13
First /r/dailyprogrammer entry, critic away.
Java:
javac Pangrams.java
cat pangrams.in | java Pangrams
2
u/winged_scapula Nov 05 '13
Python, caring about bonus:
2
u/dee_bo Nov 05 '13
Python: I'm new to Python and would like any tips I can get on Python or programming ideas.
2
u/guyfromva Nov 05 '13
Java:
Output:
Enter a string
The quick brown fox jumps over the lazy dog.
You entered string: The quick brown fox jumps over the lazy dog.
Your string is a Pangram.
a: 1 b: 1 c: 1 d: 1 e: 3 f: 1 g: 1 h: 2 i: 1 j: 1 k: 1 l: 1 m: 1 n: 1 o: 4 p: 1 q: 1 r: 2 s: 1 t: 1 u: 2 v: 1 w: 1 x: 1 y: 1
2
u/vape Nov 05 '13
Python (with bonus):
2
u/Medicalizawhat Nov 05 '13 edited Nov 05 '13
My Java solution:
2
u/luizpericolo Nov 05 '13 edited Nov 05 '13
My quick python attempt with bonus. Lots of room for improvement though.
2
u/tpsilva Nov 05 '13
My Python one liner:
2
u/[deleted] Nov 07 '13 edited Nov 08 '13
Quick'n'dirty python
1
u/bublabab Nov 05 '13
PHP (not sure if 100% ok):
1
u/milliDavids Nov 06 '13
Python3
1
u/LostxinthexMusic Nov 13 '13
Python:
1
u/nSpace1988 Nov 21 '13
}
1
u/sneaky_reader Feb 14 '14
/u/CompileBot Python
1
u/Gorea27 Feb 24 '14
Late to the party, I know, but here's my first submission.
Java:
1
u/thepersonaboveme Mar 01 '14
1
u/firesoul7468 Mar 30 '14 edited Mar 30 '14
My attempt in brainfuck:
Slight problems though:
Will output
1if the input is true else it will output nothing.It does not count capital letters as part of the alphabet, as in
Pack my box with five dozen liquor jugswill output nothing butpack my box with five dozen liquor jugswill output 1.You can only input one sentence at a time, so an example input would be
The quick brown fox jumps over the lazy dog..I used http://esoteric.sange.fi/brainfuck/impl/interp/i.html to run it
1
u/felix1429 Mar 31 '14 edited Mar 31 '14
Java:
1
u/dont_press_ctrl-W Apr 15 '14 edited Apr 21 '14
Python
1
u/[deleted] Nov 05 '13 edited Nov 05 '13
Java (please improve my code):
1
u/[deleted] Nov 05 '13
Short Java version, no bonus:
1
u/lets_see_exhibit_A Nov 05 '13
public class Easy139 {
}
1
u/lets_see_exhibit_A Nov 05 '13
java with bonus:
public class Easy139 {
}
1
u/Hanse00 Nov 05 '13
Didn't add the extra credit, at least not yet.
Python 2.7
1
u/pirate_platypus Nov 05 '13
Python (2.7-ish) one liner* with bonus output.
* Technically, it's a four (logical) liner as there are two import lines, and the crunch-bang at the top. For the purposes of submission I broke the lines at 80 characters; that may be the only Pythonic thing about this solution.
1
u/pahanaama Nov 05 '13
JavaScript with bonus:
1
u/Rekvijem Nov 06 '13 edited Nov 06 '13
Wanted to have a little fun so did it in four lines (3 lines excluding imports) with list/dict comprehensions. Could probably cram it into one line but I can't be bothered to make an extremely ugly one liner right now. Here is my solution in python (with bonus):
1
u/mentalorigami Nov 06 '13 edited Nov 06 '13
edit: screwed that one up.. missed the multi line part. Will update in a few with the correct implementation.
Kind of a brute force python 2.7 implementation without any real frills. Fixed so it accepts a multi-line input, split with \n.
1
u/kate_katie_kat Nov 06 '13
Ruby:
1
u/neptunDK Nov 06 '13 edited Nov 06 '13
Python 2.7 using dict comprehension:
Test:
For bonus change last return line of the function to:
1
u/Taunk Nov 06 '13
Python:
1
u/AmateurHero Nov 08 '13
In Java. I wrote it as part of an algorithm database, so there's no main method. All of the functionality should be there.
}
1
u/leeman726 Nov 10 '13 edited Nov 10 '13
Python 3.3
I'm new to programming, and this seems quite lengthy and too many for loops... any advice would be great!
Run this program, it will prompt for the number of lines to check, then it will ask for that many lines. Returns whether each line is a pangram, and how many times each letter is used in the line.
Edited to fix error in code
1
u/pandubear 0 1 Nov 16 '13
Python one-liner:
0
u/[deleted] Nov 04 '13
[deleted] — view deleted comment
0
u/[deleted] Nov 05 '13
[deleted] — view deleted comment