[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/ - 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: 27
File: young yung lean.gif (2 MB, 350x197) Image search: [Google]
young yung lean.gif
2 MB, 350x197
>>
File: it's a trap.png (873 KB, 1275x677) Image search: [Google]
it's a trap.png
873 KB, 1275x677
First for traps
>9 posts early
>>
File: functional programming.jpg (64 KB, 440x389) Image search: [Google]
functional programming.jpg
64 KB, 440x389
Daily reminder that if your language isn't functional, it's dysfunctional
>>
File: CPP functional 2.png (12 KB, 454x286) Image search: [Google]
CPP functional 2.png
12 KB, 454x286
First for C++

>>55041186
Fuck off trap poster
>>
File: trop.png (1 MB, 1280x720) Image search: [Google]
trop.png
1 MB, 1280x720
What are you working on /g/?

Previous thread - >>55033213
>>
>>55041174

To anybody who knows about PNG image files:

How do I get data out of the IDAT block of a PNG image? I'm trying to get pixels with spatial data and color. I already have code to parse the IHDR and PLTE blocks.

Also, what are common blocks that appear in a PNG that aren't documented? I've noticed a couple common ones.
>>
>>55041174
R8 my Meme C++ singly-linked list!

#include <stdexcept>
#include <utility>


enum LL_OP { INSERT, REMOVE, AT };
const char *show(LL_OP op) {
switch (op) {
case INSERT: return "LL::insert";
case REMOVE: return "LL::remove";
case AT: return "LL::at";
}
}

template <typename T>
class LL {
public:
LL(): first_(nullptr), len_(0) { }
template <typename Tref>
void insert(Tref v, int n) {
do_insert(std::forward<T>(v), first_, boundcheck(n, INSERT));
++len_;
}
void remove(int n) {
do_remove(first_, boundcheck(n, REMOVE));
--len_;
}
T& at(int n) { return do_at(first_, boundcheck(n, AT)); }
const T& at(int n) const { return do_at(first_, boundcheck(n, AT)); }
int len() const { return len_; }

private:
struct node {
T v;
struct node *next;
} *first_;
int len_;

int boundcheck(int n, LL_OP op) {
if (n < 0) {
n += len_;
if (n < 0) {
throw std::out_of_range(show(op));
}
}
else if (op == INSERT ? n > len_ : n >= len_) {
throw std::out_of_range(show(op));
}
return n;
}

void do_insert(T&& v, node *& cur, int i) {
if (i == 0) {
cur = new node{std::forward<T>(v), cur};
}
else {
do_insert(std::forward<T>(v), cur->next, i-1);
}
}
void do_remove(node *& cur, int i) {
if (i == 0) {
node *temp = cur;
cur = temp->next;
delete temp;
}
else {
do_remove(cur->next, i-1);
}
}
T& do_at(node *cur, int i) {
if (i == 0) {
return cur->v;
}
else {
return do_at(cur->next, i-1);
}
}
};

Is it memey enough?
>>
http://mingw-w64.org/doku.php/download running windows 10 x64 bit which one am I supposed to install?
>>
>>55041461
>C++
>using const char*

>using enum & matching each case rather than using an enum class or an array
>>
>>55041461
  T& do_at(node *cur, int i) {
return (!i) ? (cur->v) : (do_at(cur->next, i-1));
}


void do_insert(T&& v, node *& cur, int i) {

(!i) ? cur = new node{std::forward<T>(v), cur} : \
do_insert(std::forward<T>(v), cur->next, i-1);
}
>>
>>55041482
>>using const char*
nothing wrong with it sperg

>using enum & matching each case rather than using an enum class or an array
>you should do my way!! if you don't you're wrong!!
>>
>>55041521
std::string has length as a member


const char *show[] = { "LL::insert", "LL::remove", "LL::at" };

show[INSERT]
>>
>>55041511
Yeah not bad. I knew these memes tho. Also insert's bound checking for negative values should be different, my bad.
>>
>>55041461
>throwing exceptions
>bounds checking
>random access for a linked list
>>
>>55041554
>not using
const shar* repr[] = {
[INSERT] = "LL::insert",
[REMOVE] = "LL::remove",
[AT] = "LL::at",
}
>>
>>55041575
>shar

How does [INSERT] = "" work?
>>
>>55041575 >>55041587
Oh you're using C literals. Don't think that's valid C++
>>
>>55041587
>how does it work?
intuitively. Last ones have precedence, unspecified ones are null.
>>55041596
>C++
Yeah, dunno
>>
>>55041174
Tuning Uncrustify to my perfect absolute liking. Have you all done that, /g/?
>>
open GL

which one? the x and y parameters have to be there for some reason

A
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}

B
void keyboard(unsigned char key, int x, int y)
{
if (key == 27) {
exit(0);
}
}
>>
>>55041631
>opengl
>keyboard
>>
>>55041645
are you actually retarded?

if you want to quit the application you press Esc
>>
Rate my opengl code /g/

int result = 0;
void AddTwoNumbers(int x, int y) {
result = x + y;
}

sample usage:

AddTwoNumbers(3, 4);
glVertex3f(result, result, 0.f);
>>
>>55041621
my editor already does that if i press Ctrl + Alt + F
>>
>>55041686

non-creative memeing >>>/b/
>>
>>55041174
26th for yung lean
>>
>>55041708
>non-creative memeing
Memeing by its very nature implies the creation of a meme. The essence of memes is that of ideas, the blood of creativity. To suggest memeing can be uncreative is flawed not just a posteriori but semantically.

t. Philosopher King Pepe
>>
>>55041301
decompress the idat data with the compression algorithm in the IHDR chunk
filter the data according to the filtering method in the IHDR chunk
now the layout/total size of the raw data of scanlines are determined by the IHDR
>>
>>55041631
A lookup table with key => callback contents. Also you can do just:
void keyboard(unsigned char key, int, int)


Don't need to specify names.

>>55041655
But that has nothing to do with OpenGL, OpenGL doesn't have anything to do at all with a keyboard.
>>
First time working in Java and still trying to change C++ habits

I want to do something like this:
public class Block {
private int xCoor, yCoor;

Block(int x, int y){
xCoor = x;
yCoor = y;
}
}

public class MovableBlock extends Block{

BodyPart(int x, int y){
super(x, y);
}

public void move(int x, int y){
super.xCoor = x;
super.yCoor = y;
}
}


But apparently you can't edit private variables from super class, and making them public would miss the point. Is there a way without making MovableBlock an another class with mostly the same content as Block?
>>
>>55041695
Maybe... But does it do it YOUR way?
>>
>>55041791
protected
>>
OK /g/, here's a "challenge". can anyone make a program that can solve shit like
((15-3/2)^2*4+3(3*(2/5^2)^3))/((15*3/2)^44+1.5(3*(2/5^2)^3)/1000)+(1-(((15-3/2)^2*4+3(3*(2/5^2)^3))/((15*3/2)^44+1.5(3*(2/5^2)^3)/1000)))^(2^0)
? Have fun ^_^
>>
>>55041801
Oh man, I was sure I heard Java didn't have protected. Thanks
>>
>>55041811
What language? What compiler?
>>
>>55041845
Any language or compiler
>>
>>55041796
well i can configure some parameters like ident, add brackets, add spaces between types, etc
>>
>>55041811
int main(){
int ret = system("echo '((15-3/2)^2*4+3(3*(2/5^2)^3))/((15*3/2)^44+1.5(3*(2/5^2)^3)/1000)+(1-(((15-3/2)^2*4+3(3*(2/5^2)^3))/((15*3/2)^44+1.5(3*(2/5^2)^3)/1000)))^(2^0)' | bc");
printf("%d\n", ret);
return 0;
}
>>
>>55041863
>32512
Sorry anon, that's not the answer
>>
File: 3.png (29 KB, 1005x509) Image search: [Google]
3.png
29 KB, 1005x509
>>55041811
>>
>>55041888
Nice program
>>
>>55041855
not the same in all languages
>>
>>55041856
Can you do ?
int *pointer;
int& reference;
int&& rvaluereference;
int *& ref-to-pointer;

There are actually people (me) who think this style makes the most sense.
Besides, can you configure line break insertion in a fine-grained way? (
if(x){\n}else{}
versus
if(x){\n}\nelse{}
for example? (by that I mean break-before-else))
>>
>>55041892
i don't give a fuck tho
>>
File: apache-server-logo.jpg (44 KB, 650x302) Image search: [Google]
apache-server-logo.jpg
44 KB, 650x302
>>55041174
ok so finally got arch linux running with tor/transparency and iptables. Now people telling me i can run a webserver for my own websites and a irc chat room. I do work with PHP and wordpress also a little familiar with apache.

What does g suggest and why?
apache | nginx
>>
File: elisp.png (11 KB, 650x676) Image search: [Google]
elisp.png
11 KB, 650x676
>>55041811
>>
>>55041902
well, my editor uses this plugin here:

http://astyle.sourceforge.net/astyle.html

maybe does dunno
>>
>>55041229
> i <= 100

stop doing this. putting an extra conditional check in a for loop is dumb

do

< i < 101
>>
What does /g/ think of protobuf?
>>
>>55041987
> i < 101

I mean
>>
>>55041987
>>55042002
x86: jge
>>
>>55041811
Here you go .

Python

expr1 = (((15-3/2)**2)*4+3*(3*(2/(5**2)**3)))

expr2 = (((15*3/2)**44)+1.5*(3*(2/5**2)**3)/1000)

expr3 = (1-((((15-3/2)**2)*4+3*(3*(2/5**2)**3)) / \
(((15*3/2)**44)+1.5*(3*(2/5**2)**3)/1000)))**(2**0)

print ((expr1) / expr2) +expr3


output
1.0
>>
>>55042002
void lte() {
for (int i = 0; i <= 100; i++){}
}

void lt() {
for (int i = 0; i < 101; i++){}
}

// dis
lte():
pushq %rbp
movq %rsp, %rbp
movl $0, -4(%rbp)
.L3:
cmpl $100, -4(%rbp)
jg .L4
addl $1, -4(%rbp)
jmp .L3
.L4:
nop
popq %rbp
ret
lt():
pushq %rbp
movq %rsp, %rbp
movl $0, -4(%rbp)
.L7:
cmpl $100, -4(%rbp)
jg .L8
addl $1, -4(%rbp)
jmp .L7
.L8:
nop
popq %rbp
ret

(using x86 gcc 5.3)
its 2016
>>
>>55041811
is ^ XOR?
should it be integer arithmetic?
>>
>>55042046
this is compiler specific and only happens if you compile to assembly

with other languages that isn't the case

carry on
>>
>>55041209
Multiparadigm > functional
>>
>>55042054
No it's exponentiation. Just like on TI caculators and with TeX.
>>
>>55042076
Functional is best

>emulate all non-functional paradigms in reasonable code
>pure behaviour isolated, perfect information for compile time optimisation
>>
>>55042067
yet, we're talking about C++ (I used C, but the same "optimizations" are applied in the loop variants)

(and clang, icc, msvc all do similar, gcc and clang also do similar on other platforms like avr, ppc, and arm/arm64)
>>
>>55042113
Yet still slow as fuck.
>>
>>55042130
Only because nobody chooses to write imperative code in functional languages

Haskell has inlinePerformIO, for instance
>>
>>55041209
>>55042113
Daily reminder that if your language is """"functional"""", it isn't functional

>Designed to be practical and useful, rather than attractive
>Working or operating
>>
Is there anything in C more advanced than pointers?

Like, what else is there to learn after making a linked list? What other concepts are there?
>>
>>55042151
dynamic memory allocation
>>
>>55042151
things like undefined behavior
>>
>>55042151
Averaging multiple integers
>>
>>55042151
Garbage collection.
>>
File: hangnail.png (104 KB, 464x298) Image search: [Google]
hangnail.png
104 KB, 464x298
How do you deal with hangnails, /g/?

I have one on my pinky finger and it starts throbbing when I type.
>>
>>55042192
cut it out with a nail clipper and grab a bandaid pussy
>>
>>55041751

1. The only compression format is Zlib, this isn't an issue
2. My test image isn't filtered. I can already read IHDR easily
3. it is never clear about what a scan line is. Also the layout and size are already in IHDR. IDAT is "image data". This is the block were the data (color/order) of pixels should be.

I can't get it to decompress with Zlib.

Thanks for copy and pasting the documentation, anon. Very helpful
>>
>>55042142
No excuses.
>>
>>55042307
>>nobody wants to
>excuse
Nice try moron
There are fucking inline C libraries for haskell
>>
>>55042344
If you have to resort to other languages for performance, aside from ASM, your language is no better that a scripting language.
>>
>>55042384
You don't, I already told you.
>>
>>55042400
Then why is Hasklel so slow?
>>
>>55042384
>>55042400
Also >aside from asm
Because your favourite little language has inline asm?
You could write an inline asm extension for Haskell
>>
>>55042407
>>55042142

Because nobody writes imperative & performant Haskell, that's not the main aim of the language. The main aim is to be a good programming language.
>>
How do I get the length of a file in C?
>>
>>55042426
A slow language is shit by default.
>>
>>55042447
The language isn't slow you fucking moron
I've told you this three or four times
People write slow code in Haskell
If you wrote the equivalent to C code it would be faster, and a damn sight uglier
>>
>>55042463
Faster than normal, that is. Not necessarily faster than C.
>>
>>55041174
L E A N
E
A
N
>>
>>55042151
Variadic funtions
>>
>>55042463
>If you wrote the equivalent to C code
impossible, hasklel is not as powerful
>it would be faster
than python?
>>
>>55042502
>impossible, hasklel is not as powerful
You're full of shit.
>than python
You're full of shit.

Learn to fucking program, dumbass.
>lol i write 1+1 in C and its faster than haskell!
>>
>>55042517
>1+1 is slower in hasklel
top fucking kek!
>>
>>55042426
>using the same field name for different records is an unsolved problem
>concurrency is a GHC extension
>everything people like about "Haskell" is actually a GHC extension
>you need the FFI for basic programming concepts
>"good programming language"
>>
>>55042545
GHC extensions are part of what most mean by Haskell
>>
>>55042545
>>55042565
It'd be like saying "show some concise C++ code to do x"
"oh you used std? standard library doesn't count"
>>
>>55042537
Yeah, because Haskell has a runtime.
>>
>>55042431
not possible; c doesn't concern itself with such pleb issues
>>
>>55042603
>Yeah
shit language confirmed
>>
>>55042643
>performance is the only thing that matters
Non-programmer confirmed
>>
>>55042586
Except GHC adds so much more to Haskell that it's practically a different language.

>"show some concise C code to do x"
>uses C++
>>
>>55042665
>performance is not that important
webshit confirmed
>>
>>55042676
What most people mean by Haskell is GHC + extensions, not Haskell 98
>>
>>55042681
Didn't say it's not performant, did I faggot?
Said most people write slow code.
Apparently I need to say this to you YET ANOTHER FUCKING TIME.

Maybe stop putting words in other peoples mouths and start taking the dick out of your own?
>>
how do i put a C++ text-based space tactics game i made as a personal project into my resume, or should i even? i've only been working on it a week and it's already getting pretty in-depth. but it's looking a little ugly as fuck since i listened to /dpt/s advice and made all the variables and functions public since private's a csci degree meme
>>
>>55042723
i was going to give advice, but then i saw the word "meme"

get fucked kid
>>
>>55042723
memesters leave
>>
>>55042758
kiss
>>
>>55042719
>performant
>slow on 1+1 tho
t. spergshit
>>
>>55042785
how can I average gee?
>>
>>55042517
>1+1 is slower in Hasklel
kek
>>
>>55042807 >>55042838

I'm sorry, I didn't realise you couldn't read
>>
File: 649px-Bloom_filter.svg.png (22 KB, 649x233) Image search: [Google]
649px-Bloom_filter.svg.png
22 KB, 649x233
Suppose I have a dictionary of words and I want to check if a certain string forms the start to at least one word in the dictionary. For example, "utt" is the start of the word "utter" but "qzs" does not form the start of any word.

Obviously I can simply iterate over the dictionary, but I doubt this is the most performant solution possible. I can probably use some sort of binary search (the dictionary is in alphabetical order). Is there a better way /dpt/?
>>
>>55042880
https://en.wikipedia.org/wiki/Trie
>>
>>55042887
Neato, thanks.
>>
>>55042849
>damage control
>>
anyone know whot to use mingw32-make in a linux environment? this is driving me nuts. I can't figure no matter what and there's nothing on it on the internet
>>
>>55043005
https://www.tinc-vpn.org/examples/cross-compiling-windows-binary/
>>
So how do I clear all whitespace from a std::str in c++

So let's say I have string s = " The little black moose ate pizza"

How do I clear all white space to make string s then "Thelittleblackmooseatepizza"

Or even, replace those whitespaces with all but one white so "The little black moose ate pizza"
>>
>>55043110
s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
>>
>>55043110
for (unsigned int i = 0; i < my_string.size(); ++i) {
if (my_string[i] == ' ') {
my_string.erase(i, 1);
}
}
>>
http://blog.adamperry.me/rust/2016/06/11/baby-steps-porting-musl-to-rust/

It's over, C is finished.
>>
>>55042192
Drink water.
Trust me.
>>
>>55043491
Really makes you think
I'm a rust rodeo now
How will C ever recover
>>
>>55043491
and bankrupt, don't forget bankrupt!
>>
>>55043030
looks shady but I guess I'll try that, thanks.
>>
>>55043178

This works. But in the case that I have spaces before the string it doesn't exactly erase those. So I'm just looping it into my cpp file. So

Code to erase space from

#include <string>;

It's clearing as:

#include<string>;

It needs to clear as

#include<string>;


I don't really understand why it's not clearing the first space characters/how to clear them?
>>
>>55043735
You need to read the cpp file line by line. See http://stackoverflow.com/questions/7868936/read-file-line-by-line
>>
every language is good except for Java and Javascript
>>
>>55043778

That's essentially what I'm doing. I'm using Getline for the file, It gets the line, clears it using that code, then puts each line as a string element in a vector. It's working for what I need it to work for though (the real document) It's just on the fille cleared from my .cpp it seems to leave indents/tabs(although they aren't tabs but spaces).

But like I said, It's working for what It needs to. So all I need to do now is clear all elements in a string past '#' (so if someone puts a comment in a piece of the string, then it can be tossed out and ignored).
>>
>>55042431
For number of lines just count every \n character. For number of characters just count every character.
>>
>>55043810
>he hasn't discovered COBOL yet
>>
>>55042723
Make a GitHub account (inb4 le github is for plebs and liberal jews), upload it and put a link to it on your resume.
>>
>>55043810
EcmaScript 7 isn't so bad.
>>
File: GLDemoApp.png (81 KB, 516x388) Image search: [Google]
GLDemoApp.png
81 KB, 516x388
what sports game can i implement in openGL?

i can program, but need ideas guys! help!
>>
void RemoveListNode(ListNode* root_node, int position)
{
// set the before and after nodes since they will be needed for relinking the list
ListNode* before_node = NULL;
ListNode* after_node = NULL;
ListNode* current_node = root_node;

// get the node at the position
for (int i = 0; i < position; i++) {
before_node = current_node;
current_node = current_node->next;
after_node = current_node->next;
}

// free the node's memory
free(current_node);

// relink the list
if (before_node == NULL) {
root_node = after_node;
} else {
before_node->next = after_node;
}
}


If root_node is the only node in my singly linked list, how can I set it back to NULL after freeing the node? This code doesn't seem to be working.
>>
>>55043865
Sounds slow if it is a big file.
>>
>>55043995
public void remove(int index) {
if (index == 0) {
// removing the first element must be handled specially
front = front.next;
} else {
// removing some element further down in the list;
// traverse to the node before the one we want to remove
ListNode current = front;
for (int i = 0; i < index - 1; i++) {
current = current.next;
}

// change its next pointer to skip past the offending node
current.next = current.next.next;
}
}
>>
>>55043992
Kerling with cute girls and ass shots at compromising angles.
>>
>>55043992
skateboarding game desu
>>
>>55043830

Okay, so I have it clearing all past '#' with

 for (unsigned int i = 0; i < line.size(); ++i) {
if (line[i] == '#') {
for (string::iterator it = line.begin(); it!=line.end(); ++it)
line.erase(i,1);
}
}

Example input:
addu $s0,$zero,$zero # I'm a comment

output:
addu$s0,$zero,$zero


Is there a nicer way to put this though? One that doesn't crash if say I have a comment "# I'm a com#ment" with another # in it.
>>
>>55044009
It's C, it shouldn't be too slow. There isn't really any other way AFAIK.
>>
>>55042447
Even if it saves you time which is finite? Why not just use the right tools for some problems and other tools for other problems.
You can't possibly think that writing everything in C or even ASM would be rational.
>>
>>55044097
size_t comment = line.find('#');
if (comment != string::npos) {
line.erase(comment);
}
>>
>>55043992
Sex villa 3D.
>>
>>55044206
>It's C, it shouldn't be too slow
it's IO, it will be slow
>>
>>55044224

Hey that works pretty good. Thanks.

So basically comment = to the find character function, once '#' is found, it then removed all comments(or elements in the line past #) until it reaches the size of the string?

Just making sure I understand the logic.
>>
>>55044254
>>55044034
>>55044043

it gotta be a sports game, like ping pong, or tennis, etc...
>>
>>55044316
Kerling is a sport.
>>
>>55044287
Who gives a shit, there's no other way of doing it.
>>
>>55044342
>damage control
>>
>>55044316
Tennis
>>
>>55044336
>Kerling is a sport.
well didn't know about it, thanks
>>
>>55042192
Let it RRRIIIIPPP
>>
>>55044356
Ok, just get the number of lines in the file without parsing it, easy
>>
>>55044394
Ah, it's spelled curling in English. My mistake.
>>
>>55044420
>length of file
>number of lines
>web cuck
>>
>>55044020
This kind of helps, but it doesn't really work for me.

I wish I could give more information but I write spaghetti and I'm not sure I understand it
>>
File: output.webm (1 MB, 1920x1080) Image search: [Google]
output.webm
1 MB, 1920x1080
does not behave like I wanted it to, but it looks cool xD
>>
>>55044565
nice
>>
how does like grep know where to read the file from?

im guessing its like, if there is no file path passed as an argv, it will see if it can read from stdin?
>>
>tfw finally getting Java Hibernate to work
>tfw can't even count the hours i tried configuring this bullshit until it finally worked
>>
>>55044791
>singleton
>recreating singletons
>wat do
dependency injection
>>
>>55044791
world.shrink_to_fit() after world.clear()
>>
>>55044830
*monads
>>
I think I'm at the ballmer peak, lads. What program?
>>
>>55045461
Multithreaded functional fizzbuzz.
>>
>>55045461
If you need to ask then by definition you are not in the Ballmer's peak because you are not being productive.
>>
>>55045461
http://better-dpt-roll.github.io/
>>
Practicing assembly.

>>55045533
Rolling for what will be my first project.
>>
>>55045554
Hope you're ready to bash your head in
>>
>>55045554
>54
Cool, I'll be making a RPN calculator.
>>
>>55045524

You may be right. I think I may have exceed the peak because I'm unable to type without a majority of it being errors.

I have once again failed Steve Ballmer. My shame will live forever.
>>
>multiple parentheses around a name indicates a Jew on Twitter
>Lisp uses a shitton of parentheses
Was McCarthy trying to warn us of something?
>>
>>55045705
>stealing anon's joke
>being shitty alt righter
>>
>>55043995
If you want to modify a value (in this case a pointer) inside a function, you need to pass it by a pointer. So instead of passing ListNode* root_node, you would pass in ListNode** root_node_ptr (or whatever you want to call it). This is because all parameters are passed by value (remember that a pointer is just a value like any with some special syntax).
>>
>>55041631
>he uses glut
>and calls it opengl on top of it
>>
>>55045725
Who's joke did I steal, I'll apologize right away
>>
>>55045725
>Using the jewish language of lisp
It should surprise nobody that richard kikeman who wants all software to be free and never make profit off of it loves lisp..
>>
>>55045768
>>55004547
>>55040549
>>
>>55045814
>ded thread
Too much work, I'm just going to claim the joke as my own
>>
C++ Question. Let's say I have a 32 bit binary string called bitstring and

string bistring = "0110000010100010010111100001011"

What is the best way to convert each 4 bits(base 2) from the string into hex? So convert that string to 30512F0B?
>>
>>55045838
stoi & to_string
>>
>>55045837
You can't faggot
>>
>>55045893
Stop me
>>
>>55046006
I already did
>>
>>55045838
A manual implementation could look something like:
1) For-loop over the string
2) Calculate the value of a 4 bit sequence by:
value += pow(2 * ctoi(string[i]), 3 - (i % 4))
(i % 4 should go 0,1,2,3,0,1,2,...,3 as i goes 0,1,2,3,4,5,...,31)
3) Check for the last bit with (i % 4 == 3), if so:
fprintf(hexstr, "%X", value); value = 0;

Probably not the best way, but it's the first one I thought of.
>>
>>55046136

That's sounds incredibly awful. It just seems kind of weird that there's not an easier way to do these conversions. I was thinking just putting all possible 4 bit strings into a map, then find and replace each 4 bit string from the map into a new string and call it a day. I just didn't want ANOTHER map in my thing. The hex and binary serve no actual purpose, they're more just displaying the address.
>>
>>55046136
>>55046172
why the fuck you guys overcomplicate such a simple task
>>
>Rust disallows polymorphic recursion even under boxing
REEE
>>
>>55046172
It's true, it's overly complicated for the sake of being "correct". Since the range is so small (15 pairs) using a map seems fine to me, it's fast and easy to use. I suppose no standard functions for conversions exist because binary strings are fairly rarely used as far as I know.
>>
What is the best resource to learn java from?
>>
>>55046303
http://tour.dlang.org/
>>
>>55041174
What's the non CS grad way to write this?

  if(high_tuple && low_tuple && feels_like_tuple &&
icon_tuple && sunrise_tuple && alert_tuple &&
pop_tuple && uv_tuple && night_tuple
) {}
>>
>>55046276
>>55045870
>>
>>55046344
Consider this: http://xyproblem.info/
>>
>>55046172
>>55046366
My lack of knowledge of C++'s standard library shows, apologies. Like he said, using std::stoi and std::sprintf is much more logical here than anything else (I didn't know stoi accepted bases other than 10).
>>
>>55046276
>>55046424

Eh, then I guess I'll just deal. I'm pretty awful at C++ altogether so don't feel too bad.

Extra question.

So I have a string

"addu$s1,$zero,$zero"

   string binaryadd = "00000000000000000000000000000000";
/*.
.Some code
.*/
if (binary.find("addu"))
{
string s;
s = rOpfunc.find("addu")->second;
binaryadd.replace(26, 6, s);
binary.find("");
/* cout << binaryadd ;
break; */
}


happens since the found instruction is addu. It then replaces the last 6 of the string with 100001 upon finding it on the map r0pfunc. I then need to go to my registers map (contains the binary for each of those) and replace. so map $s1 finds 10001 key and inserts into the binaryadd, then it finds $zero (00000), and puts it into binaryadd.

How do I exactly iterate through this string like a container? If I find it in there and then add it into binaryadd I want to make sure it doesn't just find the same thing again. Should I remove that part of the string "$s1" so it doesn't find it again upon finding it?
>>
>muh 900MB compiler and 1.8GB toolkit
Haskell fags confirmed for retarded cucks
>>
is there some way to find out the biggest integer on a system?
>>
>>55046344
Where do you get those bools?
>>
>>55046604
Languages usually have some constant like MAX_INT somewhere in the stdlib.
>>
>>55046369
>>55046654

I just want to make sure those bools are all true
>>
>>55046339
what the fuck is that, it's like java but nigger like
>>
>>55046660
alright i was just wondering how to do the print factorial of 100 thing
I cant get it over 31! before it turns weird and prints int32 max or 0
someone told me to use a ""big int"" but i am lost regarding that
>>
>>55046670
No, I mean: where do you get them from? The problem is not how you check them, but that you need to check them in the first place.
>>
>>55046593
Let the cucks think their outdated meme languages mean anything. It's the year 2016, use Java or C++ already for christ sake.
>>
>>55046746
pls
>>55046671
>>
>>55046696
max value of 32/64 bit integers are not even close to 31!.

use ``big int''
>>
>>55046696
>alright i was just wondering how to do the print factorial of 100 thing

1000 ! in C
#include <stdio.h>

int buff[1024];

int main()
{
int i, j, r, t;
buff[0] = 1;
t = 1;
for (i = 1; i < 1000; i++) {
r = 0;
for (j = 0; j <= t; j++) {
buff[j] = buff[j] * i + r;
r = buff[j] / 100000;
if (r > 0) {
buff[j] -= r * 100000;
}
}
if (r > 0) {
t++;
buff[t] = r;
}
}
for (i = t; i >= 0; i--) {
printf("%05d",buff[i]);
}
return 0;
}
>>
>>55046776

pi@raspberrypi ~ $ ./fact 31
31! = 738197504
pi@raspberrypi ~ $ ./fact 32
32! = 2147483648
pi@raspberrypi ~ $ ./fact 33
33! = 2147483648
pi@raspberrypi ~ $ ./fact 34
34! = 0
>>
>>55046785
someone finally copy/pasted my code in /dpt/. I can die happy now
>>
>>55046806
do you have any idea how big 31! is? you hit the integer limits long before 31!
>>
>>55046813
it was you? i wrote a 1000! version too, but i didn't posted the code in that thread a while ago
>>
>>55046820
fuck you're right
it only goes up to 18!
>>
>>55046847
It probably does not. 18! is larger than 32 bits
>>
File: generations_40.webm (475 KB, 336x512) Image search: [Google]
generations_40.webm
475 KB, 336x512
>2016
>Still programming computer by hand
>Instead of evolving solutions to your problems
>>
how can i write this structure without the typedef

typedef struct node node;
struct node {
char *s;
node *next;
};


what i tried
struct node {
char *s;
struct node *next;
};


but it doesnt work
>>
>>55046866
oh, I did a similar thing before. trying to build an image using triangles and GA.
>>
Actually I worded this weird.

If I have the string a = "addu$s1,$zero,$zero", how do I go through it using a find for every register "$zero", "s1" etc, without it running into the issue of finding a later one before the previous? So $s1 comes before $zero in the string but how in a loop do I make sure it recognizes $s1 comes first in the string and to work with $s1 as it's range instead of any further? I have the , between each register so maybe that could be used but I'm absolutely lost.
>>
>>55046889

struct node;
struct node {
char *s;
struct node *next;
};

>>
>>55046889
can't you forward declare on C?
>>
>>55046905
Yup, that's an almost classical benchmark task. I want to try more sophisticated optimization algos and image description bases though.
>>
>>55046922
thanks bby

>>55046929
>>
File: fark.jpg (24 KB, 571x287) Image search: [Google]
fark.jpg
24 KB, 571x287
>>55046938
heh, found this image of mine.

this was a homework. it didn't work mostly because my instructor was an idiot and force me not to optimize GA according to problem. at some point he was asking me to

>"just cut the binary data at any point and merge them, GA will handle it!"

like GA is some kind of miracle, I hated that class
>>
what does it mean to be a "pedantic faggot" ?

english not my first language
>>
>>55047022
use google translate, faggot
>>
>>55047022
It means to write good code.
>>
>>55047022

You care too much about pointless shit and have a very limited/naive understanding of the current topic, yet tote yourself like you know everything and anything about it.
>>
>>55047038
>>55047042
>>55047085
thanks friends
>>
>>55047085
>>55047042
>>55047038

so, i shouldn't compile with the
 -pedantic 
flag ?
>>
>>55047012
Representation is important, as are tricks to avoid premature convergence (that's my main problem).

GAs and other metaheuristics are really cool in a sense that given enough time they will solve any problem, and they will probably do it faster than random search.

This work inspires me, I want to implement something similar: http://people.idsia.ch/~juergen/compressednetworksearch.html
>>
>>55044316

Badminton
>>
I need to work on control flow.
any suggestions?

The stuff I work on requires enormous loops and it is difficult to keep things organized, so something that provides organization
>>
>>55045738
...I actually didn't know that.

Fucking hell, pointers to pointers? This could get confusing real quick.
>>
File: copy of good_code.png (35 KB, 455x695) Image search: [Google]
copy of good_code.png
35 KB, 455x695
>>55047156
look no more
>>
>>55047156
It is a skill you cannot learn from others, sorry
>>
I just finished the codecademy course on Python.

Where can I learn more?

Where can I find ideas of exercises to practice?
>>
https://www.infoq.com/presentations/Simple-Made-Easy-QCon-London-2012

If anyone wants their brain organized.
>>
>>55047156
http://libgen.io/book/index.php?md5=F35DF0EB8BAEB3DBD64F5216F48E9505
>>
>>55047220
well the next will be writing a compiler in python of your favorite language.

you can start by writing a simple compiler for C in python.

you can use LLVM if you fell it's too complicated.
>>
>>55046697
I get them from this callback that triggers whenever a list of tuples is received
>>
>>55047220
scrapers

they're very easy to write and get you important information
at least that's what I'm interested in, do what you are interested in
>>
>>55047220

Read books.

Seriously, just buy a book and start doing the exercises. You'll learn more from there than any online course from codeacademy.
>>
>>55047242
>>55047272
>>55047301
Thanks!
>>
>>55047187
You can try making graphical representations, draw some rectangles and arrows in paint. It's just one of those things that will 'click' in your mind at one point and then it's smooth sailing from there.
>>
>>55047259
It's best to refactor that callback to not be shit, but otherwise you are stuck with CS101 code either way.
>>
Trying to install pygame but i'm being fed back
pygame-1.9.2a0-cp35-none-win_amd64.whl is not a supported wheel on this platform.


Any advice?
>>
>look at the programming challenges
>look over them, the first bunch sound boring or too easy
>get interested in "4chan thread/image" downloader because i've never written a downloader before


import requests

jpg = requests.get("http://i.imgur.com/fB7LRmT.jpg").content
with open("test.jpg", "wb+") as f:
f.write(jpg)


>proof of concept done
>already bored now
>>
File: 1439903195165.png (536 KB, 776x840) Image search: [Google]
1439903195165.png
536 KB, 776x840
Imagine you receive an android body by mail.

It has a 48 degrees of freedom (DOF) with 12 hrs of battery life (avg physical activity) with all necessary sensors (eye CMOS cameras, microphones, gyro/accel, tactile sensors, speech dynamic) and 10-core ARM CPU inside (there is a wifi as well, so offloading computation to the cloud is possible), and a microcontroller for precise motion control linked to main CPU.

You have a full access to software and firmware, you can use standard dev tools (compilers, runtimes) and OSes for main CPU and the microcontroller.

How would you program it?
What are the main technical problems in this project?
Which approaches/methods/algorithms would you use?
Which software would you use?
>>
>>55047554
It looks like pygame-1.9.2a0-cp35-none-win_amd64.whl is not a supported wheel on that platform.
>>
>>55047554
http://stackoverflow.com/questions/28150738/how-to-install-this-wheel

http://stackoverflow.com/questions/27737264/installing-pygame-on-64-bit-windows-7-and-64-bit-python-2-7

http://stackoverflow.com/questions/28568070/filename-whl-is-not-supported-wheel-on-this-platform
>>
>>55047554
cp35 => Python 3.5
>>
>>55047559
THIS SHIT AGAIN?
>>
>>55047557
Write a program that inputs a number which is (n * m) where n and m are primes and finds n and m. input can be as large as 256 bits
>>
>>55047559
>It has a 48 degrees of freedom (DOF)
>What are the main technical problems in this project?

It can't stand up or walk with only 48DOF, unless you're not counting the fingers and spine.
>>
>>55047559
How many times have you posted this
>>
>>55047187
Pointers aren't special.
>>
>>55047559
I'd probably just lay it in my bed and stick my dick in it.
Programming is too much work
>>
File: 1439903334301.jpg (226 KB, 850x1201) Image search: [Google]
1439903334301.jpg
226 KB, 850x1201
>>55047603
Yup

>>55047608
dunno, maybe 3 times

/dpt/ is such a boring stream-of-college-homeworks place that I have to post something like this.

I thought there may be some programmers here that are already skilled and seek for cool problems to solve, but looks like this place is a containment general for noobs. I understand that this problem may sound like a mockery to noobs that cannot even write a web scraper (lol) or struggle with keeping their code clean.. I guess I overestimate you, guys.

TL;DR; you college-tier questions are tier, not my posts
>>
File: Capture.png (352 KB, 734x751) Image search: [Google]
Capture.png
352 KB, 734x751
>>55047557
Higher level languages do a good job of separating the real challenges from the boring stuff.
>>
>>55047559
I'd probably start with this shit http://rll.berkeley.edu/gps/
>>
File: HRP4C.jpg (230 KB, 1411x769) Image search: [Google]
HRP4C.jpg
230 KB, 1411x769
>>55047607
Humans really have well over hundred muscle groups and thus DOFs, but it is also known that much less is enough for humanlike walking.

My DOF count is reasonable given cost-benefit curve and the fact that we are talking about mass-produced hardware. I modeled it after HRP4-C model android.

A more detailed breakdown of DOF is like this:

6 x 2 - legs
6 x 2 - arms
12 x 2 - hands
4 - torso (upper + lower)
3 - neck
2 - tongue
1 - mouth

Total DOFs = 58

Some of them can be excluded in cheaper models, to lower the count to 48.
Thread replies: 255
Thread images: 27

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.