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

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

Thread replies: 255
Thread images: 31
File: ada.png (2 MB, 1000x1000) Image search: [Google]
ada.png
2 MB, 1000x1000
Previous thread: >>51287700

Fucked up last OP.

Whatcha working on, /dpt/?
>>
TRAPS
R
A
P
S
>>
>>51294973
Pretty sure Ada wasn't a trap.
>>
Was Ada secretly a trap?
>>
File: jsonobjects.png (49 KB, 352x1339) Image search: [Google]
jsonobjects.png
49 KB, 352x1339
>>51294963
Okay, let's try this again.

Working on parsing the comments from 4chan's JSON.

I've got JSON objects already, but the comments are in weird broken HTML.

>>51294889
Yeah, pic related. I've got it all going into objects correctly.

It's the content of the comments that are giving me issues.
>>
>>51294988
>implying
>>
>>51295010
And here's an example of the comment content:

        "com": "The /g/ Wiki:<br><a href=\"http://wiki.installgentoo.com/\">http://wiki.installgentoo.com/</a><br><br>/g/ is for the discussion of technology and related topics.<br>/g/ is <b><u>NOT</u></b> your personal tech support team or personal consumer review site.<br><br>For tech support/issues with computers:<br><a href=\"https://startpage.com/\">https://startpage.com/</a> or <a href=\"https://duckduckgo.com\">https://duckduckgo.com</a> (i.e., fucking google it)<br><a href=\"https://stackexchange.com/\">https://stackexchange.com/</a><br><a href=\"http://www.logicalincrements.com/\">http://www.logicalincrements.com/</a><br><br>You can also search the catalog for a specific term by using:<br><a href=\"https://boards.4chan.org/g/searchword\"><a href=\"https://boards.4chan.org/g/searchword\" target=\"_blank\">https://boards.4chan.org/g/searchword</a></a><br><br>Always check the catalog before creating a thread:<br><a href=\"https://boards.4chan.org/g/catalog\">>>>/g/catalog</a><br><br>Please check the rules before you post:<br><a href=\"https://www.4chan.org/rules\"><a href=\"https://www.4chan.org/rules\" target=\"_blank\">https://www.4chan.org/rules</a></a><br><i>Begging for cryptocurrency is against the rules!</i><br><br>To use the Code tag, book-end your body of code with:<br>&#91;code] and &#91;/code]<br>Abuse of the code tag may result in a ban.",
>>
/dpt/ - Daily Programming Thread
Copyright (C) 2015 Faggot OP

This thread is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This thread is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this thread; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>>
File: ea3an.png (71 KB, 1479x739) Image search: [Google]
ea3an.png
71 KB, 1479x739
>>51295010
and here you go
a little fixing is needed, but not much.
>>
>>51295035
I'm currently just stripping the contents of all HTML stuff with a little library I'm using.

Not sure the best way to do this in C#.

>>51295040
Thanks, anon.
>>
>>51295049
Sweet, will play with this, give me a few and I'll let you know how it goes.
>>
>>51295066
incase you cbf to type
http://pastebin.com/HMiryWyc
>>
File: 1420317518446.png (152 KB, 1948x858) Image search: [Google]
1420317518446.png
152 KB, 1948x858
In C, should I use uint8_t or unsigned char for representing a byte?
>>
>>51294973
Fuck traps
>>
>>51295095
that's the spirit! :P
>>
>>51295073
Going to type it out, because I'll likely use it a little differently in a separate method, and I'll remember it better.

Thanks, though.
>>
>>51295076
uint8_t
>>
>>51294963
Please post an anime girl next time.
>>
Is there a distance formula that treats diagonal moves the same as orthogonal?
i.e. the distance between 0,0 and 1,1 be calculated as 1.
It's 1.4 for Euclidean, 2 for Manhattan.
>>
I need data serialisation format. XML is too verbose, JSON have too many braces. I decided to go with YAML. What are downsides of YAML? Any other good serialisation formats?
>>
>>51295098
Chuckled.
>>
>>51295049
What library is HtmlDocument from?

AgilityPack?
>>
File: 1446629180636.jpg (72 KB, 526x424) Image search: [Google]
1446629180636.jpg
72 KB, 526x424
>>51295113
>too many braces
>>
>>51295104
Any reason for it over unsigned char?
>>
>>51295113
any binary format
>>
>>51295076
If by byte you mean octet, use
uint8_t
. If by byte you mean machine-dependent adequately sized byte, use char
>>
>>51295123
yeah
it's on nuget
>>
File: 16.jpg (168 KB, 751x1000) Image search: [Google]
16.jpg
168 KB, 751x1000
>>51295113
>trying to reinvent sexprs
every time
>>
>>51295130
you type less and it's uniform with other type names?
>>
>>51295130
Basically, consistency. There are some times when you need to have an integer with exactly 8/16/32/64/whatever bits so you can either mix char/short/int/long/whatever with int8_t/int16_t/whatever or you can just use int8_t/int16_t/whatever everywhere.
>>
>>51295113
What are you using it for? JSON is pretty standard and well supported.
>>
>>51295156
you really thing he'd go with sexprs given he complaines about too many braces in json?
>>
File: winchan.png (205 KB, 1039x457) Image search: [Google]
winchan.png
205 KB, 1039x457
>>51295151
Yep, I love nuget.

Got it working, thanks anon. Much better than my ghetto strip method.

Will continue to work on image optimization, as the loading of images is pretty slow at the moment.
>>
>>51295111
https://en.wikipedia.org/wiki/Chebyshev_distance
>>
>>51295172
But this applies both ways. I asked about why use uint8_t over unsigned char. Also, I don't what you mean by needing exactly 8/16/32/64 bits, got any examples?
>>
>>51295167
it's just as uniform as any other
>>
>>51295148
Can't I use char for the first case too?
>>
>>51295205
so what's this built on?
WPF? winforms?
>>
>>51295232
>(u)int(8/16/32/64)_t
>(unsigned) char/short/int/long long int
?
>>
>>51295250
WPF
>>
>>51295257
>types with _t
>types without _t
?
>>
>>51295219
For example, I had a program where I had a custom hashing function. The hash key had to be more than 32 bits to avoid frequent (destructive) collisions so I used uint64_t. If I had used unsigned long long it might be 64 bits on some platforms and something else on others (most likely 32 bits which was bad) which wouldn't be a good thing, obviously.
>>
>>51295282
There nothing uniform in the latter and they are garaunteed to be the size you need
>>
>>51295292
But unsigned long long can't be less than 64 bits!
>>
>>51295282
typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;
typedef float f32;
typedef double f64;


there you go sperg
>>
>>51295301
are you blind? the latter don't require you to reach for "_" and add a worthless "t" at the end. that's uniform about them.
>>
>>51295126
topkek
>high birds
>>
>>51295258
can you post whoel code, i find this amazing as a wpf/c# noob
>>
>>51295126
>>51295327
Shit, nigga, that image is probably over 10 years old.

Still makes me giggle like a little schoolgirl.
>>
>>51295309
that's redundant; also float is not guaranteed to be 32 bits nor double to be 64 bits
>>
>>51295307
Yeah I added one extra long there accidentally, meant unsigned long. Long long was added in C99 which isn't supported for me.
>>
>>51295282
Convention is that types ending with _t are reserved by C standard library and/or language.
>>
>>51295346
How did you use uint64_t without C99?
>>
would anyone use something like http://ideone.com/ if it was built specifically for /dpt/?
I feel like making something, and a remove compile + run service seems fun to make.
the hardest thing would likely be to stop cunts from abusing it, but as long as the entire container is destroyed after a run nothing absurdly bad could happen
>>
File: winchan1.gif (2 MB, 1213x710) Image search: [Google]
winchan1.gif
2 MB, 1213x710
>>51295332
My code is pretty spaghetti at the moment.

Which part are you interested in?
>>
>>51295381
s/remove/remote
>>
>>51295380
Embedded compiler which only had/has support for fixed width integers to avoid programmer mistakes.
>>
>>51295381
just use bsd with jails?
>>
>>51295367
That's not true, the standard doesn't say anything about identifiers ending with _t.
>>
>>51295418
I don't have infinite money, or any money at all.
All services would run on shared infrastructure, most likely heroku
>>
When I look at github, it seems that many projects are programs created for other programmers for the sake of programming.

Apart from 2D vidya, what types of individual projects are not like this that someone new could do?
>>
>>51295413
But that's not C.
>>
Currently bullshitting with edge-case constructs in C++

/dpt/
how much is
 struct Empty { }; sizeof(Empty) 
?
guess
test
discuss pros&cons
>>
>>51295426
Standard does not, but the convention does, just like i is the conventional sign for electrical current and short-lived index counters.
>>
>>51295426
If I remember it correctly POSIX reserves _t.

>>51295443
Yeah, that's true as well. Still, there are cases when you need exactly X bits, not just >= X.
>>
>>51295457
What convention? There are thousands of coding conventions for C, you can't possibly follow all of them. Also, the conventional sign for electrical current is upper case I.
>>
>>51295456
Nothing to discuss here and neither it's an edge case, it's documented.

http://www.stroustrup.com/bs_faq2.html#sizeof-empty
>>
how do i compute the lengths of innermost lists in haskell, i know that:
foo::[[a]] -> [Int]  foo = map length -- works for [[1,2],[3,4,5]] = [2,3] 
for example for this type:
 foo2::[[[a]]] -> [[Int]] 
>>
>>51295381
so I guess the answer is no
oh well, back to the drawing board

anyone have any ideas that could be useful for this board/general? plz no troll
>>
>>51295485
Correct, though I is for big currents, i is for small currents.
https://electronics.stackexchange.com/questions/177834/v-i-uppercase-lowercase-convention

I wish lowercase i was not used by current because every tensor used j instead of i for sqrt(-1) and it was a real pain.
>>
>>51295478
>POSIX reserves _t
That's true. POSIX also requires char to always be 8 bit which makes the original question (kind of) irrelevant in that case.
>there are cases when you need exactly X bits
Yes, that's what was also asked at some point: an example where you need the "exactly X" part. What was provided was an example where the custom 64-bit type was the only thing provided. That's not a compelling argument.
>>
>>51295531
How about magic move generation in chess engines, which relies on (exactly) 64 bit unsigned arithmetic?

https://chessprogramming.wikispaces.com/Magic+Bitboards
>>
>>51295511
You do it by uninstalling haskell desu
>>
>>51295558
64-bit unsigned arithmetic is the same as 70-bit unsigned arithmetic if you mask the final result or mask the input before right shifts or division. I don't see how it relies on fixed 64-bit types.
>>
File: 1444307933491.jpg (83 KB, 800x850) Image search: [Google]
1444307933491.jpg
83 KB, 800x850
Holy fucking shit.

I can't even compile a dumb libclang example.

The code is like 20 lines long but I can't do shit with it because of fucking linking order with g++. I linked the whole of LLVM, then all of the libclang binaries, that depend on zlib, dl, pthread, and fucking curses (which is documented nowhere except by looking at some random makefiles in the source code of libclang), then my file, got a fuckton of "unresolved external", then tried every possible permutation, I just can't take it anymore.

Every single tutorial I find online is outdated, I just can't take it anymore.
>>
>>51295456
An error because you didn't typedef Empty?
>>
>>51295636
In C++ the typedef is not required.
>>
>>51295511
foo = (map . map) length
>>
>>51295627
If you are relying on the existence of 70 bit integers on a real platform you should just stop arguing.
>>
>>51295687
I said no such thing. I was just making an argument that a fixed 64-bit type is not required for 64-bit arithmetic.
>>
>>51295702
How about a data structure which has to be exactly N bits in size (stuff like GDT and IDT entries etc.)?
>>
Are there any cases where personal computers don't have 8 bits to a byte? Or is it stuff like arm and non i386/amd64 type architectures. Am I just free to assume the majority of people have 8 bits to a byte?
>>
>>51295783
>Are there any cases where personal computers don't have 8 bits to a byte?
On a PC? Not as far as I knw.
>>
>>51295747
That's very platform specific and isn't constrained by the portability guarantees of the C standard anymore. In that case, using "unsigned long long" would be just as fine because it's guaranteed to be 64 bits.
>>
>>51295805
One more question. Why is it said that assembly is less portable? Doesn't it all compile to the same bytecode? Or is it "less portable" in the sense i386, amd64, and arm has different instruction sets
>>
>>51295843
I give up. Do whatever you want. It's not like it is a big problem if you mix the two ways.

>>51295868
>Or is it "less portable" in the sense i386, amd64, and arm has different instruction sets
Yes.
>>
>>51295783
At present, there are no devices that would qualify as "personal computers" that have more than 8 bits in a byte. And if you write software for win32 or posix environments, a byte will always be 8 bits.
However, if instead you write reusable code, intended to be a library (eg. something like zlib) you can't rely on 8-bit bytes because the code could very well be compiled for a DSP or whatever exotic chip that has 16-bit/24-bit/32-bit bytes.
>>
File: snapshot2.png (93 KB, 817x660) Image search: [Google]
snapshot2.png
93 KB, 817x660
whats a cool language that i can pick for this assignment? needs "support for inheritance, concurrency, and runtime type discovery (reflection/introspection)"

i dont really like functional languages but haskell looks so fucking sexy.
>>
>>51295868
"assembly" is just a general term for a variety of dialects, so that's exactly why it's less portable. And since it has no "standard library" of any sort, you'll probably be making lots of OS-specific interrupts on top of CPU-specific instructions.
>>
>>51295868
C++ babby here, is assembly even compiled?
i thought i thought shit like mov was just a text representation of an opcode
>>
>>51295916
>support for inheritance, concurrency, and runtime type discovery (reflection/introspection)
Java and only Java.
>>
>>51295904
>I give up.
So you can't present any example to justify the use of the fixed width types. It's ok, nobody ever does. Looks like it's only a matter of preference with no technical value. Thanks.
>>
>>51295916
C#
>>
>>51295916
Object Pascal
>>
>>51295942
sorry, it say's "You may not choose a language from the following list: Java, Ruby, C, Scheme."

these are the languages we covered in the class so i should have specified them not being available
>>
>>51295961
Go!
>>
>>51295916
Haskell is for literal babies.

Use erlang/elixir.
>>
>>51294988
or a programmer
>>
>>51295947
It's still easier to use 64 bit integers than to do some shifting and masking with >= 64 bit integers.
>>
>>51295916
C++
>>
So I just started to learn how to program on my spare time after wagekeking everyday.

I'm trying to write a C program to display floating point numbers from 60.2, 58.2, 56.2,.......,40.2 using while-loop.

I know that to decrement by 1 I use the i-- operator and I was wondering if you could use this to decrement by 2?

Here's what I've got at the moment
    
float i;
i = 60.2;
while (i >= 40.2)
{
printf("%f ",i);
i---2;
}

printf("\n");

return 0;
>>
>>51296005
i -= 2;
>>
>>51295904
So if I write assembly for the amd64 architecture. It would work for all cpus with amd64 architecture. Neat. This makes me want to learn assembly even more. Before I thought that only people that had my specific CPU could use it.

>>51295909
Yeah, I understand. If I did have to port my library to my smart phone or something, I'd be pissed if I wrote it all and it doesn't work.

>>51295921
The way I understand it is that both C++ and Assembly uses compilers to change statements into bytecode. The difference is that assembly has a 1 instruction to 1 byte code ratio. While C++ statements can be hundreds of byte codes.
>>
>>51296018
Thank you!
>>
>>51296005
lol

you can just do i = i -2 or whatever form you want.
>>
>>51296005
>i---2;
kek'd
>>
>>51296005
Be careful with floating point arithmetic. Try to do this and see what happens
i -= .1
>>
>>51295987
Not by much (you don't need to perform masking at every step, you can do a shitload of operations ignoring the bit-width and only mask at the very end; also, the mask is optimized out if the type is the exact width you need), and you limit portability.
>>
>>51295921
Yes, cpus don't execute text representation. And text representation -> byte code is pretty much compilation.
>>
>>51296040
Didn't know it was that simple!

>>51296050
:(
>>
>>51296028
>So if I write assembly for the amd64 architecture. It would work for all cpus with amd64 architecture
Not quite. amd64 has several sub-architectures which are supersets of previous sub-architectures. If you just use the first one then yes.
>>
File: 2015-11-11_16-30-41.png (2 KB, 163x76) Image search: [Google]
2015-11-11_16-30-41.png
2 KB, 163x76
>>51296051
jajajajajaja
>>
>>51296005
i=(((i%2)/2)+200)%2, i-2
>>
File: snapshot3.png (313 KB, 1366x768) Image search: [Google]
snapshot3.png
313 KB, 1366x768
>>51296089
>DrRacket

pls no
>>
>>51295916
G O
O
>>
>>51295984
[citation needed]
>>
>>51296089
>>51296135
is this a ruse or is there a reason that both of you have DrCancer installed on your machines? do you enjoy self inflicted pain?
>>
>>51296154
>[systems programming intensifies]
>>
>>51295916
if your teacher is hella old you would get brownie points for doing a classic language like Simula or Algo
>>
Is it okay to do this?

struct Test
{
int field;

void something()
{
Test other{};
other.field = 5;

std::swap(field, other.field);
}
};


Or is that UB when other goes out of scope?
>>
>>51296198
PASCAL
A
S
C
A
L
>>
>>51296232
It's ok.
>>
>>51296232
I don't see why it should be a problem, that code is equivalent to assigning a value to field which would store it whereever in memory the struct is being stored.

But it looks like a really convoluted way of assigning 5 to a variable.
>>
Do you see a linear boost in performance when threading or can it be better? Like with 8 threads the performance would be 1/8*old performance, right?
>>
>>51296246
Okay well with that simple example it's okay because it just swap the int values around, right? What if field is an std::vector? Will it use the specialized std::swap for vector and everything will work alright?

>>51296266
It's just an example. What I'm doing is a matrix representation class that will have a rotate method where it creates a new temporary matrix, assigns rotated fields, then swaps the current matrix fields with the rotated one (as in it doesn't return a rotated matrix, it rotates the current one).
>>
>>51296089
(+ (/ 1 10) (/ 2 10)) ; => 3/10
>>
>>51296275
I've heard of cases with superlinear performance improvement but that was in some paper I can't find now. In general with 8 threads 8x is as fast as you can go.
>>
>>51296275
it would run in 1/8th amount of time in the absolute best case scenario. you will usually not get this except on embarrassingly parallel problems.
>>
>>51296275
that would be lovely, but no, it doesn't work like that
>>
>>51296287
Yeah, it should still be fine I think.
>>
>>51296275
no and it gets even worse if you have more threads than available cpu cores because of context switching
>>
>>51296275
You'll get a linear boots only if the following conditions are met simultaneously:
1) you are CPU-bound
2) you have at least as many cores as number of threads (fake-cores don't count: hyperthreading, amd-cores)
3) the threads don't contend on resources (generally locks, mutexes, cache-lines, etc)
>>
Wagekek programmer here learning if-else statements now

How come else if(num == '0') does not work? What am I doing wrong here

#include <stdio.h>
int main(){
int num;
printf("Enter an integer you want to check: ");
scanf("%d",&num);
if((num%2)==0)
printf("%d is an even number!.",num);
else
printf("%d is an odd number!.",num);
else if(num == '0')
printf("The number you entered is zero");

return 0;
}
>>
File: Scala_logo.png (11 KB, 329x93) Image search: [Google]
Scala_logo.png
11 KB, 329x93
>>51295916

i think i've decided on Scala for now, unless something better comes up

it looks really fucking neato. i just wish the logo looked cooler
>>
>>51296184
what's wrong with DrRacket anon
>>
>>51296339
s/boots/boost/
>>
File: meme.png (3 KB, 224x89) Image search: [Google]
meme.png
3 KB, 224x89
>>51296303
:^)
>>
>>51296340
Because 'X' is a char, not a number (integer). Besides I think you need to have elseif above else.
>>
>>51296275
It's S(n) = 1/(1-p + p/n), where p is the parallel code and n is the number of threads.
And that's the ideal, perfect world best case.
>>
>>51296340
'0' is a character, not an integer. When treated like an integer, '0' will have a value of the ASCII code for the character, http://www.asciitable.com/, so '0' == 48.
>>
>>51296365
>'0' will have a value of the ASCII code
not necessarily
>>
>>51296340
1. why do you have quotes around 0?
2. why did you make &num a pointer?
3. this would be better as a conditional or case statement
>>
>>51296389
>2. why did you make &num a pointer?
He's got that one right, scanf is assigning a value to num, and since C only has pass-by-value, you need to pass a pointer.
>>
>>51296340
>>51296362
>>51296365
>>51296379

I rearranged the code and modified it a bit but when I input 0 it still does not print "The number you entered is 0" but instead prints "0 is an even number!"

How would I let the programer know I inputted 0

#include <stdio.h>
int main(){
int num;
printf("Enter an integer you want to check: ");
scanf("%d",&num);
if((num%2)==0)
printf("%d is an even number!.",num);
else if(num == 0)
printf("The number you entered is zero");
else
printf("%d is an odd number!.",num);

return 0;
}
>>
>>51295392
sorry for delay

i'd be interested how you handled that mahapps thing and how you take html from the page

hell, i'd like everything, i don't care about spaghetti as i make delicious ones myself as i still learn, code can be fucked up as hell, just as long it has comments that describe things
>>
>>51296402

That's a logic error. You first check if the number is even and since it passes through the second conditional check isn't executed.

#include <stdio.h>

int main()
{
int num = 0;
printf("Enter an integer you want to check: ");
scanf("%d", &num);

/* First check if it's zero (notice lack of ' around zero) */
if(num == 0)
printf("The number you entered is zero.");
/* Then check if it's even */
else if((num % 2) == 0)
printf("%d is an even number!", num);
/* If either failed */
else
printf("%d is an odd number!", num);

return 0;
}
>>
>>51296402
by testing for 0 first
>>
>>51296399
i was asking that for his own knowledge, since i dont think he made that decision himself. it's unlikely that he understands pointers but not basic comparisons
>>
>>51296402
only one option in an if ... else if ... else ... group is going to be executed. You want two if groups, one to check if the number is even or odd (and print the appropriate message) and another to check if it is zero (and print the appropriate message), since 0 also counts a even by your definition.
>>
>>51296413
>>51296411
I'm retarded. Thank you
>>
>>51296349
>looks really fucking neato
looks like a clusterfuck desu
>>
>>51296435
You really are.

Please stop trying to program.
>>
>>51296402
you never get past the first test

you could put another if inside the first if, or just use cases
>>
>>51296435
bool retarded = true;
if (retarded == "retarded")
>>
Why can't I find an algorithm to find the sorted list of all substrings of a string that contain the last character? Apparently it's an O(n) operation.
(apopo) becomes [apopo,o,opo,po,popo]
>>
>>51295076

That image is what happens when procedural programmers try to write OO.
>>
>>51296447
I think it's you who's the retard
>desu senpai
>>
>>51296455
Just grab the substrings then sort the list with a good algorithm.

That should easily be O(n).
>>
>>51296469
>tfw comedy is dead because everyone is literally too retarded to understand such an obvious joke
>>
File: scheme.png (27 KB, 766x226) Image search: [Google]
scheme.png
27 KB, 766x226
>>51296359
>
>>
>>51296499
if("desu") {

System.StandardOut.WriteFullLine.Generator.Slice.PutLine("desu")
}
>>
>>51296499
Wanna hug it out?
>>
im trying to use a binary search function to search an array for a user input and tell if it was found or not found and what index, but it always says it wasnt found. i keep scanning through the code to see the issue but can't find it, im sure its just a wrong variable somewhere, but i think another pair of eyes would help:

#include <iostream>
using namespace std;


const int SIZE_OF_ARRAY = 6;
int Array[SIZE_OF_ARRAY];
int UserSearch;

int BinarySearch(int UserSearch, int Array[], int SIZE_OF_ARRAY);


int main() {

for (int i = 0; i < SIZE_OF_ARRAY; i++)
Array[i] = i + 2;

for (int i = 0; i < SIZE_OF_ARRAY; i++) {
cout << Array[i] << endl;
}


cout << "Enter a number you would like to search the array for: " << endl;
cin >> UserSearch;

if (BinarySearch(UserSearch, Array, SIZE_OF_ARRAY) == true)
cout << UserSearch << " found at index " << Array[SIZE_OF_ARRAY] << endl;
else
cout << UserSearch << " not found." << endl;
}


int BinarySearch(int UserSearch, int Array[], int SIZE_OF_ARRAY) {

int SearchLowIndex, SearchMidIndex = 0;
int SearchHighIndex = SIZE_OF_ARRAY - 1;

while (SearchLowIndex <= SearchHighIndex) {

SearchMidIndex = (SearchLowIndex + SearchHighIndex)/2;

if (Array[SearchMidIndex] == UserSearch)
return SearchMidIndex;
if (Array[SearchMidIndex] < UserSearch)
SearchLowIndex = SearchMidIndex + 1;
else
SearchHighIndex= SearchMidIndex - 1;
}
return SIZE_OF_ARRAY;

}
>>
>>51296471
Sorting in general takes O(n * log(n))
What kind of thing are you thinking about that makes it O(n)?
>>
>>51296520
*Factory.System
>>
>>51296459
>procedural programmers
>>
>>51296531
>implying his arrays aren't already sorted
>>
>>51296512
>>
>>51296409
>just as long it has comments that describe things
Haha, then your in for a hell of a time.

Give me a bit, I'll throw some comments in and stick it on my GitHub.
>>
>>51296530
What does BinarySearch actually return
What will main think of that return value once it gets it?
>>
File: Screenshot_2015-11-11-14-09-41.png (65 KB, 720x1280) Image search: [Google]
Screenshot_2015-11-11-14-09-41.png
65 KB, 720x1280
>>51296359
>>51296512
>>
>>51296546
How do you already sort your arrays when they are not sorted
Is this referencing that creationist sort
>>
>>51296563
>>51296359
>>51296512
it works on DrRacket :)
>>
>>51296359
>>51296512
>>51296563
so the behavior isn't even standarized?
>>
>>51296576
It probably is. But sometimes interpreters choose to not print longer than 10 digits. If you add .1 a billion times, it won't equal 100 million.
>>
>>51296558
it returns an index value, so its a scope issue, right? because the low,mid,high index variables are declared in the binarysearch function, so main doesn't cant do shit with it... right?
>>
>>51294988
>>51294991
most traps are mentally ill
ada was definitely mentally ill
>>
>>51296601
>most traps are mentally ill
>most
and by most you mean all?
>>
>>51296610
trap != tranny newfriend
>>
>>51296564
std::vector sorted_vector = {1, 2, 3, 4};
std::sort(sorted_vector.begin(), sorted_vector.end());
>>
>>51296625
std::sort is O(n * log(n))
>>
File: scheme.png (9 KB, 338x158) Image search: [Google]
scheme.png
9 KB, 338x158
>>>>>>>>
>>
I'm trying to write a C program that calculates the volume of a sphere by using programmer-created function volume()

How do I modify this code to create the function calls it
    scanf("%f",&r);

volume = (4.0/3) * M_PI * r * r * r;


Here's what I got at the moment
#include<stdio.h>
#include<math.h>

int main(){

float r;
float volume;

printf("Enter radius of the sphere : ");
scanf("%f",&r);

volume = (4.0/3) * M_PI * r * r * r;

printf("\nVolume of sphere is : %.2f",volume);

return 0;
}
>>
>>51296666
Nice quads senpai
>>
>>51296455
do you mean O(n) with respect to the size of the original string "apopo" or the size of the combined substrings
>>
>>51296619
traps = mentally ill
tranny = having fun
>>
>>51296688
Both faggots.
>>
>>51296666
>that shitty font rendering
ugh
>>
>>51296688
did you mean to post the inverse of that?
>>
>>51296668
anyone who spoonfeeds you the answer should be shot
you need to learn how to do this yourself
things to google:
how to create a function in C
how to pass parameters to a function in C
how to return a value from a function in C
how to kill yourself
>>
>>51296601
>most traps are mentally ill
>ada was definitely mentally ill
therefore, ada was a trap
QED
>>
>>51296685
Original string
Combined substrings would be O(n^2)
And the final product is a container structure of the string that contains an array of the correct indexes so it doesn't allocate O(n^2) space
>>
>>51296726
water is blue
the sky is blue
therefore the sky is water
>>
>>51296732
>>51296455
Is this just basic English (26 chars) or does it have to include an arbitrary amount of different letters? I was thinking I had something, but it doesn't work if you allow variable amount of languages.
>>
>>51296732
I mean I can easily think of a way to do it that only requires sorting the original string (rather than fucking with comparing the substrings).

I can see how there could be an O(n) algorithm for set that has that sort of pattern:

apopo
popo
opo
po
o

But I can't think of it right now. Good luck son.
>>
>>51296749
Well, there's a lot of water in the sky coming from evaporation so I guess that statement holds true.
>>
>>51296688
>ib4 not objective
both faggots, fuck each/non but be clear about it. this thread must be fulled with red pilled programmers, if you are programmer and you are blue pilled, you are not doing it right. you wont be a good programmer, ever. because program has no feelings, it is robot. you need to know pure knowledge to fuel it.
>>
>>51296637
oh ok

bubble sort then
>>
>>51296668
#include <stdio.h>
#include <math.h>

float volume(float radius);

int main()
{

float r;

printf("Enter radius of the sphere : ");
scanf("%f",&r);

printf("\nVolume of sphere is : %.2f", volume(r));

return 0;
}

float volume(float radius)
{
return (4.0 / 3) * M_PI * pow(radius, 3);
}
>>
>>51296409
Here's repo, will add comments shortly.

I know it's really poorly written, working on refactoring the codebehind/GUI interactions.

https://github.com/Kwazzi/WindowsChan

ParseChans()
and
ParseBoardCatalog()
are the methods pulling in the JSON information.
>>
>>51296749
PARADIGM SHIFT
A S
R H
A I
D F
I T
G
M
>>
lemme see yer bogosort implementations
>>
>>51295156
I would sexprs her badly
>>
>>51296786
so now you just spoonfed him
btw, radius * radius * radius is gonna be way more performant than pow(r, 3)
>>
>>51296756
Basic English, although I guess you could extend a plan for this problem to any language that has a finite number of characters
>>51296769
Doesn't work in linear time (even after sorting) I think, for something like abababababc -> aaaaabbbbbc you're stuck looking for which baba you're looking at.
>>
>>51296786
thanks family member tbf (to be frank)

>>51296826
fuck off
>>
>>51296826
4.18879020479 * radius * radius * radius
>>
>>51296843
the compiler will do that optimisation for you, so there's no need to do that
magic numbers are bad
>>
>>51296530
Did you follow someone's advice that you should learn just by writing code instead of reading any books/intros to programming? Because you shouldn't have.
You're returning inital size of array no matter what.
Your function returns a number, supposedly (like most people would assume from the declaration) the index of the found element or a failure value (e.g. -1, since 0 is a valid index) and in main you are trying to compare it to true as if your function returns binary success state and not an index.
SIZE_OF_ARRAY in BinarySearch is its own local copy of the value you pass it (it's called passing by value, if you see an argument which isn't modified by symbols like * or &, argument is getting passed by value). But anyways, even if you assumed that it's globally the same, you're not even changing it anywhere ffs. So I don't know why you expect Array[SIZE_OF_ARRAY] to point to your found element and not to the first element outside of your array.
>>
>>51296826
You're right about that.

>>51296843
The compiler will probably optimize to that anyway.
>>
>>51296855
>>51296857

>relying on the compiler
>>
>>51296856
nice blog, spergfag
>>
>>51296886
Don't forget to hit the subscribe button!
>>
>>51296904
add a tripcode and I'll hit something, alright!
>>
>>51296788
1) even though HttpClient is IDisposable, it is recommended not to using() it. This way, requests can be 'keep-alive'd
2) 4chan api does not need application/json header, as it is simply static files served through cloudflare. This is unnesseary, and there are lots of boilerplate code
3)
>dynamic data = JsonConvert.DeserializeObject(s);
>boardcatalog = data[0].ToObject<BoardCatalog>();
use the generic overload to DeserializeObject<T>. Avoid using dynamic where possible, as it is slow.
boardcatalog = JsonConvert.DeserializeObject<List<BoardCatalog>>(s)[0]
4) your commit history is a lol
>>
there is an error guys


#include <stdio.h>
#include <string.h>
#define MAXLINES 5000 /* max #lines to be sorted */
char *lineptr[MAXLINES]; /* pointers to text lines */
int readlines(char *lineptr[], int nlines);
void writelines(char *lineptr[], int nlines);
void qsort(char *lineptr[], int left, int right);
/* sort input lines */
main()
{
int nlines; /* number of input lines read */
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
qsort(lineptr, 0, nlines-1);
writelines(lineptr, nlines);
return 0;
} else {
printf("error: input too big to sort\n");
return 1;
}
}


#define MAXLEN 1000 /* max length of any input line */
int getline(char *, int);
char *alloc(int);
/* readlines: read input lines */
int readlines(char *lineptr[], int maxlines)
{
int len, nlines;
char *p, line[MAXLEN];
nlines = 0;
while ((len = getline(line, MAXLEN)) > 0)
>>>>>>>>if (nlines >= maxlines || p = alloc(len) == NULL)
return -1;
else {
line[len-1] = '\0'; /* delete newline */
strcpy(p, line);
lineptr[nlines++] = p;
}
return nlines;
}
/* writelines: write output lines */
void writelines(char *lineptr[], int nlines)
{
int i;
for (i = 0; i < nlines; i++)
printf("%s\n", lineptr[i]);
}



>>>>>>> line there is an error
error: lvalue required as left operand of assignment
help ty
>>
>>51296788
>https://github.com/Kwazzi/WindowsChan

ok, will download to see what's it all about, thanksfor posting
>>
>>51296932
suck a dick ty
>>
>>51296749
I'm glad you catch my logic

>>51296792
PARADIGM SHIFT
AA
R R
A A
D D
I I
G G
M M

S S
H H
I I
F F
T T
>>
>>51295076
left = before outsourcing go India, right = after outsource.
>>
>>51296828
Probably you could. I think got something though:

>>51296455 I think this issue is making sure it doesn't degenerate into O(n^2). I think this works, but maybe not:
 Maintain location/address of the first instance of each element of the string in the list. This includes ones you haven't seen before (updating is constant time as there's only 26 element types), in which case the location of `that element' is one AFTER where it should go.

Result is a doubly linked list.

Start at index 0 of the string.

while you're not finished:
Add the string starting from this letter at the index to Result. Note that the size of this is less than any other size currently in the result, so this can be put in BEFORE any other string starting with this letter. Adding is constant time as you have the location and the target is doubly linked.

Update the locations of the first of each element. Again, this is constant time.
Increment index.
endwhile


This should be O(n), but it only works:
1) Just a constant amount of characters.
2) Adding a memory location (string) to another is constant time, which I believe is usually assumed.

I REALLY want to say there's a better algorithm though.
>>
>>51296948
its a simple error, dont be a dick

>>51296932
>>>> line has an error, i dont want you guys to code it for me
error is : lvalue required as left operand of assignment
i just want you guys to check a look at
>>>>>>> if, line
>>
>>51296856
no, i did not receive that advice, and that is not how im learning. like i stated, i said it was probably a small mistake, and it was, and has since been fixed. thanks for your comment though, i do appreciate the feedback
>>
File: monomasterrace.png (69 KB, 773x698) Image search: [Google]
monomasterrace.png
69 KB, 773x698
>>51296925
5) you have like no github presence; you suck
only 4 total contributions
bad
>>
>>51296961
it only works if*

Formatting didn't turn out nice, either.
>>
>>51296975
>github presence
>muh buzzwords
>muh cloud
>muh memes
PRESENCE
R
E
S
E
N
C
E
>>
>>51296932
>
p = alloc(len)

Try putting this in brackets.
>>
>>51296975
>contributing to sjwhub
>>
>>51296995
>>51297000
employers look at your github
so I'm more likely to get an interview with it
>>
>>51296975
Kill yourself
>>
>>51297008
They just skim over, not necessarily check for the quality of the contributions. That's why many Indians just fork whatever they can to fill their GH profile.
>>
>>51296997
this make error to 2
undefined reference to "alloc"
undefined reference to "getline"
>>
>>51296925
Thanks for the feedback, this is my first time using JSON.

What would I do or why would I 'keepalive' the HttpClient request?

>4chan api does not need application/json header, as it is simply static files served through cloudflare. This is unnesseary, and there are lots of boilerplate code
I'm not really sure what you mean. Can you explain where my boilerplate is in this respect?

>boardcatalog = JsonConvert.DeserializeObject<List<BoardCatalog>>(s)[0]
Sweet, replaced both dynamics with this type of call.

Didn't know I could do that, had to have that hack with dynamic just to get it to work initially.
>>
>>51297028
eh, I'm not worried about some curry taking my job
and besides, as you can see from the image, I've had a few of my changes actually merged into mono
I'm happy that 3 or so commits out of 103,000 are mine
>>
>>51297035
what OS are you using? if you are using linux or another unix/unix-like OS, read the manpage for those functions
>>
>>51297060
>and besides, as you can see from the image, I've had a few of my changes actually merged into mono
That can't be said from the picture alone though - even merely posting a bug report will count you as contributor.
>>
>>51297035
That's because they're not defined anywhere. Are you thinking of malloc? And why are you re-declaring library functions like qsort?

Also your code is shit; format it properly.
>>
>>51297057
>What would I do
stop using the using(var http = new httpclient)
just use var http = new httpclient
so...no using statement
>why would I 'keepalive' the HttpClient request?
the program will try to keep a TCP connection going in the background
.NET will manage it for you
benefits: faster responses from cloudflare after the first request
downsides: none

>Can you explain where my boilerplate is in this respect?
every time you make a request you do
var req = new request
req.header.accept.clear()
req.header.accept.add(application/json)

you do not need this
just use
var responseString = await http.GetStringAsync(url);
which handles 1) creating get request 2) sending request 3) recieve request 4) read content as string
so no need to do it yourself
you might need to go back to the other way if you implement caching, but for now this would reduce your code

at the very least, refactor your methods so code is not rewritten many times
>>
>>51297081
hm, true
well...I have got some stuff into mono
I do believe that having an online portfolio will look good, and even if what you say turns out to be true: I was actually encountering the bugs I fixed in mono, so I benefited from fixing them
>>
>>51297087
>Also your code is shit; format it properly.
you just blame to the author of "c programming language" to writing a shit code ^^
code is not mine, taken from the book.

>>51297072
windows 8.1, codeblock
>>
>>51297187
that's because C is shit and so was that fuck ritchie
>>
File: a.png (18 KB, 1192x317) Image search: [Google]
a.png
18 KB, 1192x317
>tuples in Haskell
Don't get me wrong, I like Haskell, but this is some CS grad meme tier solution
>>
File: Capture.jpg (14 KB, 329x85) Image search: [Google]
Capture.jpg
14 KB, 329x85
Does anyone here know how to use CLIPS? I have to use it for some homework, but the professor kind of just said do it. So I've been trying to learn it on my own, but it's rather complicated.

I've been having trouble with comparisons using a template. I'm trying to compare a template car's slot price with an integer, say 20000. I just can't figure out the proper way to do the comparison. Here are some of my attempts:

(deftemplate Car
(slot price))

(defrule Rule1
(> (Car (price)) 20000)
=>
(printout t "The car is greater that $20k!" crlf))

but this gives an error. "Check appropriate syntax for defrule." Uh, okay. So I tried something else:

(deftemplate Car
(slot price))

(defrule Rule1
?priceVar <- (Car (price ?price ))
(> ?priceVar 20000)
=>
(printout t "The car is greater that $20k!" crlf))

This code will compile, but when I assert that Car price is 3000000 and run it, it doesn't print anything. See pic.

My professor had lent me his book on CLIPS and suggested a certain page to use. So I followed what it said and came up with this:

(deftemplate Car
(slot price))

(defrule Rule1
?priceVar <- (Car (price ?price ))
(test (> ?priceVar 20000))
=>
(printout t "The car is greater that $20k!" crlf))

This code won't compile and it gives this error:
[RULECSTR2] Previous variable bindings of ?priceVar caused the type restrictions
for argument #1 of the expression (> ?priceVar 20000)
found in CE #2 to be violated.


I'm at a loss at what to do. Syntax I find online usually just has comparisons of integers not template slots. It's very possible I'm just doing something stupid, but neither I nor my professor can figure it out.
>>
>>51297230
KEK, it's almost as bad as the Java Spring thingie with 255 different constructors
>>
>>51297187
You're retarded. All the code for the missing functions is in the same chapter (5) of K&R. Maybe you should actually read the book instead of blindly copying out code like a retard and then wondering why it doesn't work.
>>
File: toixc.png (53 KB, 777x632) Image search: [Google]
toixc.png
53 KB, 777x632
>>51297230
>tuples in C#
>>
File: Untitled.png (23 KB, 903x379) Image search: [Google]
Untitled.png
23 KB, 903x379
Tuples in C++ :)
>>
>>51297247
im reading the book, there is no missing part on the code, it simply does not compile.
>>
>>51297310
Yes there is you utter retard. Where are your definitions for alloc and getline, exactly?
>>
going to a tony hoare lecture in an hour
how jelly r u
>>
>>51297361
in the standard library, moron
>>
>>51297402
some old white dude?
k
>>
File: BotEKEh.png (105 KB, 1096x622) Image search: [Google]
BotEKEh.png
105 KB, 1096x622
To the guy in the last thread asking what this is, it's the Swift playground.
>>
>>51297127
Gotcha, I'll fiddle with these.
>>
#include <stdio.h>
/*This program takes two values and then returns the value of a*b */
int multiply_two_values (int a, int b, int c );

int multiply_two_values (int a, int b, int c )
{
int c = a*b;
printf ("%d/n",c);

}

int main()
{
multiply_two_values(int a, int b, int c);
int a = 2;
int b = 3;
exit (0);
}


Call me retarded but I have never programmed in my life and I am only 18 pages into the GNU C Tutorial. I am supposed to write a function that takes two values (a and b) and returns the value of a * b. Why won't this compile? Am I supposed to put
return (a * b);
somewhere in there?

Which attempt is closer?

#include <stdio.h>
/*This program takes two values and then reutns the value of a*b */
int multiply_two_values (int a, int b);

int multiply_two_values (int a, int b)
{
int c = a*b;
printf ("%d/n",c);

return (0);

}

int main()
{
var1 = 3;
var2 = 4;

multiply_two_values (var 1 , var 2,);

exit (0);

}
>>
>>51297420
confirmed for jelly af
Thread replies: 255
Thread images: 31

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.