/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1555540507892.png (891x605, 355K)

Other urls found in this thread:

ghostbin.com/paste/9kgeq
pastebin.com/mDyVCgkn
ghostbin.com/paste/56ux2
pastebin.com/U6qP4TYq
youtube.com/watch?v=eDiSYp_51iY
twitter.com/NSFWRedditImage

I'm programming communism

From last thread (posted at very bottom):
Common Lisp Pokémon battle type effectiveness calculator, accurate for generations 2-5.
My first common lisp program. I loved association lists.
ghostbin.com/paste/9kgeq

>>;; instead of //
>>for what reason
Because you use ';' for comments in lisp.
// isn't technically valid for comments in C89 (ANSI C), either. Only /* */ was allowed until C99 about 10 years later.
So basically, it's because you're retarded.

Is there a standard function or common method for converting a decimal to a fraction?

Is there a way to convert 0.00007933989209774674 to 1/12604 without a bunch of loops and /or recursion?

>So basically, it's because you're retarded.
kek

There are obviously ways, since CASes can do it, but if you're ruling out vast swaths of classes of algorithms you may be out of luck.

If you know it's a unit fraction you can take the reciprocal.

Good job telling us what language you're using so we can help.

There is no easy way to look for primes, it is one of the unsolved problem of mathematics. Most "simple" formulas involve shit like "2 to the power p" which of course is really difficult for computers once p is bigger than a few thousand. What you are trying to do would be a log(n) time prime finding algorithm, if it worked you'd get a nobel prize for it

Use the Euclidean algorithm to calculate the GCD.

>%03d in printf
what's the c++ equivalent of these with streams?

I just had a horrible nightmare, where I was forced to work with a programming language where the syntax actually used white space to define blocks!
The only way to tell which if an else statement belonged to was seeing if they were equally indented!

Thankfully nobody has been insane and evil enough in the real world to create something so horrible

Attached: 1554048394941.gif (720x312, 1.74M)

you dont want to see it

is the runtime of dynamic programming algorithms (with memoisation) bounded by their space complexity if you're only doing O(1) operations inside each recurrence?

e.g. if you're trying to solve a problem for an array that has 2^n possible outcomes but only keep a n^2 array for storing/reusing results, does it mean the algorithm can't run worse than O(n^2) since you only solve that many subproblems?

guess I should just use the fmt library, huh

>C++ equivalent of printf with streams?
char text[4];
snprintf(text, sizeof(text), "%03d", 7);
cout

>char array
>c++
no

>white space indicating blocks
>Thankfully nobody has been insane and evil enough in the real world to create something so horrible
Are you quite sure about that?

Attached: inquisition2.jpg (854x640, 94K)

How'd I do honestly? The table contents were a bit malformed as they came from PDFs, and I'm kinda new to C, I've used it before but I usually use Python/Bash. Was pretty impressed that it correctly parsed 16,000 tables of data in 32ms

pastebin.com/mDyVCgkn

Attached: malformed table parser.png (660x433, 43K)

It's valid C++.
You can thank Bjarne Stroustroustrudelstroup for that.
Isn't C++ such a wonderful language?

valid doesn't mean it's good or that it should be used

You don't have to pull in std::array just for an array! I've only ever wanted std::array for a client-facing API.

This, but for the whole of C++

If you're looking for good, then what the hell are you doing using C++?

>You don't have to pull in std::array
exactly because you should be using a string or a vector

b-but user, my boyfriend, IDE-kun makes it painless
>did you mean to use a tab here?
>baka, you used an extra space
also, scope-based syntax coloring (rather than the fruit salad that most people use) changed my life desu

I'd have beaten you to it if recaptcha wasn't a russian roulette game

For easy prime generation you could take a look at my algorithm here: It's reasonably efficient up to a few 10s of million primes, and can be improved a bit by changing
let k = i + i
to
let k = i * i
but then you also need bounds checking to stop yourself from going over the edge of the array.

me on the bottom left

And now you know why sepples is shit. It's such a clusterfuck of badly implemented features that learning a new languages is usually less effort than mastering it.

>IDE
emacs or death

emacs is an IDE

you're all just jealous

Jealous of not being able to find a job?
There are very, very few entry-level C++ jobs (in America at least) when compared to other languages.

>I don't mind my daughter having sex with other men, I just scoop out their cum before sex, haha
This is what you sound like

If you fully understand C++, yes, I am. Even a genius-level IQ isn't enough for that.

based and redpilled, also
>911

Emacs is the inverse of an IDE. It provides a common interface to the best tool for each job instead of bundling together mediocre vendor-locked ones.

Attached: whats an ide.png (480x480, 150K)

Literally what emacs is. Emacs is also bloat.

Attached: Integrated Designated Shitting Environment.png (665x267, 66K)

I drew that BTW. Not that anyone will care

>Emacs is also bloat.
emacs is the extension of being.
It's only as bloated as the modules you pump it full of.

>muh jobs
>>>/wdg/

Attached: bjarne.png (693x47, 3K)

also since it can run on an 80x24 RS232 terminal comfortably I'd say it's not too bloated

If you can do anything with template metaprogramming, can I make C++ print compile error messages for generics that actually make sense?

>It's only as bloated as the modules you pump it full of.
It's 43MB as default on Gentoo repositories. Even the bloated gvim is only 13MB

Attached: file.png (660x467, 78K)

it's amazing how bjarne can sell the exact opposite of what he previously sold everyone and yet they still buy it

Is Notepad++ an IDE?

No, just because it's bloated trash that's vastly inferior to the simple editor it's based on, doesn't mean it's an IDE.

It's got a lot in common with the Firefox of yesteryear (back when Mozilla respected its user base). It's hugely extensible because it's written in a language that can be harnessed by the user to fundamentally change its nature.
(emacs lisp)
Everything is an IDE unless it's name is TECO

Now VIM, that was a good editor *tokes juul*

it already does

o boy, I found my old wsdl parser!
ghostbin.com/paste/56ux2

>it's bloated trash that's vastly inferior to the simple editor it's based on
ive never read anything as dumb as this in m my life

no but you can often use static_assert

>t. the seething developer of notepad++

Sure, but why waste your time configuring every minute thing when you can just use (less bloated) defaults like vim/kate?

Attached: file.png (660x467, 74K)

>Literally what emacs is.
The keyword here is "facilities". Emacs does not provide things like a compiler, debugger or build system.
>Emacs is also bloat.
It was, 20 years ago. Not anymore.
Default Vim is shit, when I used it my config file was much longer than my Emacs config.

round(1/x), where x is your fraction

>kate
maybe some people don't use kde
but they should, kate is awesome

Why would you use anything other than a char array to store 3 digits?

>0.00007933989209774674
it's just 7933989209774674 / 100000000000000000000
then use euclid's greatest common divisor algorithm or whatever to reduce it

std::cout

It has a web browser and IRC client but not a debugger? I haven't used emacs for anything other than experimentation so I wouldn't know, but its defaults are definitely bloat. See I use xfce with some kde developed programs, but kde is just as good. I only prefer xfce for the default aesthetics, plus it's slightly quicker. For those who don't know, kate also has vim functionality.

You forgot to restore the stream state afterwards.

Because I'm reasonably comfortable with how it is set up by default, but occasionally I want to tweak something?

Vim feels uncomfortable and clunky to me no matter how often I use it (And I often have to on the machines of others).

And I can't comfortably run exclusively graphical editors kate on a plain-text or ssh remote connection with low throughput.

And have you ever bothered to check how large Kate is once you enumerate all the QT/KDE libraries it's linked to?

A barebones, text-mode-only emacs build is significantly smaller.

Also, most emacs settings are configurable via a GUI. Not too different from about:config, but it has a nice built-in documentation telling you what each option does.
(m-x customize)

My emacs config contains three lines of hand-written code, and that's because I wanted to spawn a shell in a side panel on startup when writing shell scripts, and a python interpreter side panel when writing python scripts, and an SBCL (common lisp) session when writing common lisp.

easter.c updated pastebin.com/U6qP4TYq

Floating point numbers are prone to roundoff errors so you generally can't get an exact fraction...

You may however produce good estimates by using "continued fractions".

i.e. if F(x) = 1 + (1/x) then sqrt(2) = F(F(F(...F(x)));

There are formulas like that for PI, sqrt(n), e, etc. Heaven knows how some where discovered...

But for your purposes do the process in reverse. The whole number part before the ffaction part won't always be 1, but the fraction always (1/something).

>It has a web browser and IRC client but not a debugger?
OK, so neither of those are built-in. Those are third-party programs that people wrote to integrate into emacs installs if the user downloads them.
That's like saying that Firefox has support for usenet newsgroups because you can install an addon for it.

Stop reddit spacing. It looks fucking terrible.

the C++ template preprocessor is turning-complete so you can calculate anything physically possible. however i don't think it has support for text output. at least in theory you could have it produce a binary that, when run, prints an error message to the screen

>reeeeeeeee
I bet you could write a user script to undo reddit spacing.

Attached: you1.png (159x43, 2K)

constexpr double PI = 22/7;

Attached: 1494871935189.jpg (369x387, 35K)

you can fire off static asserts if you want to terminate compilation

>ssh remote connection with low throughput
Not true at all. I've used kate to edit files on a lot of servers via SSH and never had a problem with throughput. Perhaps your 1B/s network connection is catching up to you, gramps

Also you can do the exact same thing with vim configs. There's not much of a difference between vim and emacs at the end of the day. The only reason I actually use kate is because I'm a lazy fuck that likes to use a mouse (with sidebuttons and keybinds) whenever possible.

So why's the default Gentoo repository for emacs 43MB? Is Gentoo bloat?

pls comment on code, I worked very hard

Attached: raf,360x360,075,t,fafafa:ca443f4786.jpg (360x360, 20K)

>turning-complete
I thought it could only go in a straight line

something like this will work, but float precision can fuck you.

Attached: 6273684563536.png (891x514, 29K)

dumb frogposter

youtube.com/watch?v=eDiSYp_51iY
the first 40 digits are burned into my memory thanks to this dumb song

i have no criticisms of the code or the cute anime girl

The code is poo-poo, and Horo was fucked by a pack of wolves

tmp in c++ is an anti-pattern

Attached: ss.png (661x530, 61K)

82nd for fuck anime.

>It has a web browser and IRC client but not a debugger?
Yes, because IRC clients are very simple, and the web browser was easy to cobble together for reading basic web pages from emails. The name should have tipped you off to the meme factor. It does not provide a debugger because debuggers are complex, and one written in Elisp (for a language other than Elisp itself) would probably be very slow.
>its defaults are definitely bloat. See
Emacs is mostly written in an interpreted language and includes many legacy features that are not generally used, but not worth getting rid of since they don't complicate the rest of the project. Its memory and CPU usage are very modest by modern standards, even if you use a lot of extensions.
Keep in mind that back when Emacs was bloated, a typical home computer had as much RAM as fucking Notepad uses in current Windows versions.

Why is everyone hating on C++? I have a psychology background and accidentally got into first MATLAB and then Python, but I want to learn a real language to learn more about programming.

turning complete?
What is the turning radius?

My situation yours is not.
If you're worried about bloat, but not worried about sending a shit-ton of uncompressed raster graphics down a tube to a machine you've just installed QT libraries on so you can edit your text comfortably, I think you may need to figure out your life.

>why is emacs 43MB
because gentoo decided to make the default configuration something that would please pretty much any emacs user; that is, the default configuration which also builds the X11 version.
Also it has it's own programming language, so there's that.

running 'configure' with the argument --without-all would give a better idea of size.

If they didn't:
>I installed emacs but I can't use truetype fonts! I have to compile it myself with fontconfig support or use bitmap X11 fonts REEEEE I hate gentoo, what the fuck
>I installed emacs but I can't use graphical mode in X11! Now I have to compile it myself REEEEEEEE
>I installed emacs but I can't make it give me audio warnings when I make a mistake because they didn't compile in ALSA! Now I have to compile it myself REEEEEEE
>The X11 build is too damn ugly for my precious eyes! Now I have to compile it myself if I want GTK+ because the gentoo devs wanted to save a few megabytes REEEEE
>I use Motif, not GTK+, so GTK+ looks super out-of-place! Now I have to recompile it with --with-x-toolkit=motif REEEEEEEE
>I want to be able to display images in a frame buffer, but those damn gentoo people decided to compile it with --without-jpeg to save space REEEEEE
>I need to debug emacs but those god damn gentoo guys decided to strip out the debug symbols in their config REEEEEE

So you see, it's easier to just enable stuff in the default config to make things more convenient for end users since most of us have terabytes of space, and even lower end stuff can have 500GB.

I had to compile qemu myself today because Debian decided to build it with GTK support but not SDL2.

they're seething cniles, don't pay attention to them

Attached: 423.jpg (881x246, 57K)

emacs doesn't have IRC though.

It's an extremely bloated and poorly designed language.

Boomer cniles and pythonbabies

not tested at all and i might be off by 1 in my exponent calculation because I don't remember the spec but i'm pretty sure this works
fraction doubletofraction(double number)
{
//IEEE754 doubles have 1 sign bit, 16-bit exponent, 47-bit mantissa
unsigned long exponent = reinterpret_cast(number & (FFFF > 47)
exponent -= 1

ERC, rcirc.

>tfw your template monstrosity finally compiles without errors

Also, if you're complaining about 43MB of space, you'd better be running uclibc, system V init, dash shell, and the *BSD utilities instead of GNU coreutils because those bytes add up.
And you better not own a single piece of Apple hardware/software (e.g. iTunes, XCode), and you'd better not have ever used any Microsoft-made compilers because they install gigabytes of bloated IDE's with them (if you use windoze).

but will it run without errors?
[wish I could use spoilers on Jow Forums]No[/spoiler]

That's reassuring, thanks. I thought it's a good language because you have to understand a lot of concepts and can later apply them to other languages.

That'd be normal C.
Once you can write C, it transfers to most other languages pretty easily, because most languages are more forgiving of laziness than C is. It's a good way to force good use of resources.

C++ is like a swiss army knife where there are four different looking but promising tools, but all of them are only good for stripping phillips head screws or cutting yourself.

try them both and disregard cniles such as

Are you one of the Cniles I've been warned off? Do you guys even know how confusing this is for people without a CS background? I'll go with C++ just to annoy you now.

Imagine the smell