/dpt/ - Daily Programming Thread:

old thread:

Other urls found in this thread:

boost.org/doc/libs/1_66_0/libs/numeric/ublas/doc/index.html
eigen.tuxfamily.org/index.php?title=Benchmark
nim-lang.org/docs/gc.html
twitter.com/AnonBabble

by pirating the concurrency book and probably never getting past page 10.

I'm reading it now. It's good but I feel like I have to let all these new concepts sink in before I understand them.

-Rothschilds bow to PHP
-In contact with Turing
-Possess psychic-like abilities
>Control the web with an iron but fair fist
>Own castles & banks globally
>Direct descendants of the ancient royal programming line
>Will bankroll the first cities on Mars (PHPgrad will be be the first city)
>Own 99% of computer science research facilities on Earth
>First designer AIs will in all likelihood be PHP babies
>PHP brothers said to have 215+ IQ, such intelligence on Earth has only existed deep in Tibetan monasteries & Area 51
>Ancient Indian scriptures tell of programming angels who will descend upon Earth and will bring an era of enlightenment and unprecedented technological progress with them
>They own Nanobot R&D labs around the world
>You likely have PHPbots inside you right now
>PHP brothers are in regular communication with the Archangels Michael and Gabriel, forwarding the word of God to the Orthodox Church. Who do you think set up the meeting between the pope & the Orthodox high command (First meeting between the two organisations in over 1000 years) and arranged the Orthodox leader’s first trip to Antarctica in history literally a few days later to the Bogdanoff bunker in Wilkes land?
>They learned fluent assembly in under a week
>Nation states entrust their gold reserves with the twins. There’s no gold in Ft. Knox, only Ft. PHP
>The twins are about 7 decades old, from the space-time reference point of the base human currently accepted by our society
>In reality, they are timeless beings existing in all points of time and space from the big bang to the end of the universe. We don’t know their ultimate plans yet. We hope they’re benevolent beings.

I am trying to find out how I can delete all specified elements in an unsorted linked list in PaJavaEet. I have already found out a nice algorithm for deleting the first instance. But so far, the only thing I've done is having an algorithm which just iterates through the entire list with a for loop and then invokes the method that deletes the first instance for every iteration, thus yielding a complexity of O(n^2) which sucks pretty hard.
Any other suggestion? This is how my method that removes first instance looks like. NOTE: the list can't be sorted. It also cannot have a tail node

public int removeFirstInstance(int a)
{
//if emtpy
if(head==null)
{
System.out.print("List is empty!");
return -1;
}
//if only one element
else if(elementCount==1)
{
return removeFirst();
}

Node iteration=head; //starts at beginning
int index=0;
//searching for first instance
for(int i=0;i

I guess I would loop over the list one time and loop over the specified elements in each step. Should be O(mn).

Actually, can you sort the specified elements? Then it would be O(nlogm)

Fair enough. But it's a good idea to know of it.

so looping 2 times like I did in the first instance method?

no. that's the challenge given by our teacher even if it's kinda retarded and restrictive

Just remove and keep going...
O(n)

now how would you do that in a linked list where you need to remove nodes?

just remove and keep going

...

Reminder that Rust is only three steps removed from Hitler.

Why restart at front of list after a removal>
Just
keep
going

That's 2 steps.

Shitty website counts links in citation section.

There is literally nothing wrong with C#

That's exactly what I am trying to do, but how the fuck do I remove more than one node when I am not allowed to use tails?
I was thinking of iterating through it and whenever current.value=value to be deleted, it did something like this
current=previous.next;
previous.next=current.next;
elementCount--;

but that apparently doesn't work as I can't use previous to iterate through the list. I then tried

Node current=head;
Node previous=head;
int index=0;
for(int i=0;i

Do you have to implement your own linked list?

For this assignment you will write a program to subtract large unsigned
integers. Your program should prompt and read in two large unsigned integers.
The two large integers should be stored arrays, one array for each
integer. The integers should be stored with one digit per location in the two
arrays. The first integer should be no smaller than the second. Your program
should subtract the second integer from the first. The result should be stored
in an array, again one digit per location in the array. Your program should
then output the difference.
Your program should be able to handle integers with up to 80 digits each.
You should not use any concepts from object oriented programming. In
particular please do not use any classes (or struct) or any class methods. The
one exception is that you may use the iostream class method cin.get().

Yes, forgot to say that

Removing all nodes with value x from singly linked list. Assume it's n>1 case.
if(head.val == x) {
head = head.next;
return;
}
prev = head;
cur = head.next;
while(cur != null) {
if(cur.val == x){
prev.next = cur.next;
cur = prev.next;
} else {
prev = cur;
cur = cur.next
}
}

or some such, I'm tired.

I have the following loop in main() (C language with unix sockets)
while((status = recv(sd, &ch, sizeof(ch), 0))) {
putchar(ch);
if(status == -1) {
perror("ERROR");
exit(EXIT_FAILURE);
}
if(status == 0) {
puts("Connection ended.");
exit(EXIT_FAILURE);
}
}

with the following libraries included
#include
#include
#include
#include
#include
#include
#include

there is data coming, but errno doesn't appear to be set when I disable connection with external means (disabling wifi, pulling cable, etc.). What am I doing wrong?

...

what's the standard linear algebra library in C++?

I've seen Eigen recommended a bunch of times and used it myself as well. Can't say if there's anything strictly better or more popular though

blas/lapack?

boost.org/doc/libs/1_66_0/libs/numeric/ublas/doc/index.html

Not that fast or new but most likely available.

>his language does side effects instead of returning actions for runtime to perform
Sad!

>eigen.tuxfamily.org/index.php?title=Benchmark
Obviously there's a source bias here

>his language doesn't do everything at compile time so you have type-checked guarantees on side-effects not exploding things

so I guess it's eigen3

>his language doesn't fire missiles at compile time

for some reason, when I try to print out the list, I get a nullpointerexecption when using this

>unix socket
>disable connection with external means (disabling wifi, pulling cable, etc..)
unix sockets usually refers to unix domain sockets(sockaddr_un), see man unix(7).

Call them BSD sockets, POSIX sockets or just sockets but not unix sockets.

>errno doesn't appear to be set when I disable connection with external means
It might be interpreted as a regular shutdown, recv returns 0. Your if (status == 0) will never be reached in that loop.

>It might be interpreted as a regular shutdown, recv returns 0.
Not even that, the loop "continues" no matter how long it stays disconnected, but it returns 0 if I don't disconnect.

And how many bytes does recv() keep returning?

whats the "beautiful and cleanly designed" language in the op?

1 byte.
while((status = recv(sd, &ch, sizeof(ch), 0))) {
putchar(ch);
printf("%d", status);
if(status == -1) {
perror("ERROR");
exit(EXIT_FAILURE);
}
}


Data sample:
11O1T1I1C1E1 1A1U1T1H1 1:1*1*1*1 1P1r1o1c1e1s1s1i1n1g1 1c1o1n1n1e1c1t1i1o1n1 1t1o1 1i1r1c1.1i1n1e1t1.1t1e1l1e1.1d1k1
1N1O1T1I1C1E1 1A1U1T1H1 1:1*1*1*1 1L1o1o1k1i1n1g1 1u1p1 1y1o1u1r1 1h1o1s1t1n1a1m1e1.1.1.1
1N1O1T1I1C1E1 1A1U1T1H1 1:1*1*1*1 1C1h1e1c1k1i1n1g1 1I1d1e1n1t1
1N1O1T1I1C1E1 1A1U1T1H1 1:1*1*1*1 1C1o1u1l1d1n1'1t1 1l1o1o1k1 1u1p1 1y1o1u1r1 1h1o1s1t1n1a1m1e1
1N1O1T1I1C1E1 1A1U1T1H1 1:1*1*1*1 1N1o1 1I1d1e1n1t1 1r1e1s1p1o1n1s1e1

he's thinking in C++ where you can have two pointers. a temp pointing to previous node while the current does the deleting.

That was the point I disconnected, it stays there, unless I finish the process.

I guess once the connection has been established it's too late to give you errors like EHOSTUNREACH you would get from connect().

So basically recv() is blocking until it timeout. I guess you could lower the timeout with setsockopt. Is pulling the plug while transferring data something you do often on your system?

>EHOSTUNREACH you would get from connect().
That is actually checked before that loop, so yes, it is out of the equation.
>I guess you could lower the timeout with setsockopt.
I will check that out, thank you.
>Is pulling the plug while transferring data something you do often on your system?
It is an IRC client, so the risk is there.

>It is an IRC client, so the risk is there.
But I think a regular timeout is typically what a client does in that case.

If I'm connected to ssh and yank the cable out, the ssh client won't immediately terminate, it will eventually timeout though after being unresponsive for 30 seconds or so.

I think leaving the default timeout is probably what you should do.

I love the Lain reference in the OP image.

what can rust detect that clang's sanitizers can't

if you used variable/function names that the SJW's do not approve.

>I think leaving the default timeout is probably what you should do.
The average timeout from major networks appears to be 240 seconds, with few exceptions. The default appears to be way higher than that.

1. It's not F#.

2. Wrong braces style.

>F#
why?

install J

private void removeAll( int a) {
Node iteration = head;
while (iteration != null) {
if (iteration.value == a) {
head = iteration.next;
}else if (iteration.next != null && iteration.next.value == a){
iteration.next = iteration.next.next;
}
iteration = iteration.next;
}
}

sorry made a mistake there

private void removeAll( int a) {
while (head != null && head.value == a) {
head = head.next;
}
Node iteration = head;
while (iteration != null) {
if (iteration.next != null && iteration.next.value == a){
iteration.next = iteration.next.next;
}else {
iteration = iteration.next;
}
}
}

pajeet my son..

What is the better option if I want to make desktop apps on linux that can also be shared with windows and possibly mac users with minimum fuss? I'm choosing between C# mono and Kotlin right now.

Leaning towards Kotlin because the JVM is more mature than mono on linux. Using the JVM and/or the CLR to avoid cross-compiling to different executables is a plus, and i don't want to use anything more obscure than the JVM in the sense of "do users already have this installed?".

>minimum fuss
Probably Tcl/Tk.

gtk or qt or libui and some scripting language.

Both require platform specific binaries that the user won't already have installed on their system. I don't want to cross-compile, and I want to send over a jar file or something similar and have it just work with no installation steps.

And will the user have Java?

>when you implement a feature you thought was over your head
I don't care if it's buggy, i'm proud of myself.
When's the last time you surprised yourself, /dpt/?

If you use scripting language you just have to deploy platform specific libraries with your program and on linux they can just get them through package manager.
With c# or java user still have to install the vm.

Telling someone to install Java (if they don't already have it installed, most computer users have installed it at some point) is much easier than telling them to install Python, which in turn is easier than telling them to install Tcl.

>When's the last time you surprised yourself, /dpt/?
Never. I always knew I was a genius.

The GC is great for soft realtime programs, so I never had to disable it, OTOH you use pointers etc just like you would in C; only sequences(Nim's version of dynamic arrays) need the GC. For more info on the GC: nim-lang.org/docs/gc.html

Nim's selling points are: clean whitespace-sensitive syntax.
Easy to make bindings to any C library using c2nim.
GC'd but the GC doesn't suck like D.
Extremely powerful metaprogramming capabilities.
Has decent functional programming support(and nimfp adds a lot more).

Cons:
Small(but productive!) community, probably cause it does not have a major company backing it.
The whitespace-sensitive part could be a problem for you(in reality it's too readable for you to get hung up on this)
Breaking changes, 1.0 is not there yet.
Learning resources consists of basically 1 published book and 1 tutorial.

The pros outweighs the cons and the language BDFL is currently open(PR's get accepted a lot smoother than with D) for breaking changes since they want those out before 1.0.

t. 60 iq 'genius'

>whitespace-sensitive syntax
>a good thing

t. never used a good language with it like Idris

post some pajeet memes

>There's a direct link from Starwars to Hitler

well thats a rude awakening
now i'm gonna be trying to optimize this all day lol

I just started my internship yesterday. Shitty project that I have to present and make a presentation. Probably will do a responsive system instead of a IOS and Android app. I just feel so unmotivated.

C# is not poo. Its only sin is being developed by ms.

I use Nim for vidya, and my experience with the GC is that it's a non-issue. I run a full collection before the gameplay starts, and use manual memory management for in-game objects, which circumvents the issue, but I've found that I can afford to allocate quite a bit of GC-traced junk even during gameplay, and use the remaining frame time to clean it up without any issues. Nim lets you set a maximum pause time, which is quite helpful. The main con, as far as I'm concerned, is that you can still run into annoying compiler bugs, but this mostly happens when you try to be too smart for your own good, and it's usually easy to work around.

>t. 60 iq 'genius'
At least you admit it, so I guess you're a decent fucktard.

meant to quote

It's even smellier than Java.

>mono is not a sin

>Nim lets you set a maximum pause time
Can you do asserts/panics with it?
Like, given pause time exceeds an amount or something?

Any phpfags in here or is everyone fist deep in java, c(++|#)? and/or asm?

>working on my open sauce pbbg php project
>getting shit done
>making progress
>mfw

I would write a long post about it but you probaly won't be able to reply with all the butthurt exceptions you will get.
>t. I heard some people say mono is bad
not since 2015

Completely honest answer: Sanitizers work at runtime and only detect problems on code paths that actually execute during your tests. If your test coverage isn't perfect (and whose is?) it's possible to have a lot of problems the sanitizer won't catch. Baking sanitizer semantics into the language and enforcing them at compile time gives you memory safety "for free." (In quotes because there's a cost to the programmer of having to annotate structs and functions to make this work... though the annotation is much lighter-weight than in other languages where this was tried.)

>mono
why not .NET core

dumb frogposter

...

Reified generics are good, everything else is trash. It's C++ to Java's C.

JS + Electron

>Kotlin
KEK.
If you are focusing on GUI, I would recommend logic in C/C++ and front using C# with stetic. Users will suck your penor if you write a wpf version for windows because of the native look.

No, it finished what C++ left half baked. It is simple managed C.

Is it possible to write a lambda here, in replace_if?
The task is pretty simple and elaborate, find the minimum of array, find the average, and replace all elements lower than average with minimum. It could be done literally by for's, but I want to learn STL.

#include
#include
#include
#include
#include

static constexpr unsigned SIZE = 10;
static std::array arr;
static std::string input;

int main() {
std::getline(std::cin, input);
std::stringstream ss(input);

for (std::size_t ex = 0, idx = 0; ss >> ex; ++idx)
arr[idx] = ex;

auto min = std::min_element(arr.begin(), arr.end());
auto median = std::accumulate(arr.begin(), arr.end(), 0) / SIZE;
// std::replace_if(arr.begin(), arr.end(), [](const int& a, const int& b) { return a < b; }, median);
return 0;
}

That's D.

Can I run vendor EFI firmware under qemu?

>1242x1888
HUURRRRR

D is also half baked.
The shit design of sepples with GC. What the hell were they thinking?

>Can you do asserts/panics with it?
I'm not sure what you mean, but you can read this and see if it clears things up:
nim-lang.org/docs/gc.html

>Easy to make bindings to any C library using c2nim.
>GC'd but the GC doesn't suck like D.
>Extremely powerful metaprogramming capabilities.
>Has decent functional programming support(and nimfp adds a lot more).
Sounds like Swift.

dumb frogposter

I mean given max_pause = 100ms or something.
assert that clean up never takes longer or else trigger.
Would be a really handy debug feature when testing intense video game situations without having to manually profile yourself.
But it sounds like it's most likely possible.
Been wanting to give nim a shot, any decent vulkan bindings yet, without having to use c2nim or whatever?