[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 37
File: haskell.png (12 KB, 225x321) Image search: [Google]
haskell.png
12 KB, 225x321
old thread: >>52080378

Functional programming without backflips edition

What are you working on, /g/?
>>
>>52096815
First for D
>>
How do I become a better programmer? I'm pretty lousy.

What should I practice? Remaking old school assignments?
>>
Third for D
>>
>>52096843
Dogfooding (making something that is actually useful to you) is the best way to practice
>>
Fifth
#
>>
Working on a largely functional irc bot.
The connection (which is passed around everywhere) is the only source of side effect when you write to or read from it.
>>
D IS A MEME LANGUAGE THAT NO ONE USES
>>
>>52096874
And that's why I use it
>>
I hate everything on the market so I'm doing it myself. Pure samplers sound good but don't really play like pianos, and current modeling synths play great but sound like Yamaha CP80s, so I set out to make my own, with continuous pedaling and all that good stuff that real pianos do. All the little eccentricities and such.

Here's my current closest competitor in terms of playability and model accuracy, PianoTEQ:
https://a.uguu.se/zjrgns.mp3

And here's me:
https://a.uguu.se/otxypb.mp3

Sorry the mids are cut. Having some resonance problems with the model.
>>
>tfw programming a virtual machine
am i 1337 yet lads?
>>
>>52096891
Does it run on Windows 98? Does it run Windows 98?

If the answer to either of those is "No", then you can fuck right off you scum of the Earth
>>
Also daily reminder that if your language of choice is not on this list you should probably give up and kill yourself:
- C++
- C#
- Lua
- Python
- Elixir
- Haskell
- Bash
- Clojure
- D
>>
Reading SICP because of you lads, scheme is actually comfy af.
>>
File: opcodes.jpg (111 KB, 671x713) Image search: [Google]
opcodes.jpg
111 KB, 671x713
>>52096891
Forgot pic and the fact that I might have taken a wrong approach somewhere since there are supposedly pointers involved that can change opcodes themselves and I've been indexing instructions by array indexes

>>52096908
anon pls, it's still quite tough
>>
>>52096914
>no F#
>F# users should kill themselves

I agree
>>
>>52096928
>.py
that better not be fucking python
please tell me that isn't python
>>
>>52096943
it's just a programming challenge lad, not a serious virtual machine

but yeah hehe
>>
File: COgTPoyUYAAXo1T.png (76 KB, 300x301) Image search: [Google]
COgTPoyUYAAXo1T.png
76 KB, 300x301
>>52096914
Where is F#??
>>
>>52096914
Clojure a shit. Doesn't even have proper TCO or hygenic macros
>>
>>52096953
It's over here, mate: >>>/trash/F#
>>
File: ualb8.jpg (537 KB, 1280x1813) Image search: [Google]
ualb8.jpg
537 KB, 1280x1813
>pointers
O-one day I'll just feel when I'm using pointers correctly, right?

Object* pointer = NULL

stuff
stuff
function(&pointer);
stuff

Void function(Object* pointer_name)
{
if (stuff)
{
*pointer_name = stuff;
}
}


Is there an infographic for retards like me that don't know when to dereference a pointer and when not to? What I wrote is what felt right and I assume it's completely wrong.

Also, how do you access a pointer from a different class? Or rather, how are you supposed to access it? Include a pointer in the arguments of every function?
>>
>>52096914
>no vhdl or C
It is like you hate creating things
>>
>There are people too stupid to compute averages in a finite field containing positive and negative integers
>They think C is incapable of computing averages of signed integers because of this

int64_t signed_average(int64_t a, int64_t b)
{
// If a and b are not the same sign, we can safely add without overflow.
if ((a < 0) != (b < 0)) {
return (a + b) / 2;
}
// Otherwise, we take advantage of a particularly useful mathematical
// property: (a + b) / 2 is the same as (a/2) + (b/2). We will use a
// modulus to account for averaging two odd numbers.
else {
return (a/2) + (b/2) + (((a%2) + (b%2)) / 2);
}
}

uint64_t unsigned_average(uint64_t a, uint64_t b)
{
// All unsigned integers have the same sign (positive), and therefore we
// should only use the method which avoids overflow.
return (a/2) + (b/2) + (((a%2) + (b%2)) / 2);
}

#define avg(a,b) ((a<0)^(b<0) ? ((a+b)/2) : ((a/2)+(b/2)+(((a%2)+(b%2))/2)))
>>
File: 1438603709138.jpg (33 KB, 508x595) Image search: [Google]
1438603709138.jpg
33 KB, 508x595
I got a job in C# starting in Jan. They were receptive to me bringing in F# as long as it gets the job done. Should I learn C# and F# at the same time or just focus on C# first
>>
>>52096967
I really really am like fucking remedial when it comes to pointers and wouldn't mind getting my boipussy hammered until I got it mastered.

Is there anywhere that offers pointer specific exercises to help me get used to using them?
>>
>>52096967
If you use a higher level language, it will take care of that shit for you.
>>
>>52096988
C#. Programming jobs difficulty piles up quick due to bugs and shit. Learn F# in your free time and implement it where you can if it makes things alot simpler in places, but start in C# first. Otherwise progress will be hampered by your communication with other programmers too
>>
>>52096999
I don't want it to take care of it for me. I want to understand.
>>
>>52097008
ok, yeah, i've been reading a lot about it. i read the first 4 chapters of the c# in a nutshell book. i come from dynamically typed langauges so I think it'll be a mind fuck at first, but I'm seeing how a lot of the shit they invented is just to satisfy type checking while allowing flexibility (generics seem cool)
>>
>>52096967
You can use pointers just like any other value.

You dereference a pointer to get what is pointed to. E.g.:
int x = 5;
int *px = &x; // set px to the address of x
// px is the pointer
// *px can be treated like x
*px = 3; // set the integer px points to (x) to 3
int y = *px; // y = (what px points to) // y = x
px = &y; // px now points to y
>>
>>52096987
static inline int sign(int x)
{
return (x > 0) - (x < 0);
}

int average(int n, ...)
{
va_list args;
int avg = 0;
int odd[2] = {0, 0};
int zeros = 0;

va_start(args, n);

for (int i = 0; i < n; ++i) {
int val = va_arg(args, int);

if (val == 0) {
++zeros;
continue;
}

avg += val / n;

if (val % n != 0)
++odd[val < 0];
}

va_end(args);

avg += odd[0] / 2 - odd[1] / 2;

if (n % 2 != 0)
avg += zeros / 2 * sign(avg);

return avg;
}
>>
>>52096967

>when to dereference a pointer
When it points to valid memory

>when not to
When it doesn't point to valid memory

For errything else, please consult this:
http://cslibrary.stanford.edu/102/PointersAndMemory.pdf

>Also, how do you access a pointer from a different class? Or rather, how are you supposed to access it? Include a pointer in the arguments of every function?
You access pointers the same way you would access any other integer. Either as an argument to a function, via indirection from an argument to a function, or as some value that is global.
>>
>>52096987
I think we were all joking mate

I hope
>>
Is there any real reason to use vtables or function pointers in structs in C?
I see people try to emulate member variables all the time with C, yet it always looks redundant because there's no such thing as a self variable in C.
obj[j]->vtable->destroy(obj[j])
>>
>>52096987
>average: int -> int -> int
Your average function is broken.

>>52097037
Using ideone, this gives me a runtime error when I try averaging 2147483647, 2147483647 and 2147483647
>>
>>52097084
>this gives me a runtime error
It werks for me.
>>
>>52097082
You seriously need a good reason to do this.
It gets in the way of compiler optimisations as it usually cannot inline function pointers.
>>
rate my monkey code

#include <stdio.h>
#include <ctype.h>

void prse(char **p, int f[]);
void fb(char **p, int f[]);


int main(int argc, const char * argv[]) {
int i;
char line[1024];
int f[3]; //array of instructional data
char **p;
FILE *file = fopen(argv[1], "r");
fgets(line, 1024, file));
*p = &line[0];
while(**p != '\0') {
prse(p,f);
fb(p,f);
}
return 0;
}

void prse(char **p, int f[])
{
int i;
for (i = 0; i < 5; i++) {
if (!isspace(**p)) {
f[i] = **p - '0';
++*p; // increment index of line in main
}
}
++*p; // was left pointing to whitespace
}

void fb(char **p, int f[])
{
int i;
for (i = 0; i < (f[2]*x); i++) {
((**p) - '\0') % f[0] == 0 ?
((**p) - '\0') % f[1] == 0 ? printf("FB ") :
printf("F ") :
((**p) - '\0') % f[1] == 0 ? printf("B ") :
printf("%d ", ((**p) - '\0'));
*p += 2; //skips whitespace
}
}
>>
>>52097084
Why should the average of two ints not be another int?
>>
>>52097111
It returns an int. It probably doesn't work.
>>
>>52096886
Sounds really neat breh breh
>>
>>52097084
>Your average function is broken.
you dumb? we were always averaging 2 ints to another int
>>
>>52097124
The average of an odd number and an even number is not an integer.
>>
>>52097123

oops i can already see where i fucked up in prse

need to find a better way to handle whitespace
>>
Decided to give writing type providers in OCaml a try. Time to learn Swagger~
>>
>>52097082
Generally speaking it's probably not necessary. We use it at my work to define generic interfaces and get something similar to polymorphism, Ie. define a generic serial port structure with read()/write()/ioctl() function pointers. The application code can interact with this interface and not have to worry about which hardware specific serial port actually implements those functions.
>>
>>52097147
It is in an integer average function. Please tell me you're not new to this common programming function implementation
>>
>>52097142
No, we were averaging two ints.
It's not my fault that you think the average would be int -> int -> int

I guess it's just confirmed that no C "programmer" will ever write an average function.
>>
>>52097147
It can be depending on how we define what an average is.
>>
>>52097155
>Swagger
sounds like a language invented by a hipster with a beard who barely knows how to program
>>
>>52097166
..
I guess it's not your fault though, it's probably not even possible in C without some ugly hack. But I guess that's just what C is, a load of ugly hacks.
>>
>>52097166
I'm not a C programmer, but this is like saying an integer division should always return a float, you dumb shit. We are doing integer arithmetic, not regular non-programming mathematics
>>
>>52096961

why are most of the threads pokemon porn?
>>
>>52097188
I don't fucking know man
I don't fucking know

The one thing I do know is that when it was added, /mlp/ flocked to it as if /trash/ was their calling
>>
>>52097147

Well then maybe you should have floats for input, yes? The original point to the challenge was to have an integer average. As in a function (int, int) -> int. If you want a different kind of average, you should specify the type of numbers you want to operate on.
>>
>>52097181
>>52097166
>>52097142
>>52097147
>>52097084
he's going all out lads
>>
>>52097174
it's some hipster REST API framework thing. i honestly wouldn't be using it, except some guy showed me a demo of using it for an F# type provider on /dpt/ like 3 days ago and I decided to try my hand at doing the same thing in OCaml
>>
>>52097123

nested ternary operator bullshit aside (code tags killed my formatting anyway), is this a coherent, at least somewhat intended usage of pointer-to-pointer functionality?
>>
>>52097205
No it wasn't.
The point has ALWAYS been to right a function that averages two integers. I was there in the first thread in which it came up. /dpt/ still hasn't solved it cleanly. Even that copyright bitwise average underflows.
>>
>>52097054
>some value that is global
Oh, ok. I guess that's what I should have asked.

How do I access a global variable from a class? I setup a window global variable in main, then create a series of classes that all interact with the window variable. How do they play nice with that? I figured I needed to pass a reference to the variable everywhere.

>>52097034
Here's where I sit here staring at the code trying to force myself to follow.
*px = 3;
int y = *px;
px = &y;

I appreciate your commented explanations. I think my hangup is when you're changing an address and when you're changing a value. The asterisk denotes I'm changing a value, no asterisk denotes I'm changing an address. And I'll never put an ampersand in front of px. Continuing from your code:

int *ppx = &px; //*ppx is the address at px, or &y; ppx is 3; &ppx is ??
>>
File: tastingcitrus.webm (1 MB, 640x640) Image search: [Google]
tastingcitrus.webm
1 MB, 640x640
Ask your beloved programming literate anything

>>52096987
mine
int average (const int x, const int y) 
{
if ((x > 0) == (y < 0))
return (x + y) / 2;
const int xh = x / 2;
const int yh = y / 2;
const int xhr = x % 2;
const int yhr = y % 2;
return xh + yh + (xhr & yhr);
}
>>
>>52096879
giggle
>>
>>52097232
I don't know if you left dpt for a month and missed how each of the hundreds of integer average functions returned ints as if that was our actual challenge, or you are just trolling. A baby could average 2 ints and return a float without overflow, we have not been focusing on that
>>
>>52097244

>>52097231
>>52097231
i think i could have used a static global variable to hold the index of the array instead, but isn't that poor practice?
>>
>>52097244
underflow

>>52097239
If you want a pointer to a pointer to px, then you can do that - &px is the address of px, the address of the pointer. The type is int**, not int*.


>>52097263
>a baby could return a flow without overflow
there's more to it than no overflow
>>
>>52097128
Did you not put 3 as the first argument or something stupid?
>>
File: umaru :D's at your post.jpg (109 KB, 1920x1080) Image search: [Google]
umaru :D's at your post.jpg
109 KB, 1920x1080
multi-threaded linked list stack implementation
>>
does every /dpt/ have to turn into an aspie clusterfuck over averaging integers?
>>
File: wwwww.png (39 KB, 712x542) Image search: [Google]
wwwww.png
39 KB, 712x542
making gui not so fun :(

only 1,000,000 more hours of this tedium until i can work on real functionality

i'm building a program that lets me duplicate specific or all mouse/keyboard input to any processes or applications in the background. should be neat when its done. The actual part of the program that does work is written in C++ and has no gui.
>>
>>52097310
average (3, 4) = 3.5
>>
>>52097232

Well if you're going to be an anal tightwad, this should work on most platforms. On the platforms it doesn't, your language of choice probably doesn't have any implementations, so you have little right to bitch.

#include <float.h>
#include <limits.h>

// Assure the sum of two ints can always fit into a double
_Static_assert((sizeof(int) * CHAR_BIT <= DBL_MANT_DIG),
"Your C implementation is fucked. Try again on a sane platform");

double average(int a, int b)
{
double c = a;
double d = b;
(c + d) / 2;
}
>>
>>52097324
It's for an arbitrary n.
You need to put the amount of numbers you're averaging as the first argument.
>>
>>52097335

Not portable
>>
>>52097335

Wait, forgot the return keyword. Derp. I'm getting sloppy.
>>
>>52097341
Don't bother, the guy's an idiot who can't even comprehend integer arithmetic either
>>
>>52097295
If I want to declare a pointer for another pointer I have to use two asterisks at declaration?

Will I end up in a situation where I have to do some *&ppx thing or is that redundant?
>>
>>52096967
pointer is already defined as an Object* (object pointer), so you don't need to pass it into function with the ampersand. If you do that, inside of function you will have an Object**, not an Object*.

Inside of function, it should be "void" not "Void". The argument type (Object*) is correct. You could replace "*pointer_name = stuff;" with "pointer_name = &stuff;" which I think is a little more clear. "This pointer should be equal to the address of stuff" is what you're doing.

Does that make sense? Please point out (anyone) if I'm saying anything incorrect.
>>
Well, I guess it's once again confirmed that you literally can't average two integers in C.

Nice trying guys, even if most of the solutions you came up with were in the original thread.

Here's a better one that STILL underflows - and it's even patented!

http://www.google.com/patents/US6007232?dq=6007232

If Samsung couldn't do it, it's not your fault if you can't either.
>>
>>52097356
yes.
this is how you create a pointer to an array
**arr is as equally valid to *arr[]

I wouldn't be able to tell you how to create a pointer to a multi-dimensional array without resorting to (*arr)[j][k], because C is funny like that.
>>
>>52096967
Also, the function seems pretty redundant. Instead of calling it, just call pointer = &stuff. Sure, you don't do the "if (stuff)" check, but you should just do that once you actually use pointer anyways.
>>
>>52097346

Allow me to reiterate:

>On the platforms it doesn't, your language of choice probably doesn't have any implementations

On nearly all platforms, int is 16 or 32 bits, and the mantissa of a double precision floating point number is 53 bits. While an int is 64-bits on Tru64 Unix, I'm not even sure if Haskell has a port to that platform, because it's more or less dead.
>>
>>52097387
>he doesn't unroll his nested loops
>>
File: march.gif (562 KB, 625x503) Image search: [Google]
march.gif
562 KB, 625x503
Just made an ASCII ray-marcher
>>
>>52097123
Don't name functions "prse" (did you mean "parse"??) or "fb" (fizzbuzz?). Bad names, I wouldn't accept the PR.
>>
void average(int a, int b, void (*average_and_use)(int,int))
{
average_and_use(a, b);
}
>>
first for Go
>>
>>52097174
It's for API documentation...
>>
>>52097412
compiler does this shit for me desu senpai
>>
>>52097123
underage b&
>>
>>52097455
>he doesn't write his own code
>>
>>52097432

in my mind i was pretending it was part of some enormous, multi-programmer fizzbuzz fuckfest extravaganza where there might be namespace conflicts from (non-existent) #includes

but admittedly i don't know how that sort of thing is handled anyway
>>
import std.stdio;

void main(string args[])
{
writeln("Good night /dpt/!");
}
>>
>>52097392
Well, I was just saying 'stuff' as a standin for w/e. It wasn't specific. And I didn't mean to caps void, just a habit. None of this is specific to any problem. Just trying to stretch into using pointers without trial-error until it works.

But while I'm thinking about it, if everything is in one file, I can do

int *px = NULL;

int main(){
...
function();
}

void function(){
int x = 3;
px = &x;
}


But if I move function() to a different class, how do I manipulate *px?
>>
>The Haskeller will be a pedantic little shit until we implement a big decimal library from scratch in C and use that to compute an average, and make it portable to all platforms that support C.

Just because we can, doesn't mean it's worth our time to do so. Very regularly, when averaging integers, we want an integer result, or else we'd be using floating point numbers. When we want to work with arbitrary precision arithmetic, most C programmers turn to a third party library, because writing arbitrary precision arithmetic in a way that's actually performant is actually time consuming.
>>
>>52097521
This is bad because you're pointing to a variable that is only valid within 'function()'. As soon as you exit 'function()' you are going to be left pointing to invalid memory and using px is going to explode in your face.
>>
>>52097239
If you need to set up global variables across all files, just define them in a file and include that file wherever you need it:
http://stackoverflow.com/questions/2268749/defining-global-constant-in-c

But don't make things global unless they really need to be global. Typically, as you're figuring out, you'll want to pass references around between classes:

// my main file:
// Pass dependencies through the constructor:
const int WINDOW_COUNT = 4;
WindowManager* wm = new WindowManager(WINDOW_COUNT);
EventReceiver* eventReceiver = new EventReceiver;
FizzButler* fizzButler = new FizzButler(wm, eventReceiver);

// ....

// Pass dependencies through setters / functions:
FizzButler->setTourniquet(wm->getUser->getTourniquet);
// Or, if you don't want getters and setters, just:
FizzButler->tourniquet = &(wm->user->tourniquet);

>>
typedef struct
{
int floor;
bool plusAHalf;
} avg;

avg average(int a, int b)
{
return (avg) { (a&b)+((a^b)>>1), (a%2 != b%2) };
}


What do I win?
>>
>tfw you finish implementing the instructions for your virtual machine, but it won't run properly because the damn lambda functions aren't executing
What do lads?
>>
>>52097588
Give up
>>
File: opcodes.jpg (107 KB, 669x727) Image search: [Google]
opcodes.jpg
107 KB, 669x727
>>52097588
>tfw I keep forgetting to upload an image

>>52097596
but lad I'm so close, and when I ran someone else's vm using the same binary file, it started playing an adventure game, which is tight as tits
>>
>>52097431
Badass!

>>52097486
Lol if that was the case I think you would be erring on the side of subObjectFizzBuzzPrint and subObjectFizzBuzzParse or some shit - what if "fb" is the facebook integration library???
>>
>>52097606
Maybe don't use python
>>
>>52097587
>(a&b)+((a^b)>>1)
patented
>>
>>52097618
Why not? Anyways I fixed it, I made to sure to call the opcode with a () appended to it
>>
>>52097644
It's __shit__.and(sucks)
>>
>>52097521
>But if I move function() to a different class, how do I manipulate *px?

Hmm so if *px is a member variable of a class, you can manipulate it from another class in a couple ways. You could manipulate it directly (subClass->px = &x;), or you could have some setter function (subClass->setPx(&x));

If your question is specifically about how to let inner class manipulate the variables stored in your top-level main file, you could always just pass a reference in to that subclass. So when you instantiate subObject you could pass in &px as an argument - or set it later. If both the subObject and the main file are using the same address (ie. they're both storing pointers), they can then manipulate it at will and always be sharing the same value. Does that make sense?
>>
>>52097657
Quality answer lad, still using it
>>
well shit... somehow OPAM has been broken for months now and it's just barely managed to stay glued together because the bootstrap system was a fork of the main compiler that i manually installed. so now i have to figure out what the fuck is wrong with the entire package manager and find some configuration that works just to build this library im making
>>
>>52097617

printf("you're fucked ¯\_(ツ)_/¯");
>>
ffs

which dpt came before this one
>>52021427
>>
>>52097431

this is really fucking cool. is the source up anywhere?
>>
>>52097719
Obviously it's open source or he wouldn't mention it in /g/, let alone /dpt/

We're all Sons of Stallman here
>>
>>52097627

Actually, what is patented is using that method to compute an average "in a single instruction". So there's only going to be patent issues if you implement it in hardware.
>>
>>52097764
well damn
i guess someone finally did it
but can you average three integers in C
>>
>>52097757

it was a thinly veiled "please feed me your source" request
>>
>>52097663
I can edit the value of a private object member by assigning a pointer to the address of the member's function, right?

in thingy.h
thingy{
public:
thingy(); //in cpp, makes x = 3, and y = 4.14;
~thingy();
private:
int x;
float y;
}


back in main
thingy alpha;
int* pthingy = alpha->x;

*pthingy = 6;


Is that valid? Would alpha.x = 6 now or would I get a compilation error about permissions? And further, would that even correctly execute resulting in the int pointer referencing just the address of the int component of alpha?

I am trying to not be retarded, but for whatever reason, I can't seem to internalize how these work.
>>
what the fuck i've had to compile the entire OCaml toolchain 3 times already. why are all language package managers so broken?
>>
>>52097780

Be specific now. How do you want your input to be represented, and how do you want your output to be represented? Are the integers signed or unsigned. Should the average be an integer or a rational? How many bits in the input and output values? What platforms need to be supported?
>>
>>52097810
First for rust, join us in the future
>>
File: opcodes.jpg (46 KB, 667x273) Image search: [Google]
opcodes.jpg
46 KB, 667x273
Goddamn virtual machine bullshit, managed to run enough little-endian 16-bit instructions to print some text, but I don't get the cool adventure game at the end
>>
>>52097819
i think the task speaks for itself
>>
File: pl1ubbB.png (23 KB, 499x225) Image search: [Google]
pl1ubbB.png
23 KB, 499x225
>>52097829
I've used Rust a bit but I haven't really found a place for it in my daily programming desu

also WTF opam
>>
>>52097846

But it does not.

>average 3 integers
Are we talking ints here, or something bigger? int means different things on different platforms. The output is also of question. Do we want IEEE floating point? Do we want another integer (an integer average), or do we want to provide some other data type? You have provided no information here except that there are three input arguments, and that they are "integers". Without further clarification of the nature of the data we are working on, the question is meaningless.

(I can be a pedantic shit too)
>>
File: opcodes.jpg (219 KB, 1366x768) Image search: [Google]
opcodes.jpg
219 KB, 1366x768
>>52097832
Forgot to increment instruction if a jump fails, but I get this now. Is 32768-x not the equivalent of a 15-bit bitwise not of x? Using ~ turns it into a negative number which I can't access in an address
>>
>>52096928
What is "sets" supposes to do? Did you forget rhe return in your one-liners
>>
>>52097889
This is why everyone hates trip codes.
They're all complete fags.
>>
File: cpixel.png (3 KB, 413x170) Image search: [Google]
cpixel.png
3 KB, 413x170
How "bad" is this? Friend told me that I should never do something like this, better to load a file and dynamically read the colors in. I like it this way for now -- compile times are short currently (less than 0.2ms), it took about 15 seconds to implement, and it's very easy to change.

Is there an issue with my code, /dpt/?
>>
>>52097829
Don't call it a grave, it is the future you chose
>>
File: opcodes.jpg (15 KB, 255x141) Image search: [Google]
opcodes.jpg
15 KB, 255x141
>>52097916
r(x) is simply x-32768

Anyways I passed this:
>>52097903
It's 32767-x
>>
>>52097923
>Is there an issue with my code, /dpt/?
Nah, that shit is fine.
Didn't Quake or Doom do something like that too?
>>
File: 20_100810230106_1.jpg (47 KB, 397x277) Image search: [Google]
20_100810230106_1.jpg
47 KB, 397x277
How do you guys conceptualize and visualize your design for GUIs and/or webpages before coding them?
>>
>>52097964
With pen and paper.
>>
>>52097964
Pen and paper almost always. Occasionally, when working on something already built, I'll use Photoshop to visualize tweaks / new features. But for new screens, pen and paper.
>>
>>52097964
>before coding them
AHAHAHAHAHAHA
>>
File: opcodes.jpg (229 KB, 1366x768) Image search: [Google]
opcodes.jpg
229 KB, 1366x768
>>52097941
up to 17th instruction of 21, gonna have to trace my instruction calls to see how the fuck Call isn't performing as intended
>>
got some more music files I need to encode
wrote this:

#function that will track progress of encoding
tracker() {
c=1 #count
total=`find . -name *.flac | wc -l` #find out amount of flacs in directory, call that total
progress=`echo "( $c / $total ) * 100" | bc -l` #find percentage
prettyprogress=`printf %.2f $progress` #because nobody likes strings of zeroes
track="Now Encoding `printf %03d $c` out of $total, $prettyprogress% complete"
echo $track
}
export -f tracker #so other things can use that function

#TODO: fix the fact that I have no idea how to actually track this
find -name *.flac -execdir bash -c 'tracker; oggenc -q 5 -o ~/Music/"{}.ogg" "{}"; let c++' \;


function works if you just call it on your own
I don't actually know how to use find
>>
File: Untitled.png (2 MB, 1578x592) Image search: [Google]
Untitled.png
2 MB, 1578x592
I have spent over 3 days encoding this shit and it's still not done
Left: Original
Right: Antialiased
There's still heavy temporal aliasing, and angles steeper than 60 degrees look aliased, but there's jack shit I can do about that.

Source code:
http://pastebin.com/0TfYq69T
The algorithm was adapted from Doom9, originally intended for Avisynth, located at
http://forum.doom9.org/showthread.php?p=1737201#post1737201

Vapoursynth doesn't support YV12, which can be considered a cause of slowdown.

I don't think that it will be finished for a few more days yet.
>>
>>52098121
Both look the same to me
>>
>>52098121
Hardly looks better at all
>>
>>52098139
>>52098142
The one on the right will cut you with its edges.
The one on the left will leave you with a cruel and torn wound.
>>
>>52098121

wouldn't even notice the difference if I didn't already know what I was looking for
>>
>>52098161
You'll notice the difference in full screen with it upscaled.
Most upscaling algorithms retain the aliasing to horrifying levels.

Original
>>
File: opcodes.jpg (217 KB, 1366x768) Image search: [Google]
opcodes.jpg
217 KB, 1366x768
>>52098053
Ah call was supposed to be insI+=2 as that is the index of the next instruction. insI+1 contains the argument for call

Things are moving lads
>>
>>52098179
>FILE DELETED
why
>>
>>52097453
OH OK BECAUSE ITS NAMED SWAGGER IM SUPPOSED TO EXCUSE IT FROM SOUNDING LIKE A HOMOSEXUAL LANGUAGE K
>>
File: Untitled.jpg (252 KB, 1920x1080) Image search: [Google]
Untitled.jpg
252 KB, 1920x1080
>>52098179
Whoops, that one scaled incorrectly.

This one is saved as JPG because I honestly don't think it makes a difference for the purpose of this comparison.
Original
>>
>>52097657
Why do fuck are you using a hammer? Hammers suck! Screwdrivers rules.
>>
File: Untitled.jpg (261 KB, 1920x1080) Image search: [Google]
Untitled.jpg
261 KB, 1920x1080
>>52098199
Antialiased.

Because my computer can't actually handle upscaling it with autismo algorithms like NNEDI3 I'm considering upscaling it later.
>>
>>52098210
Python is not a hammer
>>
>>52098199
>>52098219
They look the fucking same man
>>
>>52097757
No, it's an obvious troll just running a video through a video to ascii-anim converter or mplayer/mpv with libcaca output.
>>
>>52098236
nigga I dare you to try watching the original in its full aliased glory
>>
>scala's Option can contain null
good language
>>
>>52098239
>implying anyone would lie on 4chan
>>
>>52098225
You're missing the point.

The point is was trying to make is "different tools for different jobs". Python and (for example) C are two completely different tools for very different scenarios.
>>
File: Untitled.jpg (279 KB, 1920x1080) Image search: [Google]
Untitled.jpg
279 KB, 1920x1080
>>52098253
I've actually been holding back.
This is how the original game looks.

The programmer is a fuckwit, his scaling algorithm is literally just some shitty ass bicubic
ALL OF HIS GAMES ARE LIKE THIS
>>
>>52098316
dude
it looks exactly the fucking same
>>
>>52098316
Dude...
It looks the exact fucking same!
>>
>>52098315
Yes.
C is appropriate for many scenarios.
Python is never appropriate for any scenario.
>>
Wait. Can someone describe the halting problem? I mean, there has to be a way for us to solve it. I mean we are able to, at least for some programs. We understand that some programs will always finish. Some programs won't finish. Some grow linearly and some grow exponentially.

Can't we just use a general intelligence to determine if a piece of code loops. I know it's way out of our technology right now but if you ask any programmer whether or not this code halts they should say no
while True: pass


Can't we get a ai in a hundred years to tell us this doesn't halt? Or are there some programs that is impossible to detect?
>>
>>52098619
>Alan Turing PROVED in 1936 that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist.
are you ready to step up to turing
>>
>>52098649
>>52098619
can someone explain to me why the halting problem is a real issue and why people care so much about this convoluted clusterfuck of mental gymnastics that bears zero relevance to how computers function in real life?
>>
>>52098619
The halting problem says that we can't make a Turing Machine that can take an arbitrary Turing Machine (possibly by its Turing number) and its inputs, and decide whether it will complete a computation. Sure, you can tell if SOME Turing machines are going to halt or not, but there is no algorithm for doing so in the general case.
If you want to solve the Halting Problem, come up with a method of computation more powerful than a Turing Machine.
>>
>>52098687
>why people care so much about this convoluted clusterfuck of mental gymnastics that bears zero relevance to how computers function in real life?
it's an elitist meme
>>
>>52098649
>general algorithm

Does that include AI as well? Because if an AI can look at a piece of code, it should be able to solve it. Well unless if there were such a program that is impossible to detect, but I don't think such exists.

I mean think about, any program revolves around two things. Making sure an infinite loop isn't in place, and making sure the conditional gets met. I think an AI would be good at that
>>
fib(8) using iteration:

fib(0) = 0
fib(1) = 1
fib(2) = fib(0) + fib(1) = 1
fib(3) = fib(1) + fib(2) = 2
fib(4) = fib(2) + fib(3) = 3
fib(5) = fib(3) + fib(4) = 5
fib(6) = fib(4) + fib(5) = 8
fib(7) = fib(5) + fib(6) = 13
fib(8) = fib(6) + fib(7) = 21

fib(8) using recursion:

>Error: Too many lines.
see pic

which is more elegant and useful?
>>
>>52098687
This is what happens when you let people who didn't go to university be programmers.
It's important because it demonstrates that there are things that computers cannot compute.
>>
>>52098751
obviously if you give it an impossible task and give it no way of giving a nuanced answer it's not going to give the right answer. it's like asking 1 + 1 and only accepting the answers 0 and 1. the question is malformed.
>>
>>52098751
alright, so a computer cannot compute if a computer designed to not compute things can compute itself

so groundbreaking
i'm sure this will yield endless insight into the world of systems programming
>>
FUCK THIS GAY EARTH.

I'm trying to get JSon from a website on android and it says that I can't have that happen in the main thread.

God I just want to program yet all I'm doing is fucking around the web trying to get things in place.
>>
>>52098778
are you from /wdg/
because you dont belong here
>>
>>52098782
just create another thread, pajeet
>>
>>52098742
wrong thread, retard
>>52085440
>>
>>52098776
>the question is malformed
What? No it's not.

>>52098778
It's usually used in the proof that other things are not computable. "If X is computable, then we can solve the Halting Problem" or whatever.
>>
>>52098790
are you from /sci/
because smug ivory tower wankers like you don't belong here
>>
>>52098742
iteration for anything that could be an infinite iterable

recursion is for shit that will typically end on a condition more specific or complex than performing an operation x times, like in adventofcode day 22, I would use recursion to simulate the battle fight until the boss is dead
>>
>>52098793
I can't into threads. Also not indian.
>>
>>52098810
just use OpenMP, it's easy modo for multithreading
all you have to worry about are race conditions
>>
>>52098801
Hey guys, this whole O(N) notation thing is kind of shit
Can't we just disprove everything after O(1)?and make everything constant time? FFS
>>
>>52098813
Thanks for pointing me somwhere, anon. Maybe I'll take this chance to learn threading or something.

That is if AsyncTask fails.
>>
>>52098619
The halting problem concerns whether or not there exists a function that, given a function and its input, returns TRUE if the function would halt on that input and FALSE if the function would not halt on that input.

Unfortunately this is impossible and the proof is really quite simple.

Suppose that there existed a function, H, which was the solution to the halting problem.
We can define a function, f, like so:
function f(arg)
if H(f, arg) then loop forever
else return 0
end

If f would halt with its arg, then it doesn't.
If f would loop forever with its arg, then it returns.
Thus, it's undecidable whether
H(f, f)
would halt because either one would result in a contradiction.

>>52098687
How many times have you written something and forgotten a base case for recursion or forgotten to change your counter in a loop or something like that? You run your program and wait. And wait. And wait. And eventually you decide you made a mistake, but what if you hadn't? What if the program is just taking a long time to compute what you asked it to compute?
It'd be really nice if we could save a lot of time and not have to wait until we're pretty sure that the program is never going to end to decide that we made a mistake and instead just ask the computer if it does.
The computer cannot do this though. Some trivial cases can be caught but there is no general solution. Even if you view a computer as a piece of real hardware and not some abstract concept, there are way too many possible states in the hardware so it's very impractical to check all the states to see if we would eventually halt. That could take centruies.
>>
>>52098842
s/would halt because/returns either TRUE or FALSE because/
>>
>>52098842
>How many times have you written something and forgotten a base case for recursion or forgotten to change your counter in a loop or something like that? You run your program and wait. And wait. And wait. And eventually you decide you made a mistake, but what if you hadn't? What if the program is just taking a long time to compute what you asked it to compute?
It'd be really nice if we could save a lot of time and not have to wait until we're pretty sure that the program is never going to end to decide that we made a mistake and instead just ask the com
this is what debugging is for
if your program is taking a long time to do something and the rest of the application hangs, you invariably fucked up somewhere
>>
>>52096886

Do you have a page dedicated to your project?

I'd like to know more about it.
>>
>>52098863
Maybe you are using some huge input and your expected runtime even for a correct implementation is measured in hours instead of seconds or minutes.

This maybe isn't familiar because computers are pretty fast right now and computation on huge datasets isn't something most people are exposed to but think back to the days of punch cards or even when you'd have to burn your program to PROM to run it. Not only were computers slower, there was a ton of overhead to just get the program running in the first place.
>>
>>52098818
>hurr i'm so smart for understanding the halting problem and O(n) notation xDD i'm just gonna masturbate with all this enlightenment xDDD
>>
>>52098190
Passed this one, and now have nonzero reg as my next failure. Things are moving again lads. My first vm is almost complete
>>
He's really hung up on this
I wonder if he thinks P = NP
I'm sure he thinks a thread on 4chan can answer that
>>
TIL json parsers apparently can't function during compile time
>>
>>52098940
P != NP obviously
>>
>>52097295
>underflow
how
>>
>>52098944
>TIL
Go back to reddit, you fucking fag.
>>
>>52098619

>I mean, there has to be a way for us to solve it.
I hate to break it to you, but there are an infinite number of unsolvable problems. Furthermore, nearly any interesting question about what a turing machine is going to do with a given input is, in general, unsolvable.

>>52098778

It means that, more or less, it's impossible to make a perfect debugger.

>>52098959

I'd love to hear your reasoning.
>>
>>52098978
crawl back up your mom's pussy and grow up nigger
>>
File: opcodes.jpg (78 KB, 667x519) Image search: [Google]
opcodes.jpg
78 KB, 667x519
>>52098938
I-I did it lads

I have executed 16-bit little-endian pair instructions and made game
>>
>>52098989
Careful of that edge, bro.
>>
>hurr maybe it's possible to solve this NP-complete problem in polynomial time because reasons xD we just don't know xD maybe god or allah or zeus exists, who knows xDDDDD
>>
>>52098964
mean of 1 and 2 is 1.5
>>
File: opcodes.jpg (206 KB, 1366x768) Image search: [Google]
opcodes.jpg
206 KB, 1366x768
>>52099004
I don't know how they had the time to put all this shit in a 59kb binary file that didn't initially have this text. That's a fuckload worth of memory address manipulating
>>
>>52099028
that's not an underflow.
>>
>>52099058
mean(1, 2) -> 1 is underflow
>>
>>52099065
https://en.wikipedia.org/wiki/Arithmetic_underflow

an underflow is, for example, INT_MIN - 1
>>
File: opcodes.jpg (292 KB, 1366x768) Image search: [Google]
opcodes.jpg
292 KB, 1366x768
>>52099036
Am I a hacker now lads?
>>
File: opcodes.jpg (69 KB, 801x631) Image search: [Google]
opcodes.jpg
69 KB, 801x631
>>52099101
fucking grues

/blog, I'm gonna go solve the rest of it
>>
>>52096987
it still took you this long to do it. like how many weeks has it been since anon first posted the challenge?

int avg(int a, int b)
{
return b != 0 ? a / 2 + b / 2 + (a % b % 2) : a / 2;
}
>>
>>52099129
write a program to find the path
>>
>>52099065
it's truncation, which is correct for integers unless specified otherwise
>>
>>52099142
assert(avg(1,2)==1.5)
>>
>>52099155
>i don't know what an int is
go back to >>>/g/wdg >>>/vg/agdg
>>
>>52099154
the moment you say average(int, int) returns int in all cases, you have failed
>>
How do I get the power of 2 from a number?

E.g. how do I get 2 from 4 (since it's 2^2)
>>
>>52099145
nigga the program runs on around 30,000 16-bit instructions/values scattered in a binary file. I'm not nearly pro enough to brute-find a path that gets me an end result I'm not sure of

maybe one day
>>
>>52099168
>I don't know what an average is
Not my problem your function is broken

>>52099171
Log
either Log2(x)
or Log(x) / Log(2) (they're equivalent)
>>
>>52099170
kill yourself retard

unless specified otherwise:

average(double, double) returns double

average(float, float) returns float

average(BigDecimal, BigDecimal) returns BigDecimal

average(int, int) returns int

etc.
>>
>>52099182
Not him, but it's clear you've never programmed in your life if you've never heard of integer arithmetic. Next you're going to throw a hissy fit because 9/4 is equal to 2
>>
>>52099182
my function is 100% accurate and consistent

https://en.wikipedia.org/wiki/Rounding#Rounding_to_integer
>>
>>52099170
Stop with your shitty bait, m8.
f: a^2 -> a
Anything else is retarded.
>>
>>52099199
100% accurate for (even, even) and consistently wrong for average(odd, even)
>>
>>52099205
>4chan replaced my integer 'Z' with 'a'
wat
>>
>>52099210
https://en.wikipedia.org/wiki/Rounding#Rounding_to_integer

https://en.wikipedia.org/wiki/Rounding#Rounding_to_integer

https://en.wikipedia.org/wiki/Rounding#Rounding_to_integer

today babby learned that there is more than one way to round to the nearest integer
>>
>function dealing mostly with integer division shouldn't return integer
Is this the state of dpt nowadays?
>>
>>52099218

Did you change int so that it's no longer an integer (but only for the return value)?
No?

Then it's still a broken average function, isn't it?
>>
>>52099235
the fuck are you even on about

>>52099231
assburgers think they're welcome just because we have autists here
>>
>>52099246
This guy had the right idea
>>52097587
>>
Am I doing this parallel thing correctly?
#include <stdio.h>
#include <omp.h>

int main(void)
{
char str[] = "Hello World";
#pragma omp parallel
{
unsigned i;
for (i = 0; i < 11; i++)
{
putchar(str[i]);
}
putchar('\n');
}
return 0;
}
>>
>>52098619
> Can someone describe the halting problem?
Determine whether a specific program given a specific input will eventually halt, or whether it runs for ever.

The interesting point about the halting problem is that the general case is provably insoluble, i.e.there must be cases for which the answer is "don't know".

> I mean, there has to be a way for us to solve it. I mean we are able to, at least for some programs. We understand that some programs will always finish.
Any program which only contains bounded loops will terminate eventually. If a program contains unbounded loops (while loops, which includes C's "for" loops), determining whether it terminates boils down to determining whether a given condition will ever be true. That's roughly equivalent to "solving" mathematics, which is also impossible (see Goedel's theorem).

> Can't we just use a general intelligence to determine if a piece of code loops. I know it's way out of our technology right now
It has been proven that are cases where it's impossible to determine. Not "we don't know how to solve it, yet", but "it provably cannot be solved". Clearly, the set of cases which can be solved will grow over time, but we already know that no general solution exists.

> Or are there some programs that is impossible to detect?
Yes. That's the point.
>>
>>52099263
>This guy had the right idea
Not him, but yes, for flexibility, but that doesn't prevent integer arithmetic from being integer arithmetic
>>
>>52097317
le multibox
>>
>>52099282
It means you're lying when you call it an average function.

Why can't you just write a monad to bind it back to an int between each operation?
>>
http://strawpoll.me/6382880
>>
>>52099296
>I got the delta quadrant
>>
File: 1450369221617.png (80 KB, 694x732) Image search: [Google]
1450369221617.png
80 KB, 694x732
>>52096815
Well /g/
>>
>>52097587
> What do I win?
You don't, you lose. Applying &, ^ or >> to negative integers is implementation-defined, and the implementation is allowed to "define" it as undefined behaviour.

Also, if you're going to post a solution to a problem, you should probably state the problem. There's more than one version of the "average two ints" problem that's done the rounds here recently (e.g. whether to round like round() or like integer division).
>>
>>52099293
would you say

double avg(double a, double b)
{
return (a + b) / 2;
}


is lying? why/why not? did you know that avg(1e60, 1e70) returns 5.0000000005e69 instead of 5e69?
>>
>>52099293
>It means you're lying
Doing integer division is lying then
Rounding functions typically return a float so they're lying too, but it's because they take a float and therefore use float arithmetics

Floats in general aren't even the exact value you set them to
>>
>>52099312
there's a gnu c extension for nested functions, but it's nonstandard garbage
>>
>>52099312
So long as you don't use C, it should be fine. It's literally impossible to average 2 ints in C.
>>
>>52096928

>windows
>onedrive
>horrible python structure
>camelcase

it's like he deliberately wants to be shot.
>>
>>52099088
> an underflow is, for example, INT_MIN - 1
Um, no. Try actually reading the linked page, rather than just the first sentence.

"Too small" does not mean "too negative". It means "too close to zero" i.e. "too small in absolute magnitude".

Underflow only applies to floating-point, and occurs when the result's exponent is less than the lower limit but the result isn't exactly zero. Floating-point overflow occurs when it's greater than the upper limit but the result isn't infinity.

Signed integer overflow occurs when a result is greater than INT_MAX or less than INT_MIN (or the equivalent for other signed integer types), effectively resulting in a carry overflowing into the top-most bit (which determines the sign).
>>
>>52099267
No. All of your threads are sharing an unprotected resource (stdout), which can lead to a race condition.
>>
>>52099357
what's wrong with windows?
onedrive is where my files went since I bought this laptop
I think the structure looks nice
I did camelcase to differentiate between non-opcode functions and opcode functions especially since it's bad practice to override in-built functions, so I wanted to be consistent and have everything camel instead of just Set being camel
>>
>>52098619
underageb&
>>
Can /dpt/ average two floats in C?
>>
How do I display my code on here again? I almost never use this function.
>>
>>52098731
AI is still in the class of Turing machines, it doesn't have special powers because it's an AI algorithm.

It is computationally impossible to determine whether an arbitrary Turing machine will halt.
>>
>>52099395
a/2 + b/2

Haven't tried C so not sure what the rest of the program would look like
>>
>>52099318
> avg(1e60, 1e70) returns 5.0000000005e69 instead of 5e69?
It doesn't help that neither of the arguments can be represented exactly.
1e60 = 999999999999999949387135297074018866963645011013410073083904
1e70=10000000000000000725314363815292351261583744096465219555182101554790400
>>
>>52099402
see >>51971506
>>
>>52099415
Holy shit how did they type it out?
>>
>>52099413
>1e60
>1e70

>but neither can be represented exactly
>>
>>52099413
that's completely beside the point
>>
>>52099318
> did you know that avg(1e60, 1e70) returns 5.0000000005e69 instead of 5e69?
Why do you think it should return 5e69?
avg(0, 1e70) should return 5e69. And in fact, it does (not really surprising, averaging a value with zero will just decrement its exponent while leaving the significand unchanged).
>>
>>52099430
MOODS = GOODS
>>
>>52096988
>gets a job in C#
>doesn't know C#
top fucking kek, get ready to be fired the same month
>>
>>52099450
Yeah he's a nob, now refute the post under his
Thread replies: 255
Thread images: 37

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.