/dpt/ - Daily Programming Thread

Previous: What are you working on, Sup Forums?

Other urls found in this thread:

medium.freecodecamp.com/what-programming-language-should-i-learn-first-ʇdıɹɔsɐʌɐɾ-ɹǝʍsuɐ-19a33b0a467d
jeiks.net/wp-content/uploads/2014/08/TriangulationByEarClipping.pdf
github.com/finnstr/gdx-liquidfun-extension
developer.android.com/ndk/guides/ndk-build.html
better-dpt-roll.github.io/
benchmarksgame.alioth.debian.org/u64q/compare.php?lang=python3&lang2=gpp
twitter.com/SFWRedditImages

First for C#

Second for C#

Third for C#

>/dpt/ - Daily Pajeet Thread

I've got a bash script that works if i run it with ./script.sh but doesnt work if i run it as sh script.sh

i'm trying to make a shortcut to the script but the only way i know how is sh /destionation/script.sh. Can i make a similar shortcut using ./ instead of sh?

...

What does this mean?

First for C++. Amidoinitrite?

...

No.

I'm genuinely curious; are you very new to Sup Forums, or doing some good 'ole trolling?

Neither. I just can't keep up with you kids and all your newfangled memes.

write a function that prints out this structer -

+ ---- + ---- +
| | |
| | |
| | |
| | |
+ ---- + ---- +
| | |
| | |
| | |
| | |
+ ---- + ---- +

1 def box():
2 print('+', '-' * 4, '+', '-' * 4, '+')
3
4 def verticle():
5 line = ('| | |')
6 print(line)
7 print(line)
8 print(line)
9 print(line)
10
11 def do_twice(f, n):
12 f()
13 n()
14 f()
15 n()
16 f()
17
18 do_twice(box, verticle)


i don't know if i actually did it write but on checking the answer his code is much more OOP then mine.

>newfangled memes
It's literally been an internet thing since the 90's.

The practice of not only getting a "FIRST" post, but also attributing it to something you value is more recent, but certainly at least to the early 2000's.

So maybe you're neither young/new or trolling, but you're at the very least not very observant.

lol itrollu

>but you're at the very least not very observant.
Can't really argue with this, i guess.

i remember that assignement. I made a version where you could decide how many boxes you wanted and it would draw them for you.

# -*- coding: utf-8 -*-
while True:
import sys
y = int(input('How many horizontal boxes do you want? (Max 15!): '))

if y > 15:
print 'Too many you fucking retard!'
sys.exit('ss')

x = int(input('How many vertical boxes do you want?: '))
print
print

if y == '':
print 'You didnt write anything'
sys.exit('ss')

def do_twice(g):
g(x)
g(x)

def do_four(g):
do_twice(g),
do_twice(g)

if y > 1:
def first_tak(y):
print (('x' + ' -'*4 + ' ')*(y) + 'x')

if y == 1:
def first_tak(y):
print ('x' + ' -'*4 + ' x')

if y

15! is a pretty big max

wow that's really cool so did i do it right?

and I actually ahd planned on messing with it to where it's afor loop that keeps spawning boxes ahha.

Yours is absolutely impressie I never though on doing that ;-;

4 u

It's not that big.

>wow that's really cool so did i do it right?

i guess so, i dont remember the actual assignement. Was it really just to make a function that printed that box? In that case you can just put print "*box*" in the function and call it a day.

Here's some similar shit i did. I havent been in this folder in a long ass time.

space = " "
fstring = raw_input("Enter Text: ")
string = fstring*8
length = len(string)

top = string[:int(length/4)] + space*int(length/4) + string[int(length/4):]
topmid = string[:int(length/4)] + space*int(length/4) + string[:int(length/4)] + space*int(length/2)
mid = string + string[:int(length/4)]
botmid = space*int(length/2) + string[:int(length/4)] + space*int(length/4) + string[:int(length/4)]
bot = string[int(length/4):] + space*int(length/4) + string[:int(length/4)]

print "\n" + (top+"\n")*int(length/8) \
+ (topmid+"\n")*int(length/8) \
+ (mid+"\n")*int(length/8) \
+ (botmid+"\n")*int(length/8) \
+ (bot+"\n")*int(length/8) \


I dont know why but i've always liked text inputs in my scripts

for you

Why the fuck doesn't std::vector's operator[] throw an exception?

I just spend 3 days worth of freetime troubleshooting an issue because of that shit

where do you get your pdfs/epubs /dpt/?
All the major search engines have failed me and it's not in g.sicp.me

Just started learning programming using thinklikecscientistptyhon or something. I don'treally read the chapters just go to the examples for trying improve my ability to abstract logic there.

its a pretty neat book imo

Performance, if you want exceptions use get().

can anyone recommend me a page or guide to get started with concurrency and thread in java
I have an exam in 5 hours

cd /path/to/script && ./script.sh?

Nah, dont think i'm allowed to change directory like that. Getting pic related.

Then use a non shitty distro because that works for me.

Or put it in your .*rc file?

I'm working on an interpreter in Fortran for a procedural meme of a language. The rest of Sup Forums isn't working on anything because nobody here can code.
>INT(LENGTH(LIST) / 2)
Not even valid code, and 'len' returns an int, meaning in python 2, you can just use '/', and in python3, you can just use '//'.

It's not supposed to be valid. It's pseudocode???

>Not even valid code
It's pseudocode, dumbfuck.

medium.freecodecamp.com/what-programming-language-should-i-learn-first-ʇdıɹɔsɐʌɐɾ-ɹǝʍsuɐ-19a33b0a467d

it's official

Shittiest fucking fix ever

Made a script that runs ./ so that i can sh that script and get it to ./ the other. it actually works.

>Failed to execute child

Are you mentally retarded?

Why am I even asking, this is Sup Forums...

what is $PATH

just add /home/user/bin to your path and put all your garbage scripts in there

That's really bad code. If you're going to write bad code, at least make it short.

for _ in range(2):
print '+ ---- '*2+'+'
for _ in range(4):print ('|'+' '*6)*2+'|'
print '+ ---- '*2+'+'

>What are you working on, Sup Forums?
I finished this fucking triangulation algorithm, way harder than I thought

It's attempting to look like Python. You don't use fucking different intrinsic function names in pseudocode; you just abstract. If it was pseudocode, why the hell would he be wrapping his division up in an 'INT' statement as safety for his slice?

make a folder called bin in your home folder
move your scripts there
add export PATH="$PATH:~/bin" to your .bashrc

Looks good. What algorithm did you use?

It's attempting to look like python but somehow not python at the same time... hmmmm... I wonder if maybe that's because it's pseudo code

btw, there's no standard for pseudo code. Pseudo code is just any piece of code that's not designed to be compiled, instead it's supposed to be human readable. Since Python is already human readable, the two often look a lot alike.

Also you can tell it's not Python because Python's random function returns a float between 0 and 1.

If it was designed to look like Python, it would be randint

>What are you working on, Sup Forums?

Research with a professor, or how I like to call it "a fucking waste of time to get my remaining credits so I can finally graduate".

>user take my code and do this shit
>ok I'll try
>professor I can't do this shit because I don't understand you code; it's a garbage written in c++ that you dedicated 3, maybe 4 years of your life yet you didn't put a single comment on it
>how so? this shit is trivial user go home try again and see me next week

I used triangulation by ear clipping

>structer
kill yourself, you dirty illierate

>jeiks.net/wp-content/uploads/2014/08/TriangulationByEarClipping.pdf
That actually is a pretty cool algorithm.

I'd probably have never thought about it.

no lmao

Need help using Android NDK to run my .mk files.

The library was created by someone else, and I have edited a few of the .cpp files.
I need it to build so that I can use the library in my project.

>github.com/finnstr/gdx-liquidfun-extension
The .mk files and .cpp files I need to build are inside /jni/

Please help, I am stuck

The link below is all the info I have
>developer.android.com/ndk/guides/ndk-build.html

do you have a #!/bin/bash in the beginning of your script?

I used exactly this pdf, it's bretty gud

How can high traffic sites like Reddit be powered by Python? It's slow as fuck, but it somehow manages all that traffic. Do they simply spend a fortune on processing power to overcome the slowness?

It's a Linux-based build system you're gonna need cygwin if you're gonna build on Windows.

Here, I made it make a 1 second pause when it find a triangle so you can see it work

>he fell for the "if it's not C, it's slow" meme

Slow is relative, and highly dependent on what you're actually doing.

There's a massive practical difference between doing insanely manually-optimized mathematical algorithms and handling simple data requests.

Calling Java, C#, and Python "slow" in some contexts is meaningless. In the context of development iteration turnaround, those languages are sometimes orders of magnitude faster than something like Assembly or C.

It probably doesn't do that much. I mean what can you do on reddit? Upboat? Oh okay boat++. Post text? Oh okay add item to database that does the real work. Large websites are mostly a getting data to the right place problem not a doing lots of processing on data problem. Google is an exception. They spend a lot of time digging through their data trying to pull signal out of the noise. Forums are about moving noise around.

What do I do once I have downloaded cygwin?

I have tried putting the same commands into the MinGW cmd, but I get the same errors.

That's fucking nice bruh.

Are you using OpenGL to draw everything?

Kys

Cucks donate them golds so they can waste powerful servers with their shitty webshit.

>What are you working on, Sup Forums?
I decided that implementing an audio compression decoder from scratch was too much work for me, so i'm now looking at how to use Microsoft Media Foundation.

Well I'm using a lib called SFML which itself uses OpenGL, I'm just to lazy

Offer a dissenting argument if you want to be taken seriously, faggot.

can i get the picture to roll and work on a new project. need practice for when im out of school

Not trying to be condescending but you seem to lack even basic understanding of the command line so trying to help you set this up would be a major back and forth of questions.
Try and google how to setup and use the ndk on Windows with cygwin, maybe someone has written a step-by-step tutorial or something.

better-dpt-roll.github.io/

Don't shit up the thread with rolls

dont have to be rude i just want to learn

I wasn't being rude at all, you dumb faggot.

Occasionally when someone posts a roll image, we get 30-50 posts that just say something like "roll" which buries some discussion.

To avoid this, I've provided you a handy link that even does the rolling for you. I'd call that pretty civil, from a utilitarian perspective.

everything will be ok

>I wasn't being rude at all, you dumb faggot

fucking kek

dumb thin-skinned frogposter

you guys are fucking retarded

Rate my code pls

/**
* @param n n
* @return d on success, -1 on failure
*/
int64_t f(uint8_t n)
{
if (n 92) return -1;
n -= 2;

uint64_t a = 1, b = 1, c = 0, d = 1, e = 1, f = 0;

while (n) {
uint64_t g, h;
if (n & 1) {
g = a * d + b * e;
h = b * d + c * e;
f = b * e + c * f;
d = g;
e = h;
}
g = a * b + b * c;
a = a * a + b * b;
c = b * b + c * c;
b = g;
n >>= 1;
}

/* return d */
return d;
}

rate my with ada.text_io, ada.integer_text_io;
use ada.text_io, ada.integer_text_io;

procedure cal is
subtype Weekday is integer range 0 .. 6;
subtype Month is integer range 1 .. 12;

month_names : array (Month) of String (1 .. 9) :=
("January ", "February ", "March ",
"April ", "May ", "June ",
"July ", "August ", "September",
"October ", "November ", "December ");

function is_leap_year(y: Integer) return boolean is
begin
return (y mod 4 = 0 and y mod 100 /= 0) or y mod 400 = 0;
end is_leap_year;

function length(m: Month; y: Integer) return Integer is
begin
if m = 2 then
if is_leap_year(y) then
return 29;
else
return 28;
end if;
elsif m in 9 | 4 | 6 | 11 then
return 30;
else
return 31;
end if;
end length;

-- returns the weekday of the last day of the month
procedure print_month(m : Month; y : Integer; day : in out Weekday) is
mon_len : Integer range 28 .. 31 := length(m, y);
begin
Put_Line(month_names (m));
for i in Weekday range 0 .. day - 1 loop
Put(" ");
end loop;

for date in Positive range 1 .. mon_len loop
Put(date, 3);
if day = 6 then
Put_Line("");
day := 0;
else
day := day + 1;
end if;
end loop;
Put_Line("");
Put_Line("");
end print_month;

y : Integer;
startday : Weekday;
begin
Put("Enter year: "); Get(y);
Put("Enter first day of week (0..6): "); Get(startday);

for m in Month loop
print_month(m, y, startday);
end loop;
end cal;

Realized that I haven't touched Ada for years and wanted to give it a shot. There's probably a better way to do that month name array initialization but I'm too lazy to remember/relearn how unbounded strings work.

dont have to be rude i was just telling you not to be rude

(checked)
I understand that the server is mostly waiting for the database to retrieve the requested data, but still. On such a grand scale, things like URL routing in Python will add up quickly in terms of CPU time.

clear/10

this code is CUTE

>things like URL routing in Python will add up quickly in terms of CPU time
What makes you think this?

>Sup Forums
>not retarded

pick one

>you seem to lack even basic understanding of the command line
Indeed I do.

I just want to make some fun physics on Android, but wanting to edit native code has lead me out of my depth. I don't want to give up though.

I feel like a down syndrome trying to solve a Sudoku.

Thanks for the help though, I will follow your advice

Can f be both a function and a variable at the same time?
I didn't realize that. Neat

Also is that faster than the standard
def fib(n):
a,b=1,0
yield b
yield a
for i in range(n):
a,b = a+b,a
yield a

It looks like it because the loop looks like O(log n)

No brief explanation of what the function is doing.
single letter variable names which looks like is picked in alphabetic order rather than according to the usual terms in any context.
Weird comment for an if statement and the return statement, but nowhere where it might be useful. (eg. like why n > 92 is a failure or what the function does)

When all this is combined, you have bad code.

Even though a web server spends most of its time in a database and writing data, there is still *some* overhead. If you could reduce the overhead 10x by using C++ over Python instead, you'll reduce CPU time. If you have large amount of traffic, you could serve even more clients per server, thus saving money. I know that development time is more costly than buying extra machines, but does that also apply on a large scale like Reddit?
Also, URL routing is just an example. It doesn't require I/O (hard drive, or network).

>Can f be both a function and a variable at the same time?
Yes, the f inside the function masks the function f.

>Also is that faster than the standard
I suspect so, but to be sure you'd have to benchmark both of them. You're correct that it's O(lg n).

Hmm, I see what you mean. Maybe the comment should be

/* if n is greater than 92, we will run out of bits, so fail */


There aren't really any good names that I could use for those variables.

>If you could reduce the overhead 10x by using C++ over Python instead
Why do you think there is this much overhead?

Why do you think that C++ specifically would be a good choice to do this?

Do you understand how much development time would be required for a re-write of backend systems? Keep in mind, we're not talking about just a first-iteration re-write that "works"; risk must be taken into account in potentially much more massive bugs due to using an unsafe language.

And keep in mind that all of this still goes back to the fact that it's extremely unlikely that you could squeeze an order of magnitude more performance out of a back-end rewrite in a different language, rather than simply optimizing the implementation in the current technology stack.

Then there's the 100's of libraries they're using that they'll have to find or develop C++ equivalents of...

All in all, it's easy to sit here and recommend a lower-level language for anything that could *potentially* benefit, but ultimately it just doesn't hold up to a business-case conversation.

By the way, I don't think Reddit is at the scale you're thinking it may be. At least, not in a way that a low-level language would significantly effect without an undue amount of staffing and development.

It seems that everyone has forgotten that you must be mentally retarded to create a social network similar to the Reddit scheme.

>inb4 Sup Forums is in PHP
Fuck off

Holy shit, llvm is huge.

Ok i'm ready to be laughed at.
usernumber = raw_input("enter a number and I'll tell you if it is a prime number or not. Use only integers.")
number = int(usernumber)
def isPrime(num):
for i in range(2,num - 1):
if num % i == 0:
print "It's composite"
break

isPrime(number)
raw_input()

the idea is that I want the function to print a statement also if the number is prime, but for the life of me i cant think of a way to do that. It's probably something really simple im missing too.

bloatware

Are you looking for the "else" command?

If this, else this.

You only need to test up to sqrt(num).

> enter 78213808329
> wait for 50 years

nice user, you'll go far

benchmarksgame.alioth.debian.org/u64q/compare.php?lang=python3&lang2=gpp
Python is much slower than C++, but that's just when number crunching.
But you're right. Python makes much more sense to use than C++ for the reason you mentioned (library support, safety, time).

1082 def getrandmon():
1083 rn = random.randint(1, 100)
1084 if floor 3 and floor 50 and rn 75:
1100 return 30
1101 if rn > 50 and rn 75:
1104 return 10
1105 if floor > 5 and floor 8 and floor 50 and rn 75:
1121 return 70
1122 if rn > 50 and rn 75:
1125 return 50
1126 if floor > 10:
1127 if rn 25 and rn 50 and rn 75 and rn 88:
1137 return 90

I made a cool function guys

If by "cool", you mean horribly written, then sure.

You wrote a "cool" function.

Your month_names should be an enumeration instead of an array of strings.

Y should be a natural

Other things, basically you're not using the type system to its full advantage. For example, inputting the day of the week as a number instead of the work is a contrivance for C.

I had an else statement, but i couldnt get it to work properly, it would sometimes list composite numbers as prime and such.
thank you for the advice.
I'm terrible at math
pls no bully, I just want to be a good programmer one day

pls no rudeposting