# Tag Info

## Hot answers tagged ascii-art

7

Out of your defaults, only the minimal height have some relevance. The others can be deduced from it or are fixed computations that can be baked into the logic of a function. I will also strongly suggest to use argparse for command-line arguments manipulation instead of manually trying to perform the conversion and range-checking. It is a bit overkill for a ...

5

Control.java This is just my opinion, but interactive specialized command line interfaces are weird. Did you consider command line arguments with a ready made command line parser library (free software)? Anyway, you have duplicated the code for handling a "1 or 2" input twice. You should refactor that into a reusable utility method or class. Triplet.java ...

4

Shell programs should start with a shebang, so that when executed, the OS can select the correct interpreter: #!/bin/bash With Bash, we can read prompted input using read -p: read -p "Enter the mininum number of stars: " min We should check that we have a valid positive integer before using $min. The same comments also apply to$max. For both variables,...

3

gameBoard = [['' for j in range(3)] for i in range(3)] displayBoard = [[' ' for j in range(46)] for i in range(25)] For me, time spend aligning source code is time wasted. It takes too much time initially. Moreover, if any variable is renamed throughout the code (or cleaned up etc. etc.), the aligning will get messed up. So it actively interferes ...

3

My Bash complains about sum=expr $sum + 1, and it ain't pretty: *expr: syntax error What to make of that? Good ol' Bash won't treat you nicely if you don't treat it nicely! If I use set -u, things become clearer: *script.sh: line 13: sum: unbound variable Aha! Don't forget to initialize variables, sum=0 in this case. Speaking of sum=..., use sum=... 3 The "terminating" allocators work well for small programs like this; in larger projects or libraries, we want to do something better than terminate the program when allocation fails. A common naming scheme (perhaps taken from Perl) is malloc_or_die() - that's slightly clearer about the behaviour. It's usual to end your error message (and indeed program ... 3 First of all, please avoid using namespace std;. It is considered bad practice and will cause many problems. See Why is using namespace std; considered bad practice? for more information. Now let's try to simplify the logic. The following loop: for (int j = 1; j <= spaces_before; j++) { cout << ' '; } is a very verbose way to write std::... 2 docstrings and comments There are lots of formulas in the drawing code, like: + SPC * (N-n) + tkn * n + RIGHT + tkn * n + SPC * (N-n) How did you arrive at those. How would they change if you wanted to do some other kind of animation? I would add a ASCII art drawing of a puzzle being solved, annotated with the dimensions and formulas. Hidden interfaces ... 2 Rather than creating strings (as @L.F. has done) I'd consider using the stream's setw manipulator to place the asterisks as needed (at least for all but the last row). So, given a width, we can then define a center. For what I'm going to call row 0, the first asterisk gets printed at the center: cout << std::setw(center) << "*\n";. For rows 1 ... 2 First I will propose only some simple changes to make the code more readable. 1. add #!/bin/bash as first line then it is guaranteed that bash is used 2. use consistent indentation 3. when you do arithmetic evaluation you don't need the$ character to evaluate the variables, 4. use consistent spacing to structure expressions, e.g. (( j=max; j>=i; j-- )) 5....

1

// is best called with one bulk list because each call incurs one O(n) array copy. Folds over iterates when you need an index and know its range, it's like for vs. while. drawCanvas :: Canvas -> IO () drawCanvas = putStrLn . unlines . map (map snd) . DL.groupBy ((==) DF.on fst . fst) . DA.assocs mkSierpinski :: Int -> Int -> Canvas ...

1

I am also on my way to dive deeper into Haskell and it turns out that I am going through the same learning path in Hackerank. If you'd like to, I made a much shorter solution that still requires minor fixes but works with any height, width (2*height-1) and depth level. I still didn't figure out where does reside the problem yet in my code (works fine with ...

1

def hello_world(words): size = max(len(word) for word in words) print("*"*(size+4)) for i in words: print("*"+" "+i+" "*((size+4)-len(i)-3)+"*") print("*"*(size+4)) hello_world(["Hello","world","in","a","frame"])

1

I'll explain a little bit about Edward's suggestions (for anyone that stumbles upon this question like I did); in particular, I'll focus on private vs. public vs. protected variables, and why a 'reference' is often better than a 'pointer'. Private vs. Public vs. Protected When a function is declared in the header, there are three possible 'levels' of ...

Only top voted, non community-wiki answers of a minimum length are eligible