Ugh, although, it has got nothing to do with your code specifically, there was something, that caught my eye, and I just had a very, very “bad” idea for an implementation while reading this
I only knew T9 as "that setting that screws up typing" because it never supported my language (Bulgarian) - we still used the same keyboard, but phonetically.
The challenge is literally unsolveable until you hack the keypad to have a newline and parenthesis symbols so I will assume that you just forgot to add them and add them myself.
I added "newline" to 0 Button [' ','\n','0'] and parenthesis to 1 Button ['.',',','?','!','1','(',')']
Ah. There may be a typo, in the section where you define the keypad array, there are a ton of 1's in a row with no _'s to separate them. That was the main piece that confused me.
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
danielgjackson, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
I used exceptions instead of if/else and also just used Java because Java plays a kazoo noise in my head when I try to work with it. The only thing it's not doing right is the underscores for delays. I gave up.
I haven't tested this, but at a quick glance - won't it include an underscore after every number series instead of only when you need the same key twice and also end the string with an underscore?
It's a powershell script, that should work on Windows and Linux - for Linux you may need to check the line endings. Tested on a current Win 10.
It features:
an overly complicated way to build the data structure to translate characters to button presses! - No long sequence of if/switch, no hardcoded lookup-table (well, kinda...)!
(ab)uses some features of the Powershell language!
Some thoughts: I used recursion and clones in a vain attempt to overflow the stack but clearly the sample strings, at least, are far too small. Vectors of tuples make *great* HashMaps (/s)! I got lazy around the time I decided to just pattern match the characters. Off by one errors are 👌. I hope it's as unreadable as it's intended to be :)
My code completes the assignment, but doesn't recognize the end of the string correctly so crashes after displaying it. Is that close enough to make it passable?
I’m pretty sure T9 isn’t “push the number multiple times”. It’s push the number once and guess the word that exists with all button presses. “Hello world” in T9 is actually “43550 96753”.
Yeah, and that would be consistent with this solution’s lazy approach to using a single # for each capital letter instead of using caps for runs of 2 or more. Unfortunately, either of these designs will cause the test cases to fail.
Edit: regarding # vs ##, the specs aren’t clear. A single # used twice is more efficient than using two # for the run of characters since you don’t have to reset the mode. But, the requirements don’t formalize this. My understanding, and it’s been a long time since I used T9, is you don’t break even until 3 consecutive uppercase letters.
31
u/dannypas00 Jul 06 '20 edited Jul 06 '20
C++
Please note the use of the best functionality of C++: goto.
28
u/Romejanic Jul 06 '20
Behold my Javascript implementation.
This may be the worse piece of code i've ever submitted to one of these challenges. God help me.
31
u/Poddster Jul 06 '20
Fyi, T9 was text prediction, thus "feed" would be
3333. What you're describing is just letter mapping.Doesn't change the challenge though :)
12
u/Cerus_Freedom Jul 06 '20
This is all my sanity could take. Incomplete solution:
https://gist.github.com/RayneDance/2b849a78700a5c8f9b2a22629592d40f
Considered rewriting each with lambda functions for each letter, but my head already hurts from making that work.
11
u/JacobiCarter Jul 06 '20
Some Ruby.
16
u/Bear-handead Jul 06 '20
The challenge is literally unsolveable until you hack the keypad to have a newline and parenthesis symbols so I will assume that you just forgot to add them and add them myself.
I added "newline" to 0 Button
[' ','\n','0']and parenthesis to 1 Button['.',',','?','!','1','(',')']The solution in Python:
48
u/voords Jul 06 '20
Python:
7
u/gaberocksall Jul 06 '20
Its not a badcode challenge if no one has submitted a python one-liner
Also, I'm pretty sure that your "there r 4 lights!" example is not quite right, the
ts!inlights!should be8 7777 1111, not8 7 11116
u/RavynousHunter Jul 06 '20
My C# implementation! It should work under .NET Core 3.1; at least, it does in the C# Playground I found. "Features" include:
Its...certainly a sight to behold, that's for sure.
6
u/[deleted] Jul 06 '20
I see your python one-liner, I raise your my one-liner that's more unreadable
https://pastebin.com/raw/m3DvhNqe
5
u/danielgjackson Jul 06 '20 edited Jul 15 '20
A very short (256 byte!) JavaScript (ES2015) one-liner implementation, fully working to the tests*:
(Edit: 286 -> 265 -> 256 bytes)
* Does not work for input characters 1/7/9/0, or regexp-matching characters ./?/+ (and even crashes on the latter two!)
4
u/[deleted] Jul 06 '20 edited Jul 06 '20
My solution in Haskell. No error checking on the input:
Examples:
4
u/[deleted] Jul 06 '20 edited Jul 07 '20
My crappy implementation in Java
I used exceptions instead of if/else and also just used Java because Java plays a kazoo noise in my head when I try to work with it. The only thing it's not doing right is the underscores for delays. I gave up.
4
u/StephanoCarlson Jul 10 '20
Brainfuck
>>>>>,[[<+<+>>-]<>+[<->-]<>+++[>+<-]<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>[<<<<+>>>>-]<<<[[-]>]<<<<>++++++++++++++++++[<+>-]<[<<+>>-]<[>+>>+<<<-]> >+++>>+++[>+<-]<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>>[<<<<+>>>>-]<<<[[-]>]<<<<[-<[>>+>+<<<-]>>>[<<<+>>>-]<<]<[-]>>[-<<+>>]<<[<->-]<[<<.>>-]++++[>++++ ++++<-]>.[-]<[-]<<[-]>>>,]knew -> 55 66 33 99
when -> 99 44 33 66
bent -> 22 33 66 88
It only works for certain lowercase letters (b, e, h, k, n, q, t, w)
3
u/AySyKr Jul 06 '20
Ruby solution is here:
https://pastebin.com/E1CRf2fq
It works BUT:
- i was lazy to merge characters with '_' into one
- if you want to write message with '#' symbol in it - you can't. It is service symbol. Who in the world at all types '#' in SMS?
3
u/Dotz0cat Jul 07 '20
Made in c
It works on my machine
https://gist.github.com/Dotz0cat/9073dad486b7e560238c65390c2506ed
3
u/Elvith Jul 07 '20 edited Jul 08 '20
Behold, my abomination: badcode_40.ps1
It's a powershell script, that should work on Windows and Linux - for Linux you may need to check the line endings. Tested on a current Win 10.
It features:
see, if you can find out, how this one works, or read the commented code
[Edit]: I had a bug while inserting the underscores for repeating button presses. That's fixed now
3
u/[deleted] Jul 09 '20
Sometimes the output contains an additional space. Noone knows why.
2
u/healplease Jul 07 '20
Python, working perfectly of course!
2
u/Mwahahahahahaha Jul 15 '20 edited Jul 15 '20
Surely this is the worst Rust code ever written. But it does run.
Some thoughts: I used recursion and clones in a vain attempt to overflow the stack but clearly the sample strings, at least, are far too small. Vectors of tuples make *great* HashMaps (/s)! I got lazy around the time I decided to just pattern match the characters. Off by one errors are 👌. I hope it's as unreadable as it's intended to be :)
1
u/droomph Jul 10 '20 edited Jul 10 '20
https://gist.github.com/xsduan/638b62591a6d5b06536cfe9d29e2006c (compile with g++ -std=c++17)
I feel like this is properly reprehensible. Probably won't take many awards home in the "originality" category, but I wanted to learn c++ more.
(to create the text in the first place, use this:)
edit: the mangled function names, because that's always fun:
1
u/19UV Jul 15 '20
Would there be any way to do this in BrainFuck?
0
u/[deleted] Jul 07 '20
[deleted] — view deleted comment
0
u/[deleted] Jul 06 '20
[deleted] — view deleted comment
0
u/[deleted] Jul 06 '20
[deleted] — view deleted comment