/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

academy.sciencealert.com/sales/pwyw-learn-to-code-2017-google-go?utm_source=sciencealert.com&utm_medium=referral&utm_campaign=pwyw-learn-to-code-2017-google-go_020217&utm_term=scsf-211745
doc.rust-lang.org/book/
twitter.com/SFWRedditGifs

Somebody kill me

Please do not use an anime image next time. Thanks.

Thank you for using an anime picture.

First for Visual Basic as waifu

Daily Programming Challenge!

In any language, write a program that will draw a circle of arbitrary size in the terminal!

Since most terminals fonts are not 1:1, your circle might look like this:
./circle 10
#####
# #
# #
# #
# #
# #
# #
# #
#####
You can cheat and make your circle look nicer by dividing your x values by 2.
./circle 10
#####
## ##
# #
## ##
#####

I am currently working through the K&R book. I am confused by these two problems.

1-20
>Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter?

1-21
>Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab . When either a tab or a single blank would suffice to reach a tab stop, which should be given preference?

What is the difference between detab and entab? Sounds like to me both programs just want to ensure that there are the appropriate number of blanks in between the tabstops.

how do you post inline code on Sup Forums?

[ code ] [/ code ]

can someone post that pic of the beta ass kid in the apple store with the god awful posture?

From what I understand detab converts tabs to spaces, entab converts spaces to tab. Since there may not be an exactly equivalent amount of spaces per tab, the second will have to be tabbing at least the equal amount.

Currently working on sky-net defence system. A learning, self aware botnet.

I'm working on a p2p imageboard architecture.
>language
undecided yet, any suggestion? I'm also planning on making a non-bloat web browser as front end (with client side theming and scripting).

I'd write 1-20 by reallocing the array where the text file is stored and memmoving everything to the right of the tab and overwriting the tab with n spaces.

>be me
>in ENGR270
>already know x86_64 assembly so class is extremely easy
>put off final homework until the night before
>school forgot to pay for their GoDaddy webhosting so I can't download the homework
>homework pdf is password protected

>mfw Google has it cached

You know the saying, right? If you want something done right, do it yourself!

>Now it happens to be the case that C++17 is putting exactly the wrong kind of restriction on function calls. They will allow them to remain about as unpredictable as they are now. It's just that compilers can't weave the operations inside the functions. They're still unordered they just removed one of the most important thing about having this.
Can someone explain this further?

academy.sciencealert.com/sales/pwyw-learn-to-code-2017-google-go?utm_source=sciencealert.com&utm_medium=referral&utm_campaign=pwyw-learn-to-code-2017-google-go_020217&utm_term=scsf-211745

I've been thinking about buying this bundle for 24 bucks for practice. Is it worth it? Couldn't really find anything on google about science alert. I'm afraid because it seems too cheap.

Just had a random thought: Why can't we have tuples as class' members? For example, something like:
class Person
{
string Name { get; set; }
(string Day, string Month, string Year) Birthday;
}

And then you can access it like: person.Birdthday.Day ...
I don't want to write a class/struct just to simply wrap some types.
>inb4 anonymous types

f :: Int -> Float
f = fromInteger . toEnum

inR r (x,y) = ((f x) ^ 2 + (f y) ^ 2)

No reason

You can with proper record types. What lang is this?

How's mine?
void display_bitmap(char **data, int size)
{
unsigned i, j;
for (i = 0; i < size; i++)
{
unsigned empty = 1;
for (j = 0; j < size; j++)
if (empty && data[i][j])
empty = 0;
if (!empty)
{
for (j = 0; j < size; j++)
putchar((!data[i][j]) ? ' ' : '#');
putchar('\n');
}
}
}

void draw_bitmap(char **data, int size)
{
unsigned orig = (size / 2) + (size & 1);
float i;
for (i = 0; i < 2 * acos(-1.0f); i += 0.01f)
{
int y = sin(i) * (size / 2) / 1.8f; /* term height */
int x = cos(i) * (size / 2);
data[orig + y][orig + x] = 1;
}
}

What do you mean? Now that I think about it: What if another class needs the same tuple? I end up rewriting the same definition for the tuple, which is dumb and redundant and we go back to square one.
>proper record types
Idk what are those, checking rn. I tried making the example in C#.

please no

>What do you mean?
There's no reason that couldn't be part of the language.

ive got a retarded question here guys bear with me
class ContactList
String toString(Contact[] list, int index)
if (index=0)//i need to figure out the base case later
return null;
else
return ((toString(list[], n-1) + "\n" + list[index-1].Contact.toString());


i would like to return the entire list recursively as a big string but the problem that i'm having is that both the superclass and subclass have a method with the same name and I don't remember how to reverse override methods. Basically, how retarded am I? is using a pointer valid?

class Contact{
String toString()
return contactInfo}

>arbitrary size in the terminal!
>10
What does this 10 represent? Radius? Because it isn't

Is there a simple way to find memory leaks in a Python script?

I have a script that accesses an API (with requests module) and downloads small files occasionally. It runs 24/7 and after a day or two it eats so much memory that the OS fills the swap memory completely and starts killing off other processes. I have 512MB of RAM and 256MB of swap, and htop tells me the script starts off at ~5.5% memory usage but gradually grows to over 12%, even though the only data that I'm explicitly storing in the script is a set of short strings, which I'm pretty sure isn't the culprit.

I put "del"s all over my script to delete objects that I thought could have caused this, no effect.
I tried using pympler to look through stored objects, but it hasn't been very helpful.

I'm at a loss right now. Any ideas?

What ancient machine are you on?

>Java
Trash.
>Sepples
Trash.
>P*thon
Trash.
>Ruby
Trash.
>PHP
Trash.
>(((C#)))
Trash.
>JS
Trash.
>Perl
Trash.
>C
Trash.
>VB
Trash.
>R
Trash.
>Scala
Trash.
>Shell
Trash.
>Action Script
Trash.

It's called a VPS, friendo.

>
Trash.

What's a good name for a theorem?

(Your Name)'s Theorem

Why aren't you using Ada?

Obviously thought about that already. It's boring.
I would like some anime name.

I don't think people usually name their own theorems; a name organically forms when an important theorem is discovered.

Akari's Theorem

Why should I?

Akarin's Theorem

I think people won't mind if I propose some sort of name.
I will think about it.

cutemind

I think it might be height
But it only counts out to 9 on the first one

Fact: OCaml programmers are the most powerful race in the world.

>in the Old World
ftfy

Fact: Rust programmers are the safest race in the world.

Agreed

It's a systems language that got it right

>he cannot even implement calculus of construction or use any sort of higher order type theory in his language
lmao rustoddlers everyone

Fact: Haskell programmers are the most useless and lazy in the world.

What are you on about? Rust's type system is fuckton more powerful than almost all languages, including C(ancer)

b-but rust is the safest language ever! it doesn't have the same memory problems that other languages have that lead to security problems! look at the CIA leak!

Thought about learning it but I guess it's trash. Thanks, mate.

*most popular useful languages

If what you're saying is true, I'm interested. Elaborate.

I'd pick Rust or Ada over any other language if I wanted security. Like in Bank system, Power plant etc

Oh C is not in the list then

>useful languages
So what you're defining is empty?

Rust isn't either

>tfw started another language flame war ITT without even realizing it
I guess some things just can't be helped.

Reading the rust book.

You mean master race.

>actually a guy
Even better!

I-I want to learn rust, but there isn't any Rust book by Brian Kernighan so I can't learn it.

All you need: doc.rust-lang.org/book/

me on the top right

I wish the book was better. It's structured well but there is are no practice sections.

I hate touch screen

The power of C++ but with a real type, tasking, and formal verification system. It also has the novel concept of specifying your type sizes and fixed point arithmetic, as is it's a real systems language.

I-I tried reading other programming books but its too hard because they don't explain the concepts as well as Kernighan does. The only programming language I know is Go because it has a book written by Brian Kernighan. The only other books I read on programming are the Practice of Programming and the Unix Programming environment for the same reason. I'm not very smart ⊙﹏⊙

Is it OOP trash by any chance?

Start with Haskell.

If you already know a language it should not be that hard. Where are you stuck? Have you tried asking in their beginners' IRC?

This. Rust is pretty easy once you know Haskell and any other imperative language.

I can only learn it if it has a Brian Kernighan book as explained here

I-I tried to learn java but its too hard ⊙﹏⊙. I-I couldn't understand anything, I don't understand what an object is or inheritance, so I-i gave up ;_;

Seeing how retarded you are, C might be the language for you. It does an amazing job containing programmers that aren't all that smart.

D-Does it have a book by Kernighan which I can learn from?

Dunno

Can you stop typing like a fucking idiot?

S-s-sorry I-I'm j-just a l-little n-nervous

>java
Why would you be learning that piece of trash?

Can you stop bullying?

What techniques do you use to find memory leaks in codebases of 100k+ lines of code?

Using Rust.

Install Gentoo

I learned some Ada in my first year studying computer science at uni. Haven't used it since then, since it's a pain in the ass compared to C++.

Getting anally probed by Project Euler

I'm currently doing a problem pertaining to Totient functions (the number of all terms that are relatively prime to a number n), and I thought my smart-ass had figured out an efficient manner of calculating the function.

Except it's almost always off by one. It's either one above or one below, and I'm pretty sure it's because I computers don't have infinite-precision decimal places...

Here's my code... I can't seem to find a way to make it work
/*
(T(n) = totient (n) == Phi(n))

From one of Euler's many identities,
n/T(n) === PI[of all prime numbers that divide into n] (p / p-1)
//(Note, [all prime numbers that divide into n] can be written as p|n
Therefore,
T(n) = n *PI[p | n] (p-1/ p)
*/
long Totient(const long n, const set& primes, long& result)
{
double product = 1;
int sqrtN = sqrt(n);
for(long prime : primes)
{
if(prime > sqrtN)
break;
if(n % prime == 0)
{
double factor = 1 - double(1)/prime;

double prime2 = n/prime; //Because we're only going to sqrt(N), we need to take into account
//The prime number that is n/ prime (otherwise, we'll be a bit off);

double f2 = 1 - double(1)/prime2; //The fraction on the "other side" of sqrt(N);

product *= factor;
product *= f2;
}
}
result = n*product;
return result;
}


Unrelated, but how's HackerRank? I started doing some of the intro problems and they seemed kind of easy... Do they get to "Project Euler" difficulty?

Ironically my next project will be in Rust

nice

this

Fucking dope

Unrelated, but
What are you guys's thoughts on Moral Luck?

How is it a pain?

Ultimately, consequences are the only thing that really matters

I don't know the specifics of your problem and I'm not trying to figure it out but generally when you are doing floating point operations you want to set up your shit so a) there are fewer of them, and b) they all happen at the end.

I don't really remember the reasoning behind this tip but I think it has something to do with the error growing larger every time you do something to a floating point number so you want them to not be floating points til the very end to minimize the error.

When the BSD license requires you to include a copy of the license with a binary release, does that mean just DLL releases or do I need to retain the license in a larger program?

Huh... Didn't even occur to me to use that trick...Pretty genius imho...

Unfortunately, I'm still running into the same error... I think I"ll have to go back to the drawing board for this one.

Thanks anyways!

Memesnek has memory leaks? I thought it did GC? Are they really managing to fail at detecting circular references?

For what purpose? Just make a Birthday class and have a Birthday object instance.

Learn based Haskllllellll (・へ・)