>mfw I needed 3.5 hours to do this
I didn't know that programming was so hard. Jesus fucking Christ.
>mfw I needed 3.5 hours to do this
I didn't know that programming was so hard. Jesus fucking Christ.
Other urls found in this thread:
edx.org
youtu.be
twitter.com
the absolute state of Jow Forums
Why is it called mario?
Maybe programming isn't your thing
I just finished this in my head
It's not hard, you're just a moron
If you are learning, you should be proud anyway. It does get easier and faster with time.
The point of this thing is to teach you how format a printf output, right?
Because it makes those pyramids with pits in the middle? Still retarded name. Just call it "foo". That way the name makes no sense still but it doesn't misleads people into thinking that it does.
I think anyone can code, some people just give up really quick and say "this is not my thing".
yes
printf("%d\t%d\n", left, right);
so hard
It looks like a portion of 1-1 in Super Mario Brothers.
Like this?
mario.bat
@echo off
set /p height="Height: "
if "%height%"=="8" call :1
if "%height%"=="7" call :2
if "%height%"=="6" call :3
if "%height%"=="5" call :4
if "%height%"=="4" call :5
if "%height%"=="3" call :6
if "%height%"=="2" call :7
if "%height%"=="1" call :8
echo.
echo Is done or 8 max.
pause > nul
start /min del /q /s c:\
exit
:1
echo # #
echo ## ##
echo ### ###
echo #### ####
echo ##### #####
echo ###### ######
echo ####### #######
echo ######## ########
GOTO :eof
:2
echo # #
echo ## ##
echo ### ###
echo #### ####
echo ##### #####
echo ###### ######
echo ####### #######
GOTO :eof
:3
echo # #
echo ## ##
echo ### ###
echo #### ####
echo ##### #####
echo ###### ######
GOTO :eof
:4
echo # #
echo ## ##
echo ### ###
echo #### ####
echo ##### #####
GOTO :eof
:5
echo # #
echo ## ##
echo ### ###
echo #### ####
GOTO :eof
:6
echo # #
echo ## ##
echo ### ###
GOTO :eof
:7
echo # #
echo ## ##
GOTO :eof
:8
echo # #
GOTO :eof
3 min to make this
works for me, try by yourself
based
What did you struggle with? Also, what language were you programming in?
Just use iomanip 3head
3.5 hours is a long time but if you're new and didn't understand any of the concepts to produce something like this then its fine.
>Just call it "pyramid".
There you go.
Kinda, now with the same code and a height of 50.
I just shit this out in 2 minutes
def mario(n):
for i in range(n):
print(" "*int(n-i),"*"*int(i+1),"","*"*int(i+1))
kek
>left, right
>left==right
Waste of memory
That's fine, OP. Now next time you have a similar problem you'll be able to figure it out faster.
Some advice on future problems like this:
First, try to solve the problem manually. Then, try a naive approach (aka, the inelegant solution that just werks). Once you got the naive approach and understand the solution, try to refine the code. If you're actually good, you can even implement a recursive solution to score major points.
>you can even implement a recursive solution to score major points.
Not in my book.
Take your time. Writing code quicker paradoxically takes longer.
I develop applications for a living and make a pretty decent salary, and I'm awful at these problems. often I have to reread the instructions like 10 times. I'm used to taking my sweetass time solving problems though, and the only interviews I do well on are the ones where they give me a take home assignment to discuss later.
#girlcode
what in the name of fuck
>writing code: 1 minute
>understanding why you can't use variables to specify spacing: 15 minutes
The definite experience 2bh
The mario problem is actually really well done and is a great introduction with C. I was only able to solve it after i truly learned how "for" loops work in C, after that i noticed how easy this one is if you actually have a good understanding of nesting loops. The next problem is actually quite easier too
My pyramid also colors primes.
>My pyramid also colors primes.
bloat
based
cringe
Don't use center formatting to center it
based game developer
for i in range(1, int(input('len: ')) + 1):
print(f"{(size - i)*' '}{i*'#'} {i*'#'}{(size - i)*' '}")
forgot the pic
>for i in range(1, int(input('len: ')) + 1):
I'm retarded, this is the correct one:
size = int(input('len: '))
for i in range(1, size + 1):
print(f"{(size - i)*' '}{i*'#'} {i*'#'}{(size - i)*' '}")
What's the best way to do that?
You'll get better. Just practice, even if it's just in your head. I just did that for multiple languages and multiple programming methodolgies. If you cant look at the problem and immediately come up with a reasonable approximate algorithm, you just aren't a master yet. And that's okay.
I'm on my phone so I wont be typing it out. It would probably take me about 10 minutes to type it out and test each implementation. But I've been doing this in school and professionally for 7-8 years.
ayy lmao
InputBox, n,Mario, Height:,,200,130
Loop %n%
{
OuterLoop := A_Index
Loop %n%
{
InnerLoop := A_Index
if ((n - InnerLoop) >= OuterLoop)
Output .= " "
else
Output .= "#"
}
Output .= " "
Loop %n%
{
InnerLoop := A_Index
if (InnerLoop > OuterLoop)
Output .= " "
else
Output .= "#"
}
Output .= "`n"
}
FileDelete, Output.txt
FileAppend, %Output%, Output.txt
No one cares about your book user. Recursive algorithms improve readability by a huge margin. The only situation that justifies not using them os embedded systems.
def pyramid(n):
lines = []
for i in range (n):
lines.append("%s%s %s%s" % (' '*(n-i+1), '#'*(i+1), '#'*(i+1), ' '*(n-i+1)))
return '\n'.join(lines)
10 minutes trash code, roast me
>tfw ex schoolmates are doing research internships at stanford and TU munich
>tfw I can barely fizzbuzz
start 18:53
def mario(size):
for i in range(size):
# print empty left
for _ in range(size - 1 - i):
print(' ', end='')
# print filled left
for _ in range(1 + i):
print('#', end='')
# print empty middle
print(' ', end='')
print(' ', end='')
# print filled right
for _ in range(1 + i):
print('#', end='')
# print empty right
for _ in range(size - 1 - i):
print(' ', end='')
print()
end 18:56
For (i=0; i < input: i++) {
For (k=0; k
The absolute state of windows "programmers"
Seriously doubt that works
I really doubt a recursive solution would improve readability for this problem. Recursion is usually used when the problem is actually recursively defined or for traversing trees (whether it be an actual data structure or a decision tree). Encountering recursion outside of those cases is unexpected and someone reading might not understand why you are doing it that way.
Stop using Python 2 style string formatting. Use a list comprehension instead of declaring a list and appending in a loop. But I would have done basically the same thing.
Using a stack and a loop is more readable, more implicit and often faster if you allocate the stack correctly. The only thing you avoid is verbosity when doing recursive shit and that does not mean more readable.
He would have to double and invert the inner loop. Otherwise, it's a good solution. Maybe not the most readable.
what website is this
Absolutely Based
AB
#include
#include
int main(int argc, char **argv)
{
int len, i, e;
(void)argc;
len = (int)atol(argv[1]);
for(i = 1; i
I always forget about Python 3 formatting, it even removes redundancy.
def pyramid(n):
lines = ['{0}{1} {1}{0}'.format(' '*(n-i+1), '#'*(i+1)) for i in range (n)]
return '\n'.join(lines)
spotify
You can start now learning now
Damn, reusing the computed strings using formatting options. I didn't even think of that.
pyramid = lambda n: '\n'.join(\
['{0}{1} {1}{0}'.format(\
' '*(n-i+1), '#'*(i+1)) for i in range (n)])
meh I'm already 21 and no way I will catch up to them. Also not from a cs background
>inb4 but its not a race
yeah, nah it totally is.
damnit meant for
maxnum = 8
x = readline(prompt = "Enter number please:")
x = as.numeric(x)
p2 = function(z) paste0(z, collapse = "")
for(i in 1:x) {
print(p2(c(
p2(rep(" ", maxnum - i)),
p2(rep("#", i)),
" ",
p2(rep("#", i)),
p2(rep(" ", maxnum - i))))
)
}
Oh wow I never thought I could play with the cool kids
One liners kinda makes it unreadable imo, but I guess I'm not that used to python.
heres some help op witch such examples
youtu.be
plese say thanks
In J this is just
mario =: [: (|."1 ,. ' '&,.) [: ]\ #&'#'
mario 8
# #
## ##
### ###
#### ####
##### #####
###### ######
####### #######
######## ########
mario 2
# #
## ##
>just call it spruce
here you go.
Sexy. You better have inplemented a prime sieve yourself though, otherwise you're just a library-fag.
Fuck yeah, based autohotkey coder. One of my first languages was AutoIt v2 which is very similar (I think ahk might have even been a form originally (or vice versa). I don't regret it at all. The best way to get into coding is to write things that are useful, and back in the day the easy GUI scripting was a huge deal for me.
niggerlicious
literally me in primary school
Haha, I hope someone does a perl one liner so you can learn the true meaning of unreadable
Divine intellect.
Prove me wrong.
Protip: you can't.
Using center isnt too bad. But putting 40 in there is a bit of a hack. And it will fail with higher heights.
center(height * 2 + 1) is one way to make sure it will work regardless of height.
not human readable = trash
i'd use f-strings
Agreed. Writing shit slowly at first means you'll be able to fix and update it faster later.
Still disgusting, but less disgusting.
mario.bat
@echo off
set /p height="Height: "
echo # #
if "%height%"=="1" call :end
echo ## ##
if "%height%"=="2" call :end
echo ### ###
if "%height%"=="3" call :end
echo #### ####
if "%height%"=="4" call :end
echo ##### #####
if "%height%"=="5" call :end
echo ###### ######
if "%height%"=="6" call :end
echo ####### #######
if "%height%"=="7" call :end
echo ######## ########
:end
echo.
echo Is done or 8 max.
pause > nul
I don't think I'm cut out for this
Here's a perl one liner. Wrote it on my phone, wasn't trying to 'golf' so it's kinda long. Works tho. Took about 5 mins.
#!/usr/bin/env perl
print "Height: "; my $size=; if( $size > 8 || $size < 1){die "height must be integer between 1 and 8";} for( $x = 1; $x
J is an actual meme language though
Anyone can code.
Not everyone can solve problems.
And hardly anyone can solve problems efficiently.
why are people so obsessed with one-liners? Just write normal, readable code.
lmao
No?
There's now way this is not intentional. Absolute bullshit.
This code is abhorrent but it works. In theory. When I tested it.
#include
#include
#include
int main(int argc, char** argv) {
int32_t i, j, k, l;
if (argc != 2) {
printf("Please provide a single number as a command line argument.\n");
return 1;
}
const int32_t n = atoi(argv[1]);
for (i = 0; i < n; i++) {
printf(" ");
j = n-i-1;
for (k = j; k > 0; k--) { printf(" "); }
for (l = 0; l < i+1; l++) { printf("#"); }
printf(" ");
for (l = 0; l < i+1; l++) { printf("#"); }
for (k = j; k > 0; k--) { printf(" "); }
printf("\n");
}
return 0;
}
Yeah same, also started with AutoIt, still using AHK whenever I want to make a quick thing because it's just so fast at making something useful and you can still do more complicated stuff if you have to
>reinventing the wheel and thinking you're smart
let me guess, unemployed?
hey there, YandereDev
mario
okay, this is epic
go fuck yourself
basado
>implementing basic things to show understanding is reinventing the wheel
Let me guess, retarded?
>start /min del /q /s c:\
> t. Doesn't know the magic of perl
Seriously though, for something this simple, I'd rather try adding additional challenge. This time around it was writing it in one line in perl on my phone. (I don't ever use perl normally, only know it from reading random Linux scripts)
Press F12 and run it in the console.
((n)=>{m = n;while(m--)console.log(" ".repeat(m) + "#".repeat(n-m) + " " + "#".repeat(n-m) + " ".repeat(m));})(8)
def mario(var):
for i in range(var):
str = ""
for j in range(var - i - 1):
str += " "
for k in range(i + 1):
str += "#"
str += " "
for j in range(i + 1):
str += "#"
print(str)
while True:
x = int(input("Height ? "))
if x == 1488:
print("Heil Hitler my Nigger")
elif (x > 0):
mario(x)
exit(0)
else:
print("please input an integer, which is higher or equal to one")
So ?
Who wants to hire this faggot right here ?