/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

informit.com/articles/article.aspx?p=1959565&seqNum=13
en.wikipedia.org/wiki/Curry–Howard_correspondence
en.wikipedia.org/wiki/Wave_function_collapse
en.wikipedia.org/wiki/Bell's_theorem
twitter.com/SFWRedditImages

#include

#include

#include

#include

using namespace std;

int main() {

cout

My code is spitting out -nan(ind) and not printing averages. Do you guys know what I'm doing wrong?

Write a program that shows if a post number is a dub, trip, quad, quint, etc!

int main(void)
{
size_t n = 999999999;
while (++n)
{
char buf[100];
sprintf(buf, "%zu", n);
int i, j = 0, len = strlen(buf);
for (i = len - 1; i > 0; --i)
{
if (buf[i] != buf[i - 1])
break;
else
j++;
}
if (j > 1)
{
const char *names[] = {
"singles", "dubs", "trips", "quads", "quints",
"sextuples", "septuples", "octuples", "nontuples"
};
const char *str = names[j];
static char tuple[20];
if (j > 8) /* for extra large gets */
{
sprintf(tuple, "%u-tuples", j);
str = tuple;
}
fprintf(stdout, "%s - %s!\n", buf, str);
}
}
}

Yes. Stop using using namespace std; , and std::endl

> interfaces are a "standard language feature".

Show us your solutions to the Expression Problem using the paradigms your programming language designer has forced upon you.

Lets use Wadler's original example language, where we initially have a datatype of Expr = Num and an eval function. We want to add a datatype (Add : Expr Expr -> Expr) and a function show : Expr -> String

That's what's giving me the error?

>access modifiers are a "standard language feature"
Shows us your solution to the expression problem using access modifiers, pluslet. Access modifiers BTFO!!! Sepples monkeys are literally subhuman.

Who mentioned sepples?

I just want to see what solutions you brainlets can come up with, if any, using language of your choice.

in Haskell this is just

data Fix f = Fix (f (Fix f))
data Sum f g a = Sum (Either (f a) (g a))
data Pair f g a = Pair (f a, g a)
data Identity a = Identity a
data Const a b = Const a

data ExprF a e = ExprF (Sum (Const a) (Pair Identity Identity) e)
data Expr a = Expr (Fix (ExprF a))


as well as 1000 lines of functor, applicative, monad, traversable, show1, read1, etc instances

What does it have to do with interfaces, fucktard?

Daily reminder that programs are not proofs!

Someone mentioned it in other thread and I laughed. Interfaces are only needed if you've adopted a specific paradigm and it just happens that the expression problem is a bitch to solve in that paradigm (lots of boilerplate).

the only solution
even works with negatives
public static void checkem(int postNumber) {
switch(repeatingDigits(postNumber)) {
case 1: System.out.print("Nice singles!");
break;
case 2: System.out.print("Nice doubles!");
break;
case 3: System.out.print("Nice triples!");
break;
case 4: System.out.print("Nice quads!");
break;
default: System.out.print("Nice get!");

}
}

public static int repeatingDigits(int num) {
int digit = num%10;
int i = 0;
while (num != 0) {
if (num %10 != digit) break;
num /= 10;
i++;
}
return i;
}

proof it

Opinions on using nested arrayLists in terms of performance as to save and find nested information for a 2D character?

Go write me a proof that can edit text, user.

I'm trying to match a boolean expression with
[^tTrRuUeE|FfAaLlSsEe]


but this will match for example "sese".

I only want to accept "true" or "false"

what do?

>Interfaces are only needed if you've adopted a specific paradigm
Care to explain the source of this weird delusion?

>it just happens that the expression problem is a bitch to solve in that paradigm
What does it have to do with interfaces?

s/(true|false)/i

fix id

what is this for?

>doubles are a subset of integers
>just Sup Forums things

The only valid answer:
((t|T)(r|T)(u|U)(e|E))|((f|F)(a|A)(l|L)(s|S)(e|E))

>makes retarded post
>screenshots it
>attempts to attribute it to random people
>thinks anyone paid attention to his schizophrenic shenanigans and knows what he's talking about
Mental illness at its finest.

(t|T)(f|N)

this matches the string "eruerueureuuuuuueeee"

retard

Actually, it doesn't, fucktard, but I'm glad you're taking it so seriously.

obviously it matched his filter

Wouldn't this just be /(true|false)/ig?

getAttemptPanel is returning null. any reason why?

public class CodeBreakerUI {


private JPanel attemptPanel;
private JPanel colorPanel;
Codebreaker codebreaker;


public CodeBreakerUI(Codebreaker cb)
{
Codebreaker codebreaker = cb;
initComponents();
}
private void initComponents()
{
JPanel attemptPanel = new JPanel();
JPanel colorPanel = new JPanel();

attemptPanel.setMinimumSize(new Dimension(200, 400));
colorPanel.setMinimumSize(new Dimension(550, 60));
attemptPanel.setPreferredSize(new Dimension(200, 400));
colorPanel.setPreferredSize(new Dimension(550, 60));

attemptPanel.setBorder(BorderFactory.createTitledBorder("Codebreaker Attempt"));
colorPanel.setBorder(BorderFactory.createTitledBorder("Codebreaker Colors"));
}

/**
* @return the attemptPanel
*/
public JPanel getAttemptPanel() {
return attemptPanel;
}

bros I've started learning process and thread API and I'm struggling with it. All this pointer nonsense in C is hurting my brain, am I retarded?

Any good reading material on this stuff I've been coasting till now.

You're initializing a local variable in the initComponents function rather tha initializing the class member. Or at least that'd be the case in C++, I don't really know Java but it seems to be the case for you as well.

this is correct

So I'd move both JPanels to the CodeBreakerUI constructor?

Saw this and wanted to take a stab at making it more ergonomic.

#include

template struct
is_interface
{
struct interface_size { virtual void f(); };
static constexpr bool value = std::is_abstract() && sizeof(T) == sizeof(interface_size);
};
templatestruct
interface : T{
static_assert(is_interface::value,"invalid interface");
};


struct some_interface{
virtual void foo() = 0;
//int x;
};

struct test : interface{
//blah blah blah
};

No, just get rid of JPanel type in front of these variables. Might need prefix them with this. or something, not sure how it works in Java.

no you would just do
attemptPanel = new JPanel();

or if you want to be more verbose you can do this.attemptPanel

You both are gems, love ya

>What does it have to do with interfaces?

It just happened to be what the brainlet in the other thread was arguing about with "my favourite language is better than yours because you don't have interfaces built in". It reeks of "I only know how to program in one paradigm, because my PL designer holds my hand".

It happens that interfaces are a shit tool for solving the expression problem, which is why I brought it up. Turns out that PL designer holding your hand only gets you so far, but eventually he gets in your fucking way - because he didn't leave you the right primitives to solve more general problems, only a few higher level tools to solve a subset of problems.

You're not retarded, it's just hard. Keep at it. Then try out something like go

learn ____ and you'll never be hungry again

>"my favourite language is better than yours because you don't have interfaces built in"
Except no one was arguing that at any point, fucktard.

>It happens that interfaces are a shit tool for solving the expression problem
What do interfaces have to do with the expression problem, fucktard?

>It reeks of "I only know how to program in one paradigm, because my PL designer holds my hand".
That's actually what your post reeks of, what with your mindless lashing out and irrelevant whining about how interfaces don't solve whatever problem your functional toy language happens to be good for.

>learn ____ and you'll never be hungry again
Learn to enjoy eating from dumpsters.

cobalt

to fish

keep it programming related

Is this true, /dpt/?

more java shit. My JMenuBar and all of the JPanels are not visible.
public class MasterMindUI {
Game game;
CodeBreakerUI cbui;
CodeMakerUI cmui;
JFrame frm;
JMenuBar menuBar;
JMenu helpMenu;
JMenu gameMenu;
JMenuItem newGameMenuItem;
JMenuItem exitItem;
JMenuItem aboutItem;
JMenuItem rulesItem;

public MasterMindUI(Game newgame)
{
game = newgame;
Codebreaker cb = game.getCodebreaker();
Codemaker cm = game.getCodemaker();
cbui = new CodeBreakerUI(cb);
cmui = new CodeMakerUI(cm);
initComponents();
}
public void initComponents()
{
helpMenu = new JMenu();
gameMenu = new JMenu();
frm = new JFrame();
menuBar = new JMenuBar();
newGameMenuItem = new JMenuItem();
exitItem = new JMenuItem("Exit");
aboutItem = new JMenuItem("About");
rulesItem = new JMenuItem("Rules");

exitItem.addActionListener(new exitListener());
aboutItem.addActionListener(new aboutListener());
rulesItem.addActionListener(new rulesListener());
Dimension frame = new Dimension(300, 600);
frm.setSize(frame);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setLayout(new BorderLayout());
menuBar.add(gameMenu, helpMenu);
gameMenu.add(newGameMenuItem);
gameMenu.add(exitItem);
helpMenu.add(aboutItem);
helpMenu.add(rulesItem);
menuBar.add(helpMenu);
menuBar.add(gameMenu);
frm.setJMenuBar(menuBar);
frm.add(cbui.getAttemptPanel());
frm.add(cbui.getColorPanel());
frm.add(cmui.getSecretCode());
frm.add(cmui.getCodemakerResponse());

menuBar.setVisible(true);
frm.setVisible(true);

}

>no you're not retarded, but you can still be retarded like me

keep at it dog. Pointers are a bitch but you'll get them.

Do compiler parsers and lexers use regex to identify tokens or do they use other methods?

>implying agdg can even use a computer
drag and drop is almost too tough for half of them.

WHAT
THE
FUCK

Just like your wife's anus gets conditioned to accommodate her bulls big black cock your brain gets used to pointer bullshit.

Sorry i meant cobol

>game programmers see world in oop
well duh

Look, the fact that you're so caught up on interfaces, which were last thread, is really showing how autistic you are.

I merely quoted interfaces from last thread as an example of "paradigm which your PL designer forces on you", but what I really wanted was a more general discussion on alternative ways to solve EP.

Also, you started lashing out from first reply, where I've tried to post calm replies and not respond to your bait.

Now solve the fucking expression problem in Java and C# without looking like an absolute prick and I'll drop it!

Game programmers see the world in OO,
and Haskell user see the world as a huge function?

>you're so caught up on interfaces
It's not about interfaces, though. It's about the fact that you can't fathom anything beyond whatever pure functional memery you've been indoctrinated with, so the mere mention of OOP-sounding terms makes you lash out irrationally and everything and nothing.

>I merely quoted interfaces from last thread as an example of "paradigm which your PL designer forces on you"
But you only think it's an example of that because you're a FP cultist.

>Now solve the fucking expression problem in Java and C#
I don't care about Java or C#. Why should I solve it in Java or C#, you absolute mongoloid?

There was this one time when I was learning lisp when I haven't sleep in several days, I have legit begun seeing things as lists.

>Haskell user see the world as a huge function
so do physicists

monads

you put a world in, you get a world out.

WHAT THE FUCK DID YOU JUST FUCKING SAY ABOUT MY PROGRAMMING LANGUAGE YOU LITTLE BITCH

I said its shit.

Wouldn't it be more like you put a world in and you get a function or container that returns a world out?

JavaScript:
you put world in, you got 1 out

How do I check to see if there's a carryout in the addition of two characters? i.e:

1111 1111 + 1 (both 8 bits) = 1 1111 1111

Is it sufficient to cast to a short and simply mask it with 1111 1111 0000 0000 and if it returns 0, then no carry out, else, there was a carry out

>__forceinline static __inline__ __attribute__((__always_inline__))

String/ numeric literals might use regex. Recursive constructs will use a state machine which can be generated from a specification language such as BNF.

Addition that results in a carry is UB, you can't detect it because the optimizer will assume it doesn't happen

UB?

if ( (input.a > 0x88) && (input.b > 0x88))
{
//it's always have overflow
}
if ( !((input.a > 0x88) && (input.b > 0x88)))
{
//it's never overflow
}


im to lazy to think about if one is smaller that 0x88

undefined behavior

Undefined behavior.

I don't understand how? I mean if I have two chars, a and b, I figured I could do something like this:

unsigned char a = 255;
unsigned char b = 32;

short sum = (short)a + (short)b;

if(sum & (~255))
//carry out
else
//no


checking if there are any bits 16-9 that are set. If there are, then we know there was carry out

...

what is the purpose of this?

writing an 8080 emulator and writing functions to set the flags

set half carry if(target & 0xF) + (value & 0xF)) & 0x10)

set carry if (result > FF)

actually...

set half carry if( (target & 0xf) - (value & 0xf) < 0)


Dumb is I

I've gone through a beginner C++ book and have done a lot of (entry-level) programming exercises. Is CLRS right for me?

Thanks, this makes more sense. I need to figure out how to abstract it for various operations. interestingly, the half carry (auxiliary) bit is set to 1 if it carrys inward as well. I.e:

0001 0000 - 1 =
0000 1111 -> set half carry

CLRS is more of a mathematical book. It's less about implementing algorithms than about analyzing them. If you're looking for something more about programming and writing good/clever programs, I suggest SICP.

Source: Studying CLRS right now

If that C++ book is stroustrup's book which is more of a general programming book, then yes, go ahead.

Please learn at least one language that isn't C++ though.

This might be helpful

informit.com/articles/article.aspx?p=1959565&seqNum=13

Checking this book out from my university library because it's also got parity count. Thanks for the recommendation!

What's this?
en.wikipedia.org/wiki/Curry–Howard_correspondence

That's only true in classical mechanics.

en.wikipedia.org/wiki/Wave_function_collapse

I'm making a small text based adventure game using javascript for my webdev class. Only 19 different events will happen, what kind of data structure should I use?

I was thinking a binary tree with the landing page being the root. Does that make sense?

It's no problem you'd run into that book eventually.

It's one of the big book recommendations for low level optimizations.

Quantum field theory is built on operator-valued functions.

Wave functions which get set!'d when the wavefunctions collapse.

That means
psi(x) = a(x) + b(x) + c(x)

randomly gets changed to:
psi(x) = b(x)

Or one of the other 3 at random. That's stateful user.

Also quantum mechanics either has nonlocality (spooky) or true randomness. True randomness isn't a function.
en.wikipedia.org/wiki/Bell's_theorem

Face it. Haskell doesn't correspond with reality.

Has anyone ever written a programming the implemented the 9p protocol? If so any resources you recommend?

Fun fact: by learning C++, you are indirectly learn C.

and if you know C then you can forget about C++

I'm this user.

Got the test, it's 90 minutes with 2 questions, 1 easy and 1 difficult, and they say you can use any language but they give priority to those who write in Python or Node.js. Have to take the test by Monday.

Java is pretty much the only language I've used extensively, but I've been trying to learn some python lately to write a bitcoin trading bot anyway. I know it's easier and much more forgiving than Java, plus I've used it briefly at points in the past, so I think I'm gonna use that.

Since I'm not a total noob and have most programming fundamentals down, where can I practice & learn as much Python as possible within the next 2 days? Just to get the specifics of the language and practice muh data structures & what not? Codecademy a good option?

Why making program with C like structure (global variable, non namespace-ed function)
feels easier and more convenience than make it with C++ structure (OOP-style)
even when making C++ program??

Because OOP demands you know the solution before you write it down.

It's excessively structured.

I'm programming a multi-threaded program where each new thread that gets created takes in a socket object as a parameter and does some shit with it.

I want to test it, so I made a client program that makes threads that all send a connection request to the server's socket and so on.

The problem I have now is that responses from my server to the client's socket are getting mixed up, responses that should've went to one thread's socket is going to another, etc.

I think the problem is that even though I'm creating different socket objects for each connection, all those objects are operating with the same port and host parameters. Am I correct? And if I am, what can I do to simulate connection requests from different hosts?

Could you describe the difficulties you are you having with pointers?

A pointer is just a variable that holds a memory address

I should clarify this is in java