r/dailyprogrammer • u/jnazario 2 0 • Jul 18 '16
[2016-07-18] Challenge #276 [Easy] Recktangles
Description
There is a crisis unfolding in Reddit. For many years, Redditors have continued to evolve sh*tposting to new highs, but it seems progress has slowed in recent times. Your mission, should you choose to accept it, is to create a state of the art rektangular sh*tpost generator and bring sh*tposting into the 21st century.
Given a word, a width and a length, you must print a rektangle with the word of the given dimensions.
Formal Inputs & Outputs
Input description
The input is a string word, a width and a height
Output description
Quality rektangles. See examples. Any orientation of the rektangle is acceptable
Examples
Input: "REKT", width=1, height=1
Output:
R E K T E K K E T K E RInput: "REKT", width=2, height=2
Output:
T K E R E K T K E K E K E R E K T K E R E K E K E K T K E R E K T
Notes/Hints
None
Bonus
Many fun bonuses possible - the more ways you can squeeze REKT into different shapes, the better.
- Print rektangles rotated by 45 degrees.
- Print words in other shapes (? surprise me)
- Creatively colored output? Rainbow rektangles would be glorious.
Credit
This challenge was submitted by /u/stonerbobo
Finally
Have a good challenge idea?
Consider submitting it to /r/dailyprogrammer_ideas. Thank you!
4
u/mtk4000 Jul 18 '16
You need to escape the asterisks in sh*tpost. They're italicizing text.
27
u/lukz 2 0 Jul 18 '16 edited Jul 19 '16
Z80 Assembly
This one didn't feel too easy as I had to move in the screen space in four different directions and also keep track of if I need to print the original word or the reversed word. But finally it works.
On input, enter two digits signifying the width and the height, then space, then your input word. The program will clear the screen and draw the rectangular pattern. The program size is
114bytes. It will run on Sharp MZ-800 computer.Screenshot
Update: The program size is now 112 bytes.
16
u/kamaln7 Jul 18 '16
I wrote something similar the other day, though it's not exactly what the original challenge is:
source:
6
u/a_Happy_Tiny_Bunny Jul 18 '16
Haskell
No bonuses.
6
u/monkeyx9 Jul 19 '16 edited Jul 19 '16
This was my shitty failed attempt at a version in brainfuck. I quickly realized why it is called brainfuck..
here is just a basic rektangle with comments for your shitposting pleasure
and here it is in classic Brain fuck
+/u/CompileBot Brainfuck
4
u/Yammerrz Jul 18 '16 edited Jul 18 '16
Python3 - Pretty short and sweet
Output:
4
u/roydl7 Jul 19 '16 edited Jul 19 '16
C89
My first post here, any feedback is welcome!
Output:
3
u/syholloway Jul 18 '16
PHP
No Bonus this time. finally found a use for a php generator though.
invoke with:
3
u/pulpdrew Jul 19 '16 edited Jul 19 '16
Java Solution. It's quite long as I found this one pretty challenging. I'd be grateful for any suggestions you might have. It doesn't implement any bonus, but it does work for any reasonable input.
edit: I made it a little shorter and cleaner with the use of some StringBuilders.
}
3
u/voi26 Aug 22 '16 edited Aug 27 '16
I doubt anyone will ever see this considering it's a month old at this point, but it's the first one that I did that I got stuck on and managed to complete by myself, so I thought I would post it. I also want to become comfortable with putting things out there.
It's in C#. Any advice on how to improve that and make it a bit less ugly would be appreciated.
2
u/SethDusek5 Jul 18 '16
Can you post an example with width=3, height=3? And also a rectangle
2
u/El_Dumfuco Jul 18 '16 edited Jul 18 '16
Matlab:
2
u/[deleted] Jul 18 '16
Crystal, no bonus:
Play: https://play.crystal-lang.org/#/r/149j
Rainbow bonus: https://play.crystal-lang.org/#/r/149i
2
u/[deleted] Jul 18 '16 edited Jul 18 '16
Swift 3.0
No bonuses (yet). Since the text kinda oscillates, I chose to just use the sin function to work out the correct values.
I use a temporary 2D array make formatting the final output a bit easier.
[edit] Xcode project on GitHub https://github.com/notronik/rektangle-shitpost-generator
Invoked on the command line with arguments <word> <width> <height>
Code
Output
4x3 CENA
10x100 REDDIT
http://pastebin.com/raw/tLtfeKC5
2
u/netbpa Jul 18 '16
Perl6 no bonus
2
u/glenbolake 2 0 Jul 18 '16
Python 3 with a fun little animation.
2
u/jhubbardsf Jul 18 '16
Ruby
No bonuses.
2
u/a_Happy_Tiny_Bunny Jul 19 '16
C89
2
u/CorrectMyBadGrammar Jul 19 '16 edited Jul 19 '16
C99. My hacky solution is based on the observation that i-th letter in the first row is the same as the first letter in the i-th row.
OUTPUT:
2
u/Scroph 0 0 Jul 19 '16 edited Jul 19 '16
This challenge broke something inside my brain. I somehow managed to solve it in 156 lines of C++ code :
No bonus though.
2
u/SirCinnamon Jul 19 '16
Done in java, quite messy but it gets the job done. Feedback is welcome!
https://github.com/sircinnamon/Rektangle/blob/master/Recktangle.java
2
u/sdlambert Jul 23 '16
This one was harder than some of the intermediate challenges I've done.
Solution in Javascript
2
u/gabyjunior 1 2 Jul 28 '16 edited Jul 28 '16
A little late to this challenge, in C generating a maze using Kruskal algorithm with word printed in random colors on the floor of never ending corridors.
Takes as input: word/number of rows/number of columns
The output is in HTML format, you may redirect it to a file and open it in your preferred browser.
The source code is here.
And a sample output there.
2
u/Godspiral 3 3 Jul 18 '16 edited Jul 18 '16
in J,
1
u/Toasted_FlapJacks Jul 18 '16
Are we returning a String in that format, or a 2D array?
1
u/abyssalheaven 0 1 Jul 18 '16 edited Jul 18 '16
Python 3 no bonuses, feels sloppy af, but should be able to do any phrase.
+/u/CompileBot Python 3
1
u/PurpleRoo Jul 18 '16
C++
Kinda messy.
1
u/augus7 Jul 19 '16
This took an embarrassingly long time...
Python:
Output:
1
u/4kpics Jul 20 '16 edited Jul 20 '16
C89, compiles with
cc rekt.c. O(1) storage space, uses a separate code path for single-char strings. Produces randomized colored output.Example input
Example output: http://i.imgur.com/07D9bPM.png
1
u/[deleted] Jul 20 '16
Python 2.7 No bonus. Any feedback is appreciated and always welcome, thanks!
1
u/ITooHaveAHat Jul 20 '16
Haskell
Spent far too long tweaking +1/-1 to indices in order to get the layout right. Had the general idea, but somehow couldn't quite nail it immediately.
1
u/jeaton Jul 21 '16
Python:
1
u/[deleted] Jul 21 '16 edited Jul 21 '16
First attempt at doing a daily challenge. So apologies if the formatting of this reply is all wrong:-S. Took a few attempts as all sorts of crazy stuff was happening with the format.
I am pretty new to programming but willing to learn and any feedback is appreciated. Although I appreciate I have to get better at commenting and variable names. I will try and revise this at some point to improve readability.
I am currently working my way through C++ Through Game Programming, so I have only used the code and syntax I know. It's a decent book though so far as I can tell.
Really enjoyed the challenge though!!
C++ Implementation.
Example of the output:
http://imgur.com/Ad6spu4
1
u/idonotspeakenglish Jul 22 '16
C# (No Bonus)
My solutions are always full of nested loops and very convoluted. I'm looking for feedback to improve the efficiency of my code.
1
u/Shipereck Jul 22 '16
Java.
I'm really bad at this, it took me about an hour and I couldn't figure out how to make it go backwards, so I just opted to make it repeat.
I don't think I did bad for someone learning java for 3/4 days though.
1
u/holeyness Jul 22 '16
Python3 Hi, first time using this subreddit. Any feedback is appreciated. I'm also not a native python speaker, but please be harsh!
1
u/crimsonhold Jul 23 '16
My attempt with C++:
include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
}
1
u/Azy8BsKXVko Jul 23 '16
Rust
Repo with Cargo.toml and whatnot here.
1
u/tritanjent Jul 23 '16
C++ this is the solution i came up with let me know what you think
1
u/sallystudios Jul 24 '16
C++ in 350 lines of code
I have 1 semester of C++ experience and this took me about 4 hours. Not easy. There are probably MUCH smoother implementations of this.
1
u/ohneSalz Jul 24 '16
My very first Java program.
1
u/ATXgaymer02 Jul 24 '16
Swift 2.2
This was my first time basically building any program from scratch. It took me one and a half days of my weekend... but I did it!
I tried hard to make the code as readable as possible, but when editing the strings and then reversing them, I'm sure it gets pretty bad. Any comments or suggestions would be lovely. Also, I'm sure this code could be refactored, but I'm still pretty fresh in my knowledge of Swift/programming (I saw some other guy using mapping but I have no clue what that is yet).
Sidebar: Whoever decided that there had to be spaces in-between the letters of the "full word" rows is literally the devil. That really added a level of complexity that almost made me quit. Here Goes:
Output
1
u/EtDecius Jul 25 '16
C++: No bonuses. 144 lines including comments/error checking. Input string and recktangle dimensions declared in main().
Output: "REKT" 4x3: http://i.imgur.com/yBGuUed.jpg?1
1
u/bgalaprod Jul 25 '16
How would you do this without rewriting certain indexes in the array?
C: #include <stdio.h> #include <stdlib.h> #include <string.h>
Output: word: JUICE, width: 5, height: 3
1
u/karldcampbell Jul 26 '16
Kotlin:
And the unit test (b/c TDD...)
1
u/[deleted] Jul 26 '16 edited Jul 26 '16
Python 3 first submission. Bit of a mess with all the if statements, but it works:
1
u/iFappster Jul 27 '16
Ruby Programming. Really new to programming, so replies are much appreciated
1
u/[deleted] Jul 27 '16 edited Jul 27 '16
My Python 3 solution. I will possibly try to add the bonus later. This easy was definitely more challenging than a typical easy if you want to go for a terse solution.
1
u/[deleted] Jul 27 '16
Fortran 90:
Output example:
1
u/slowboard Jul 27 '16
Python 3
My first submission! I'm currently learning python, mostly for fun. I decided to liberally comment, as this is probably the most complicated string manipulation I've done so far.
1
u/ClassyDinosir Jul 31 '16
Done in Python 3 as I'm interested in learning a new language.
did the "print words in other shapes" bonus by copying u/karmaln7 shape without referencing his code.
those are the functions for generating the solution to the base problem, some possible outputs are:
Code for the bonus:
and the outputs possible:
1
u/Gobbedyret 1 0 Aug 01 '16
Python 3.5
First the proper solution...
1
u/_bush Aug 04 '16
Since I'm only a beginner, I made a simpler version in C, without width and length options:
1
u/yoavst Aug 05 '16
Kotlin:
1
u/LordJackass Aug 05 '16
C++ without the bonuses:
1
u/brunomoreira99 Aug 06 '16 edited Aug 06 '16
Javascript
I'm new to this subreddit and this one really got me thinking for an embarrassingly long time.
I'll post it as a link to JSFiddle. Hope you guys don't mind. I could easily color the output but I was lazy. :P
JSFiddle - Recktangles
1
u/Valion02 Aug 09 '16
Here goes my first submission! It's written in Java.
I used command-line arguments for the word, width and height variables.
I'm a pretty novice programmer so I would love to get some feedback on this as I did a lot of things that probably could have been done better. Here you go:
1
u/KingTops Aug 13 '16
Java
Source
1
u/Kerndog73 Aug 17 '16
C++
1
u/ixwd Sep 05 '16
Java.
I'm pretty new to programming so any feedback would be appreciated but I think I'm a bit late to the party.
}
1
u/boroxun Sep 06 '16
C++ I am a beginner in programming. Here is my solution:
Output:
1
u/yeah_i_got_skills Sep 24 '16 edited Sep 26 '16
Python 3
Output:
Edit, updated:
1
u/futbolbrasil Oct 14 '16
Javascript
0
u/[deleted] Jul 18 '16
[deleted] — view deleted comment
0
u/[deleted] Jul 18 '16
[deleted] — view deleted comment
0
u/[deleted] Jul 19 '16
[deleted] — view deleted comment
0
u/[deleted] Jul 20 '16
[deleted] — view deleted comment