r/dailyprogrammer • • Oct 20 '14
[10/20/2014] Challenge #185 [Easy] Generated twitter handles
Description
For those that don't tweet or know the workings of Twitter, you can reply to 'tweets' by replying to that user with an @ symbol and their username.
Here's an example from John Carmack's twitter.
His initial tweet
@ID_AA_Carmack : "Even more than most things, the challenges in computer vision seem to be the gulf between theory and practice."
And a reply
@professorlamp : @ID_AA_Carmack Couldn't say I have too much experience with that
You can see, the '@' symbol is more or less an integral part of the tweet and the reply. Wouldn't it be neat if we could think of names that incorporate the @ symbol and also form a word?
e.g.
@tack -> (attack)
@trocious ->(atrocious)
Formal Inputs & Outputs
Input description
As input, you should give a word list for your program to scout through to find viable matches. The most popular word list is good ol' enable1.txt
/u/G33kDude has supplied an even bigger text file. I've hosted it on my site over here , I recommend 'saving as' to download the file.
Output description
Both outputs should contain the 'truncated' version of the word and the original word. For example.
@tack : attackThere are two outputs that we are interested in:
- The 10 longest twitter handles sorted by length in descending order.
- The 10 shortest twitter handles sorted by length in ascending order.
Bonus
I think it would be even better if we could find words that have 'at' in them at any point of the word and replace it with the @ symbol. Most of these wouldn't be valid in Twitter but that's not the point here.
For example
r@@a -> (ratata)
r@ic@e ->(raticate)
dr@ ->(drat)
Finally
Have a good challenge idea?
Consider submitting it to /r/dailyprogrammer_ideas
Thanks to /u/jnazario for the challenge!
Remember to check out our IRC channel. Check the sidebar for a link -->
5
u/madkatalpha Oct 21 '14 edited Oct 21 '14
Because C# is always fun:
3
u/dohaqatar7 1 1 Oct 20 '14 edited Oct 22 '14
Haskell
Output
I ran my code on a list of every Pokemon. None start with "at", but I got some results for the extra.
I also ran it on the traditional enable1.txt.
I found a huge list of words
Just for fun, I ran it on a list of names; although, looking at the output, some of these don't look a whole lot like names.
60
u/13467 1 1 Oct 20 '14
Unix one-liner:
10
u/jnazario 2 0 Oct 20 '14 edited Oct 21 '14
hey, cool! it's my challenge! and here's my F# solution
9
u/Reverse_Skydiver 1 0 Oct 20 '14 edited Oct 21 '14
Quite a short version done in Java:
Here are the methods from the "Library" class if you're interested:
readfromfile:
sortbylength:
toStringArray:
printArray:
7
u/McDirty84 Oct 20 '14 edited Oct 20 '14
python 2.7 I decided this would be a fun exercise in chaining a fat list comprehension together. I used the larger textfile from /u/G33kDude and do an output from enable1.txt seperately Also I added a clarification/rule
I ran out of time to do regular at words, which can just be a simpler version of the list comprehension. So here it is yall.
Output from wordlist.txt
Output from enable1.txt
6
u/marchelzo Oct 20 '14
Here is my Haskell solution. I made it omit words where the "at" is followed by an "e", because they are typically pronounced differently than "@".
6
u/Hawk_Irontusk Oct 20 '14 edited Oct 20 '14
Perl easy version one liner:
5
u/petethemonkey Oct 21 '14 edited Oct 21 '14
Ruby
3
u/[deleted] Oct 20 '14 edited Oct 20 '14
Lua (bonus only, in lexical order):
Output:
3
u/ddsnowboard Oct 21 '14
Python 3.4
I did the bonus and returned both the longest and the shortest. Any comments are appreciated. Also, if someone could shed some light on the "sort(key = len)" line for me, that would be nice. I found that somewhere to sort the list by length, but I don't quite understand how it works. Is key supposed to be a function that is called with the item as its argument for each item?
Output from output.txt:
2
u/[deleted] Oct 20 '14
Okay so I think I have managed to do this one already which for me is a record. Done it in Java, any feedback would be hugely welcome. I am studying software dev and trying to do little tasks to practice some skills.
2
u/R3C Oct 21 '14
Python 3. My first challenge
Output with enable1.txt
2
u/robotreader Oct 21 '14
The key here is obviously that not every "at" pair is pronounced correctly. Fortunately, CMU has a pronunciation dictionary. http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict.0.7a (note that as a pronunciation dictionary, it is capable of having a different pronunciation than the one you use and still being right.)
This method filters out false positives like "ate" while allowing words like "staten" which /u/marchelzo does not.
Ruby solution below. Let's not discuss how long it took me to get the lists right, shall we?
Output:
The ideal dictionary would really be in IPA, but I couldn't find one.
2
u/VietOne Oct 21 '14
C# Solution doing both the original and bonus. Included comments by habit
Feedback is welcome
Optimizations
Lists only sorted once in descending order. Top 10 are longest, bottom 10 are shortest. To get shortest, simply skip all but the last 10 while checking to make sure there are more than 10 entries. Runs slightly faster than making both a descending and ascending list in my testing.
Improvements
Both the challenge to begin with "at" and any location of "at" has been made to be case-insensitive
2
u/lazydancer Oct 21 '14
Javascript (nodejs) with large function chain
1
u/G33kDude 1 1 Oct 20 '14
Here we go! Bonus done in AutoHotkey. I take advantage of the built in sorting of our object keys. I'll update it in a bit with the normal challenge too.
enable1 output and 6mb word list I had on hand
Edit: Now does both challenges.
1
u/Zwo93 Oct 20 '14 edited Oct 21 '14
First submission, it's not very pretty but it works
Edit: Python 2
EDIT 2: Thank you to /u/ddsnowboard (not on my post) here's an updated version. I've just been using python for a couple class assignments, so this has been very helpful
I'll leave the older version to show the change
1
u/Ddiflas Oct 20 '14
My solution, using C#:
Criticism or suggestions are more than welcome.
1
u/Garth5689 Oct 20 '14
Python 3:
Output:
Bonus:
1
u/chocolate4tw Oct 20 '14
hello, first challenge for me.
written in c++ including the bonus:
1
u/Maping Oct 21 '14
Java
This works, but is slow. How long should the bigger file you provided be taking? My program takes about 5 seconds to run.
(Note: enter 1 for the bonus, 2 for the normal version.)
}
And the output:
Shortest:
@ony : atony
@rip : atrip
@ilt : atilt
@oll : atoll
@ria : atria
@tar : attar
@one : atone
@tic : attic
@oms : atoms
@las : atlas
Longest:
@temptabilities : attemptabilities
@herosclerosis's : atherosclerosis's
@rabiliousness's : atrabiliousness's
@rabiliousnesses : atrabiliousnesses
@tributiveness's : attributiveness's
@tributivenesses : attributivenesses
@titudinarianism : attitudinarianism
@tractableness's : attractableness's
@herosclerotically : atherosclerotically
@titudinarianism's : attitudinarianism's
1
u/your_distant_cousin Oct 21 '14
In Rust, reading input from stdin. I decided to sort the bonus words by frequency of "at". I would have liked to extract the print loops into a function taking a generic Iterator, but couldn't get it to compile.
And the output:
1
u/hutsboR 3 0 Oct 21 '14 edited Oct 21 '14
Dart:
Output:
1
u/dkhaburdzania Oct 21 '14
my ruby solution
1
u/thorwing Oct 21 '14 edited Oct 21 '14
JAVA
OUTPUT
1
u/Jberczel Oct 21 '14
ruby solution:
1
u/csharpminer Oct 21 '14
C# solution. 2 methods heavily influenced by /u/Ddiflas
First solution and it didn't turn out at all like how I imagined.
Feedback/criticism welcomed
1
u/crabfish10 Oct 21 '14
python 2.7. Kind of clumsy, but it works.
bonus
1
u/Dutsj Oct 21 '14
A bit late, but here is my Java solution, making intensive use of the java streams api and lambdas that were introduced in java 8.
1
u/artless_codemonkey Oct 21 '14
Quick Python implementation with ListComprehension
1
u/cooper6581 Oct 21 '14
Go
1
u/giraffe_laugh Oct 21 '14
1
u/YuEnDee14 Oct 21 '14
Here's my solution in C#:
https://gist.github.com/YuEnDee14/135338a124293d13a10e
Linq functions made this challenge pretty easy, and I think going for the bonus of words containing "at" actually was made easier by the Linq "Contains" function, as well. If I have time, I'll go back over this in another language that doesn't have built-in functions like that and try to come up with a more novel solution.
As always, though, any feedback is welcomed and appreciated!
1
u/frozensunshine 1 0 Oct 22 '14
Yay got it running. C99.
Outputs:
a@: aat
r@@ouille: ratatouille
@tack: attack
@: at
r@ic@e: raticate
dr@: drat
@aa: ataa
@b: atb
@cca: atcca
@ccb: atccb
@ccc: atccc
@ccd: atccd
@cce: atcce
@ccf: atccf
@ccg: atccg
@cch: atcch
@cci: atcci
@ccj: atccj
@cck: atcck
fix@e: fixate
Also, since this is one of those rare times, my
valgrindoutput-==21432== HEAP SUMMARY: ==21432== in use at exit: 0 bytes in 0 blocks ==21432== total heap usage: 1 allocs, 1 frees, 568 bytes allocated ==21432== ==21432== All heap blocks were freed -- no leaks are possible ==21432== ==21432== For counts of detected and suppressed errors, rerun with: -v ==21432== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)1
u/mongreldog Oct 22 '14 edited Oct 22 '14
F#
1
u/[deleted] Oct 22 '14 edited Oct 22 '14
A C++ solution. For an added challenge:
typedeffor readability.#defined values.No explicit loops. (But one
for_eachfunction call. Only one, though.)1
u/tuvok302 Oct 22 '14
The power of powershell compels you. % is an alias for foreach, and $_ is object in the pipeline. I'm fairly certain with a bit more work I could've just made this two lines, creating the empty array (I've found Powershell to be... poor... at picking what type of list I want in the past) and everything else.
1
u/arachnist Oct 22 '14
Ruby
1
u/[deleted] Oct 22 '14 edited Oct 22 '14
Python 2.7 solution- feedback always appreciated!
1
u/[deleted] Oct 22 '14
I'm a little late but here is my attempt in Python:
Output:
Can anyone tell me why i needed the 16 in the last "for" of my code to output 10 items in reverse? I achieved this by trial and error.
1
u/dyslexic_captcha Oct 23 '14
C# First post and first attempt at C#. Feedback is welcome, I haven't programmed in a long while.
1
u/[deleted] Oct 24 '14 edited Oct 24 '14
Here's mine, done in Python3 and using
WordList.txt. I changed it a little bit, also replacing 'att' with '@' (since there's no difference in how you'd pronounce '@tack' and '@ack'), and also getting rid of the possessives (e.g. words with a'in them).And my results:
And to answer the bonus question:
Results:
Feedback welcome!
1
u/[deleted] Oct 24 '14 edited Oct 25 '14
python3 in one line:
output:
bonus:
output: (kinda boring, none of these contains 2 or more "at")
1
u/qlf00n Oct 25 '14
Python, just started learning, feedback is very welcome:
import re
The output:
1
u/Zarimax Oct 28 '14 edited Oct 28 '14
C++11
My first submission and my first time using C++ since college. Looking at some of the other solutions, this is probably one of the most cumbersome.
1
u/[deleted] Oct 28 '14
I realize this is way late but I am new here and this is my first submission.
I wrote it in java:
I believe this is O( n2 ) complexity because of the sorting algorithm I ran but I'm not 100% sure. If anyone is still on this thread, am I correct?
Solution: I only did the bonus for now. I may come back tonight and finish. I believe instead of checking to see if it contains, I just need to check the first 2 letters of substring.
1
u/RangeruDangeru Oct 30 '14
Super late, Python 2.7
1
u/Unh0ly_Tigg 0 0 Oct 31 '14
Really late entry, Java 8 (stream api + lambdas + nio)
1
u/dorncog Nov 06 '14 edited Nov 06 '14
node.js
1
u/_ewan Nov 10 '14
Python
It's been a while, so feedback is welcome!
1
u/[deleted] Nov 16 '14
Ruby, less than 300 characters (Programmer Trigger Warning: Ugly code): https://gist.github.com/oGabrielMarques/53fe9949c3e92cbc8f15
1
u/silverfox17 Nov 17 '14 edited Nov 17 '14
Shortest 10, longest 10, "at" replaced with @ PYTHON:
1
u/iamnotacrazyperson Nov 24 '14
Super late, but I did it so here it is. First thing I've ever written in PHP:
1
u/katysdayout Jan 04 '15 edited Jan 04 '15
In python
1
u/the_dinks 0 1 Jan 08 '15
python 2.7
1
u/OOPSItsJava Jan 25 '15
package Hello;
import javax.swing.JOptionPane;
public class GeneratedTwitter {
}
I know it's 3 months old but I wanted to feel apart of something :'(
1
u/Matt4885 Jan 28 '15
I'm a little bit behind, but since I'm somewhat new to programming I'd figure I would take a shot at it. If anyone has constructive criticism please let me hear it.
Implementation in C:
1
u/lewisj489 0 1 Mar 16 '15
C#, Had lot's of fun with this. Tried a few ways, this is my shortest.
1
u/[deleted] Oct 20 '14 edited Oct 21 '14
Python 2:
Output (shortened):
The variable match_start_only can be set to False to match the pattern in the entire string. You can also choose a completely different pattern (finding 'and' and replacing it with '&' for example).
Pretty happy with the result, but comments are appreciated. One thing I'm not satisfied with is using search with ^pattern instead of start with just the pattern, but I couldn't think of a neat way to put that in the code.
Edit: whoops, forgot to look at the output description. Sorted the handles and then used slices to get the first and last 10 items.
Edit2: made a mistake with the slices, fixed it now.
0
u/rdpascua Oct 26 '14
PHP:
0
u/[deleted] Oct 20 '14
[deleted] — view deleted comment
0
u/[deleted] Oct 21 '14
[deleted] — view deleted comment
1
u/[deleted] Oct 28 '14
[removed] — view removed comment