/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

github.com/thomaskeck/FastBDT/blob/master/PyFastBDT/FastBDT.py
lobste.rs/s/f5vsl9/first_annual_haskell_users_survey#c_faec5j
twitter.com/SFWRedditVideos

THE JEWS ARE BEHIND EVERYTHING.

meme

,eme is you here

I'm writing a program dealing with tries in c. I pass a group of words, and it inserts each word into the trie. The last trienode in each word should then point to a trie full of words that occur after the original word in the group.

example "black cat eats"

black, cat, and eats are all in original trie. the node for k in black and the node in t for cat should have a pointer to a trie with the next word (cat for black and eats for cat)

I'm having trouble creating the trie at the last node in the word. any ideas how I could implement this?

my TrieNode struct has a count (occurance of the word in the text), an array of pointers to the next letter, and a pointer to new node for the trie inside of the node.

my new fizzbuzz, in C, r8!

#include
#include
#include
#include
#include

int
main(void) {
/* declare variables */
int i;

// Fizz Buzz

for(i = 0; i < 100/15; i++) {
fizzfactor = i%3;
buzzfactor = i%5;

// unrolled innor loop for efficiancy
printf("%d\n", j++);
printf("%d\n", j++);
puts("fizz");
printf("%d\n", j++);
puts("buzz");
puts("fizz");
printf("%d\n", j++);
printf("%d\n", j++);
puts("fizz");
puts("buzz");
printf("%d\n", j++);
puts("fizz");
printf("%d\n", j++);
printf("%d\n", j++);
puts("fizz buzz");

}

return 100;
}

>fizzfactor and buzzfactor are used nowhere
>output:
1
2
fizz
3
buzz
fizz
4

>returns 100
Here's your 3/5 for the try

>innor

why do we constantly have two threads up now?

It's a scheme to prevent the trapfag from making a new threads, you always have a new one ready so people jump to the already existing one.
Of course, all it takes is a more determined trapfag to do the same and then it's an arms race again like we had a couple years back during the first reign of the hime poster and the copycat shitposting that followed.

interpreted langs are better
for x in[str("Fizz"*(1-min(i%5,1)))+str("Buzz"*(1-min(i%3,1)))+str(str(i)*((min(i%5,1))*(min(i%3,1)))) for i in range(101)]:print(x)
i just keep fucking this up fampaiborghini

In C how important would you say "string.h" or string manipulation in general is?

Why is haskell so fatty fatty boombatty?

haskell-platform wants 1.3gb on my drive like a big fatty fat

elixir

Install 17 Packages

Total download size: 19 M
Installed size: 41 M

Slim and wriggly like a cheecky salamander

No serious programmer uses strings.

Actually, serious programmers use nothing but strings.

The locker room of the Rec has N lockers that are labeled 1,2,...,N . Each locker is locked, but can be opened using its unique key. Copies of the key to each locker are in its adjacent lockers; i.e. a copy of the key to locker i is placed in locker i+1 and iāˆ’1 (the key to locker 1 is only in locker 2 and the key to locker
N is only in locker N āˆ’ 1). T tennis balls are inside T distinct lockers (and you know which of the lockers they are in). You are given keys to M of the lockers and your goal is to collect all of the tennis balls by opening the least number of lockers.

You will design, analyze and implement a dynamic programming algorithm to solve instances of this problem correctly. Be sure that your algorithm correctly finds the minimum number of lockers that can be opened
to collect all of the tennis balls.

plz help

Just tell the teacher that tennis is for gays and walk away.

Seriously?

this is in germany so my teacher will probably use it as a means to introduce me to his muslim friends

>2017
>can't split a string

How do you output anything at all?

foo

So far I have

Make three lists
One list will be all the lockers you know have tennis balls in them
One list will be all the lockers you have keys for
One list will be for lockers with neither of them
For each locker you have a key for, find paths to all the lockers with tennis balls and open tennis ball lockers which correspond to minimum path lengths
Any locker within this path should be move moved into the list of lockers that you have keys for
Do this until all lockers which you know have tennis balls in them are also in the list which has your list of keys
Sum all the minimum paths to get the answer

Does that sound right?

or bar?

any idea how I could get current GPU usage and temps with python ? preferably for both AMD and Nvidia but I wanna start with AMD. Doesnt necessarily have to work on Linux but would be nice.

I honestly wouldn't care what his/her genitals look like with an ass like that.

you got to be a true faggot to say something like that.

its clearly a vagina with and not a man.

Probably some library magic is all you need.

You'd be amazed at how good 2017 trap asses are. Technology has improved a lot in the field.

I need someone who knows C# to help figure out if something is possible. It would be appreciated.

I have a base class. Let's call it Data1. I want it to have a memember variable (We shall call it Stuff.), but it's type needs to be implemented by any derived class. Is this possible?
I feel like generics is the key, but I don't know them well enough and I'd rather not have Data2 and Data3

Some C#ish sudo code bellow to demonstrate what I mean.
abstract class Data1
{
var Stuff {get; set;}
}

class Data2 : Data1
{
string Stuff {get; set;}
}

class Data3 : Data 1
{
List Stuff {get; set}
}

>tfw kinda wanna learn rust now

problem is all answers I get are old and dont really work anymore. also my catalyst control center or whatever they call it nowadays doenst really work anyway because AMD is fucking shit. I was just hoping there was some library that could do it for me or atleast some lightweight tool. seems like "aticonfig" command used to do that but that seems to only be a linux thing.

Sucks that it is so hard to get that information, might just move forward without it and try to add GPU support later on.

daily PHAGGOT thread

using System;
using System.Collections.Generic;

namespace Test {
class Program {
static void Main(string[] args) {
Data1 d1 = new Data1 {Stuff = "foo"};
Console.WriteLine($@"This is the Data1 version {d1}");
Data abs = (Data) d1;
Console.WriteLine($@"This is the abstract version of Data1 {abs}");

Data2 d2 = new Data2 {Stuff = new List {"bar", "boo"}};
Console.WriteLine($@"This is the Data2 version {d2}");
abs = (Data) d2;
Console.WriteLine($@"This is the abstract version of Data2 {abs}");
}
}

abstract class Data {
private Object Stuff { get; set; }
}


class Data1 : Data {
public string Stuff { get; set; }

public override string ToString() {
return Stuff;
}
}

class Data2 : Data {
public List Stuff;
public override string ToString() {
return string.Join(", ", Stuff);
}
}
}


output
This is the Data1 version foo
This is the abstract version of Data1 foo
This is the Data2 version bar, boo
This is the abstract version of Data2 bar, boo

I don't know C# at all, but if it's generics work similar to C++ templates, then that might be possible with something like:

abstract class Data1
{
T Stuff {get; set;}
}

class Data2 : Data1
{
string Stuff {get; set;}
}

class Data3 : Data1
{
List Stuff {get; set}
}


That's all just a guess.

In C++ this is just

class
Base_Data1{
virtual void* get_stuff()=0;
virtual void set_stuff(void* v)=0;
}

template
class Data1 : Base_Data1{
T stuff;
void* get_stuff(){
return static_cast(&stuff);
}
void set_stuff(void* v){
stuff = *static_cast(v);
}
}

class Data2 : Data1{
}

class Data2 : Data1< std::list >{

}

>sudo code
I mean I know it's pronounced weirdly but still...

>void
do PImpl polymorphism instead faggot

Note that if you do that in C++ you don't have a proper inheritance hierarchy for polymorphism. You need Data1 to inherit from a base, non-templated class.

Is there any way to call my C library from python's ctypes without having to redefine all of my struct types in python? I don't need to use the structs in python, just pass the pointer to one of them created by one of my C functions to the other C functions.

ANNA = cdll.LoadLibrary('./libANNA.so')
constructNetwork = ANNA.constructNetwork
constructNetwork.restype = POINTER(c_int)
network = constructNetwork(c_int(10), c_int(10000), c_float(0.5))
ANNA.setMaximizationPreference(c_float(1.0))
ANNA.trainToConvergence(network, c_float(0.05), c_float(0.1))
ANNA.deleteNetwork(network)


The variable "network" is supposed to be a struct representing the neural net. The best I can do is get it to segfault.

That is simpler then I expected. Thanks

No prob my dude.

Apart from clarity, not too much difference at that scale.

All you are doing is creating an extra variable on the stack but who cares, its just a few characters.

Deleted the post to fix the fuck-ups, but thanks for the answer. Won't bother reposting it

Right, in C++ it won't work. Operating under the assumption that this is possible in C#, I took a guess as to what it might look like.

(require-extension srfi-13)

(define phonetic-map
'(
(#\A "ALPHA") (#\B "BRAVO") (#\C "CHARLIE") (#\D "DELTA") (#\E "ECHO")
(#\F "FOXTROT") (#\G "GOLF") (#\H "HOTEL") (#\I "INDIA")
(#\J "JULIET") (#\K "KILO") (#\L "LIMA") (#\M "MIKE") (#\N "NOVEMBER")
(#\O "OSCAR") (#\P "PAPA") (#\Q "QUEBEC") (#\R "ROMEO") (#\S "SIERRA")
(#\T "TANGO") (#\U "UNIFORM") (#\V "VICTOR") (#\W "WHISKY")
(#\X "X-RAY") (#\Y "YANKEE") (#\Z "ZULU") (#\0 "ZERO") (#\1 "ONE")
(#\2 "TWO") (#\3 "THREE") (#\4 "FOUR") (#\5 "FIVE") (#\6 "SIX")
(#\7 "SEVEN") (#\8 "EIGHT") (#\9 "NIN-ER") (#\space "SPACE")
(#\- "DASH")))

(define (phonetic str)
(if (string? str)
(string-join (map (lambda (x) (car (cdr (assoc x phonetic-map)))) (string->list (string-upcase str))))
""))

(printf "~A\n" (phonetic (string-join (command-line-arguments))))
what would be the most common lispy way to achieve the same thing?

I'm new to rainmeter, and I'm trying to pass the value of a measure in one skin to another skin, how do I do that?

I find it very usefull
of course, you could just implement those functions yourself
but it would probably be a waste of time

my bad

>when you write a cryptographic hash function from scratch and unit test it a bunch and it works

Why make a new one?

Does anyone here have experience calling C code from python? I really really need help.

I have done such things.. Describe your problem.

What's the best way to do it? I'm I can't get ctypes to work and cffi doesn't make a whole lot of sense.

Not him, and by no means an expert on python/c interop, but take a look at github.com/thomaskeck/FastBDT/blob/master/PyFastBDT/FastBDT.py

I think the tl;dr is you use ctypes.cdll.LoadLibrary() and then define the arg/return types for each function you need to use. I think you use ctypes.c_void_p as a generic pointer-to-struct type, and it does casts under the hood or something.

To elaborate more on I think you need to set constructNetwork.restype to a c_void_p instead of a pointer to an int, and define what the argument types are before you call it. Same for setMaximizationPreference, trainToConvergence, and deleteNetwork.

I already tried that and it's still segfaulting for some reason. It works fine from the C driver.

ANNA = cdll.LoadLibrary('./libANNA.so')
ANNA.constructNetwork.argtypes = [c_int, c_int, c_float]
ANNA.constructNetwork.restype = c_void_p
network = ANNA.constructNetwork(c_int(10), c_int(1000), c_float(0.5))
ANNA.trainToConvergence.argtypes = [c_void_p, c_float, c_float]
ANNA.trainToConvergence(network, c_float(0.05), c_float(0.1))
ANNA.deleteNetwork.argtypes = [c_void_p]
ANNA.deleteNetwork(network)

It segfaults on trainToConvergence(), to be specific.

All the other functions seem to be working, but they don't do a whole lot so it's hard to tell for sure.

Daily reminder faggots should be shot.

Oh, no no no, don't mistake my words, I'm not a homophobe. Just a category theorist.

You see:
>the set of faggots is a subset of the set of men
>the set of men is a subset of the set of males
>the set of males is disjoint from the set of females
>the set of females is a superset of the set of young girls
>the set of young girls is a superset of the set of anime lolis
>the set of anime lolis is a superset of the set of programmers
>the set of programmers is the complement of the set of non programmers
>the set of non programmers is a subset of the set of brainlets
>the set of brainlets is a subset of the set of people who deserve to die
>also on an irrelevant note the intersection of the set of brainlets with the set of programmers is equal to the set of pajeets
>(who also deserve to die too as well)

fight me gays

>set of anime lolis is a superset of programmers
Sup Forums

This implies the set of pajeets is a subset of lolis.

getting started with pic related. what are some good resources? what kind of job can i get as a haskell programmer?

You're jumping onto the tail end of the latest programming fad. You can expect unemployment.

cool. maybe i'll just learn lisp instead

Being a haskell programmer doesn't get you a job. Learning haskell may make you a better programmer in general, by forcing you to write pure functional code until you figure out how to tell when this is an easier/faster/safer approach to solving a problem, which could land you a job down the line (or help you keep a job by writing code nobody else can understand).

Programming languages are tools, not ends unto themselves. I recommend picking up C, javascript, or python if you haven't already.

ya i've already mastered c

GDB is showing that it's coming from a regular expression somewhere, but my program doesn't even contain any strings.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff78da852 in regexec () from /lib/x86_64-linux-gnu/libc.so.6


What's going on here? I don't understand.

Do you have a backtrace? Could the libANNA be using regex? Or maybe even python itself...

It's a neural network library that I'm writing. It doesn't use any regexps. I turned off optimizations and now it just hangs instead of segfaulting. It still works fine when I run it from C.

The backtrace says it's coming from somewhere inside here, but I sure as hell don't see any regexps.

int step(Network* network, float rawInputs[NUMBER_OF_INPUTS]) {
network->currentIteration++;
Neuron* currentNeuron = network->currentNeuron;
if (network->mostRecentReinforcement > currentNeuron->lastUpdated && currentNeuron->timesUsedSinceReinforcement > 0) {
updateWeights(currentNeuron, getReinforcement(network, currentNeuron->lastUpdated));
}
float inputData[WEIGHT_LENGTH];
getInputs(network, rawInputs, network->currentNeuron, inputData);
int activationIndex = processNeuron(currentNeuron, inputData);
assert(activationIndex < NUMBER_OF_CONNECTIONS);
currentNeuron->timesUsedSinceReinforcement++;
currentNeuron->lastUpdated = network->currentIteration;
currentNeuron->cumulativeValue = network->neuronAccumulationRate + cool(currentNeuron, network->currentIteration);
int actionCode = currentNeuron->actionCode;
network->currentNeuron = &(network->neurons[currentNeuron->connectionIndices[activationIndex]]);
return actionCode;
}

I would normally expect a backtrace to say which line it's on when it calls the whatever that apparently leads to regex. But I also don't see anything in there that I would have expected to lead to a regex (or string operation of any kind).

I know nothing about programming but by chance I stumbled on a youtube tutorial for freebasic and it seemed pretty neat, but can you actually do anything with it?
It seems simple enough to learn but I don't want to put in time learning if it's literally useless

It doesn't give a line number on that one for some reason.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff78da852 in regexec () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007ffff78da852 in regexec () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff78efc26 in step () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007fffe059e48e in runUntilOutput (network=0x1507980, input=0x7fffffffd730) at ANNA.c:74
#3 0x00007fffe059fa0a in trainToConvergence (network=0x1507980, errorCutoff=0.0500000007,
learningRate=0.100000001) at ANNA.c:322
#4 0x00007ffff6592c7c in ffi_call_unix64 () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#5 0x00007ffff65925ac in ffi_call () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#6 0x00007ffff67cd12d in _ctypes_callproc ()
from /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so
#7 0x00007ffff67cd6a3 in ?? ()
from /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so
#8 0x000000000048a487 in PyEval_EvalFrameEx ()
#9 0x000000000048e45b in PyEval_EvalCodeEx ()
#10 0x000000000048f15b in PyEval_EvalCode ()
#11 0x0000000000559730 in ?? ()
#12 0x00000000004793c5 in PyRun_FileExFlags ()
#13 0x00000000004797a2 in PyRun_SimpleFileExFlags ()
#14 0x00000000005bfaa0 in Py_Main ()
#15 0x000000000047d9f4 in main ()

Am I the only person that very strongly dislikes Racket?

The only nice thing about the language is that it is a lisp. But regarding any of the details compared to other schemes, I feel that it constantly makes the wrong choices.

For example, building traditional classes and single-dispatch OO into the language, instead of having a CLOS-like system with multimethods.

No polymorphism in its base library. Having separate (vector-map ...) for vectors, (map ...) for lists, and (hash-map ...) for hashmaps, with the latter being especially egregious.

Empathizing immutability without providing good enough built in data structures in the core standard library, compared to say, Clojure. Now sure, third party libraries fix this, but if you are trying to make a practical functional language, training every user to use efficient data structures is the single most important factor to the average runtime performance of your languages library ecosystem.

etc etc. The more I get into it, the more I feel friction with every little detail in it.

I completely share your sentiment about the OOP of Racket. Aside from tinyCLOS, I have the feeling that Scheme in general is motivated by an impression that single inheritance leads to faster implementations. When I checked out Christian Queinnec's CLOS scheme implementation it stuck me that it was limited to single inheritance as well.
The implementation of scheme I like the most is Guile and it's for GOOPS on one hand and on the other its completeness and practicality.

; in form (char . string)
(defparameter *phonetic-map* ...)
(defun phonetic (str)
(if (stringp str)
(map 'list (lambda (x) (cdr (assoc x *phonetic-map*))
(string-upcase str))))

(loop for x on (phonetic "abcd")
do (format t "~a " x)
finally (terpri))

; in form (char . string)
(defparameter *phonetic-map* ...)
(defun phonetic (str)
(if (stringp str)
(map 'list (lambda (x) (cdr (assoc x *phonetic-map*))
(string-upcase str))))

(loop for x on (phonetic (concatenate 'string *args*))
do (format t "~a " x)
finally (terpri))


Fixed.

>CL programmers not using keywords in their loop forms
(loop :for x :on (phonetic (concatenate 'string *args*))
:do (format t "~a " x)
:finally (terpri))

>non common lisp
>having loops

>the set of males is disjoint from the set of females
Wrong.

>No polymorphism in its base library
This is from the standard desu. It's not required by RNRS for map etc. to be polymorphic, so no one makes map etc. polymorphic. Something something muh performance.

It's luckily not to bad to make the usual suspects polymorphic though. Just a few lines in your macros and randoms include.

>category theorist
>only talks about sets
Right...

>Terry beat up some CIA niggers and is now wanted
wtf

>a category theorist.
There's usually a proper name for a "category theorist" that only understands one category, user.

You can probably do lots of things with it and honestly after you get decent with any programming language, a new one will take at most just a couple of days to get pretty good in

>after you get decent with any programming language, a new one will take at most just a couple of days to get pretty good in
That's wrong, unless your standard of "good" is being able to loop and declare variables.

lobste.rs/s/f5vsl9/first_annual_haskell_users_survey#c_faec5j
> Interestingly, the work of community workers is often to talk about issues before they come a trashfire, go to reddit and subsequently to Sup Forums.
What did he mean by this?

doubt it

honestly, I'm not sure
does he mean having private conversations with problematic community members before they post inflammatory things?
or carefully curating the community to drive out users who have differing opinions?

>google "C++ operator"
>found image

Wtf is that

>haskellers create a technical survey for haskell programmers
>some whore complains that the survey didn't even ask if she happens to be a transgender lesbian otherkin
>demands that i be fixed because "it's important for some of us"
>some haskeller points out that it's a cancerous idea
>a "community team" rustlet barges in and starts lecturing about how important it is, how hard he works organizing the rust community, and how haskell guy should be ashamed for suggesting that SJW surverying is cancerous
You just can't make this shit up... I wonder how long before they get to Idris.

>C++11
don't listen to the devil

>user-defined literals
>floating point hexadecimal literals
>sepples: the absolute state

>I wonder how long before they get to Idris.
Conor McBride has his pronouns in his Twitter bio.

In fact, just give his Twitter feed a quick scroll. It's too late for Idris.

Not that it makes a fucking difference.

There's nothing wrong with hexadecimal fractions.

Trie

>1-4) user-defined integer literals, such as 12_km
>5-6) user-defined floating-point literals, such as 0.5_Pa
alright, I'm a fucking programming fizzbuzz failure, someone explain to me why this is a good feature

>rust has pointers
>rust doesn't allow pointer arithmetic
>rust doesn't allow pointers to static data unless you declare them globally and borrow the memory block again and again in every scope that uses it

i didn't think rust could get even more shit
oh wait
>rust 1.21 just deprecated several keywords from the previous release