[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: 19
File: K&R himegoto.jpg (159 KB, 500x700) Image search: [Google]
K&R himegoto.jpg
159 KB, 500x700
old thread: >>51870998

What are you working on, /g/?
>>
first for my wife's son
>>
>unable to manipulate text document to get rid of certain values and insert new ones
>instead manually change it from the text document
>do the rest through loops
>project worth 500 points

Surely I'll get at least half of those points.
>>
himemegoto is an animeme
>>
>>51874489
The other one was posted before the bump limit (310) too
>>
>>51874414
I ordered a copy of K&R from an amazon marketplace seller 2 weeks ago and it still hasn't arrived.
If it doesn't arrive by today, I'm requesting a refund.
>>
>>51874496
still better than this fag thread

this one was posted before 300 which is even worse

and the other one was only posted early in response to this thread
>>
>>51874489
Fuck you, this thread was first.
>>
>>51874463
Why don't you load the text document in chunks, change out the values you want, and then overwrite the original file?
Just use a string tokenizer.
>>
>>51874573
Stop being a faggot, holy shit you retards fighting over the OP image is literally worse than tripfags.
>>
>>51874573
Yours was too cis scum.
>>
>>51874581
if YOU stopped being a faggot and stopped forcing your fucking hime pics every single thread there would be NO fight at all over the OP image

>>51874583
mine wasn't posted before 300
>>
>>51874583
i saw a boipucci in /pol/ it looked like fucking shit like a tiny ballsack and a retracted micropenis fucking kill yourself fucking pathetic freak
>>
>>51874598
If YOU stopped being a faggot and stopped forcing your whatever the fuck pics every single thread there would be NO fight at all over the OP image.

You fucking dumbass.
It takes two to have a fight.

Frankly, I think you're seriously reaching and you need to fuck off to whatever cesspool of the internet you came from that isn't here.
>>/trash/
>>
File: 1450143580507.png (2 KB, 170x331) Image search: [Google]
1450143580507.png
2 KB, 170x331
Create a program that generates this output using any programming language you like. Measure how long it took you and then post it ITT

$ ./star "meme master"
m m m
e e e
m m m
e e e

m m m
a a a
s s s
t t t
eee
meme masteretsam emem
eee
t t t
s s s
a a a
m m m

e e e
m m m
e e e
m m m


Here's mine, written in C.
https://paste.installgentoo.com/view/raw/3a653784
>>
>>51874621
it's completely fucking unreasonable to repost a thread before the bump limit to force your images and if we had more janitors like we used to they would get deleted so fuck off fucking FAGGOT
>>
>>51874598
Anon should've waited before the bump limit.
You shouldn't be fighting over the OP pic.
>>
>>51874649
>Anon should've waited before the bump limit.
and because he autistically ignores that rule he gets to walk all over you? TOP KUCK
>>
>>51874648
it's literally 1 guy shitting up the board because he didn't get to post his OP pic

global rules 6, 7 and 10, you piece of shit
kill yourself
>>
>>51874664
tbqh senpai /dpt/ has to be a sticky with a limit of 1k replies. I know 8ch has it. This way aspies like you don't go apeshit over some magic number.
>>
MODS = GODS
MODS = GODS
MODS = GODS
>>
Trap threads have completely taken over, I love it.

On topic: C is shit XD
>>
>>51874707
That just ruins the fun though.
>>
Python type annotations were a mistake. Should have waited for Python 4 and use proper syntax instead of this madness.
>>
>>51874770
No fun here m8.
>>
>>51874783
what motivation do python users have to stick with python if they're gonna keep releasing fundamentally incompatible revisions to the language?
>>
>>51874718
>>51874768
K I L L Y O U R S E L F
I ᠎ I
L ᠎ ᠎ ᠎ L
L ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ L
Y ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ Y
O ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ O
U ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ U
R ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ R
S ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ S
E ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ E
L ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ L
F ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ F

>>51874796
their "apps" are so simple that compatibility doesn't matter.
>>
>>51874796
Lots of Python users still stick with Python 2.

I know I do.
>>
>>51874770
It shouldn't be fun, you autist. NOBODY should be fighting over the OP image. It knocks more threads off the board than absolutely necessary.
>>
File: 1430853197680.png (331 KB, 474x432) Image search: [Google]
1430853197680.png
331 KB, 474x432
fib(8) using iteration: 1 1 2 3 5 8 13 21

fib(8) using recursion:
fib(8) = fib(7) + fib(6)
fib(7) = fib(6) + fib(5)
fib(6) = fib(5) + fib(4)
fib(5) = fib(4) + fib(3)
fib(4) = fib(3) + fib(2)
fib(3) = fib(2) + fib(1)
fib(2) = 1
fib(1) = 1
fib(3) = 2
fib(4) = 3
fib(5) = 5
fib(6) = 8
fib(7) = 13
fib(8) = 21

which is more elegant and useful?
>>
File: lolifighting.webm (3 MB, 1066x600) Image search: [Google]
lolifighting.webm
3 MB, 1066x600
Ask your beloved programming literate anything.
>>
>>51874846
fib(x) using iteration: product [1..x]
fib(x) using recursion: x == 1 then 1 else fib(x - 1)
>>
>>51874858
do you do anything for a living?
>>
>that guy in class that codes on notepad
not notepad++, actual notepad
>>
>write small python/flask application
>now just create an lxc to put that in, how hard can it be, this $3 rented server is going to be so clean and organized
>it's not easy at all
I do respect you, sysadmins.
>>
>>51874858
What kind of shitty gtk C# program should I write?
>>
>>51874858
Are you a bot?
Only a bot would have the patience to post this shit every fucking day in every thread.
>>
>>51874883
graphic frontend for gcc written in vala
>>
>>51874858
Sure. Algorithmically, how does the ``procedural" terrain editor tool that was used in the Unreal Engine 4 Kite demo work?

I'm assuming for example that the terrain data was mapped to a 2-dimensional array containing keys which corresponded to value pairs in a hashmap. The value data in particular referring to the diffuse texture map which would be used at the location that the element in the 2D array corresponded to.

So, what I don't understand at the moment is how they stitch the terrain data together.
It sounds awfully expensive to compile a UV map for 4096x4096 tiles.
>>
>>51874414
Should I read K&R?
>>
File: 1428149537051.png (96 KB, 612x727) Image search: [Google]
1428149537051.png
96 KB, 612x727
>>51874884
it's not always the same guy
>>
>>51875044
CPrimer Plus by Stephen Prata
>>
File: 1403837987365.png (48 KB, 400x389) Image search: [Google]
1403837987365.png
48 KB, 400x389
>mfw /g/ can't even average 2 complex numbers in C
>>
>>51875069
>le meme frog
>>
>>51875069
ffs /g/, how stupid can you be?
>>
>>51875069
prove him wrong, anons!
>>
File: 1406026539260.png (191 KB, 550x550) Image search: [Google]
1406026539260.png
191 KB, 550x550
>>51875085
>>51875069
>>51875096
Holy shit man you could at least try to pretend to be a different person
>>
>can't average numbers
>argue about traps and anime
today's /dpt/ quality, everyone!
>>
>>51875107
>2016
>pretending
how much of a shitstain are you, webfag? still butthurt for getting rekt? burgers?
>>
>>51874864
>fib(x) using iteration: product [1..x]
you what, /g/?
>>
>>51875049
i'm fairly sure it's mostly Tetsumi, code artisan and x times undefeated master debater
>>
>>51874635
python, quickly and shittily done in about 20 minutes
https://paste.installgentoo.com/view/raw/7f803757
>>
>>51875124
/g/ is the bottom rung of programming; the css trash has invaded /dpt/
>>
>>51875069
I wonder how many people even know about the complex keyword.
>>
File: 1438820665798.jpg (58 KB, 450x443) Image search: [Google]
1438820665798.jpg
58 KB, 450x443
>>51875141
>>51875118
>>51875111
>>51875096
>>51875085
>>51875069
>>51875149
Stop flooding the fucking thread you goddamn manchild.
>>
>>51875131
>forgot about the big dick playa
don't make me bait you into averaging 2 numbers, m8!
>>
>>51875158
>animuuuuuu
>muh traps
>wdg
>homescreen general
>watch thread
>checkem
anon, pls
>>
>>51875111
>trips of truth
>>
>>51875158
>remembering the time his ass got destroyed
still butthurt?
>>
>>51874635
Python, did not take track of time, maybe 15 minutes
#!/usr/bin/env python3
import sys

def print_star(text):
w = h = len(text) * 2 - 1
img = [[' ' for x in range(w)] for y in range(h)]

def setchar(i, c):
img[int(h/2)][i] = c
img[int(h/2)][-i-1] = c
img[i][int(w/2)] = c
img[-i-1][int(w/2)] = c
img[i][i] = c
img[-i-1][i] = c
img[i][-i-1] = c
img[-i-1][-i-1] = c

for i in range(0, len(text)):
setchar(i, text[i])

for line in img:
print("".join(line))

if len(sys.argv) != 2 or len(sys.argv[1]) < 2:
print("usage: %s text" % sys.argv[0])
sys.exit(1)
print_star(sys.argv[1])
>>
what should I know before diving into discrete math.(using Graham and Knuth's book)?
>>
>>51875508
basic arithmetic (like averaging two numbers)
>>
File: scala.png (13 KB, 167x246) Image search: [Google]
scala.png
13 KB, 167x246
Getting into Scala.
I like the FP + OOP combination, much better than Erlang or Elixir.
I do miss the bit syntax in those languages, but it's faster and clearer than Python.
Python gets messy quite easily.
>>
>>51874414
Who is this beauty?
>>
Is a C array basically a pointer?
>>
>>51875818
An array has storage associated with it and its label cannot be reassigned.
>>
>>51875843
>array has storage
so does a pointer
>cannot be reassigned
you can declare the pointer const
>>
>>51875878
>so does a pointer
Not necessarily. A pointer can point to anywhere; it doesn't mean that it "owns" that memory.
>you can declare the pointer const
That's besides the point.

Also I should also mention that the way they're accessed is different.
If you do
// file1.c
int array[10];

// file2.c
extern int *array;

That will produce incorrect code.
>>
File: 1450123841024.jpg (356 KB, 1280x720) Image search: [Google]
1450123841024.jpg
356 KB, 1280x720
>encog neural networks in Java
kill me
>>
>>51874635
like 20 minutes
def shitpost(inp):
out = ""
grid = []
l = len(inp)
for x in range((l*2)-1):
grid.append([])
for y in range((l*2)-1):
grid[x].append(" ")
for i in range(l):
grid[i][l-1] = inp[i]
grid[-i][l-1] = inp[-i]
grid[l-1][i] = inp[i]
grid[l-1][-i] = inp[-i]
grid[i][i] = inp[i]
grid[i+l-1][i+l-1] = inp[-i-1]
grid[-i+l-1][i+l-1] = inp[-i-1]
grid[i+l-1][-i+l-1] = inp[-i-1]
for x in grid:
for y in x:
out += y
out += "\n"
return out
>>
>>51870954
pls
>>
>>51875905
>That will produce incorrect code.
Will it really? On what platform?
>>
>>51875992
both of them
>>
>>51875946
just noticed something
make that 25 minutes
def shitpost(inp):
out = ""
grid = []
l = len(inp)
for x in range((l*2)-1):
grid.append([])
for y in range((l*2)-1):
grid[x].append(" ")
for i in range(l):
grid[i][l-1] = inp[i]
grid[-i-1][l-1] = inp[i]
grid[l-1][i] = inp[i]
grid[l-1][-i-1] = inp[i]
grid[i][i] = inp[i]
grid[i+l-1][i+l-1] = inp[-i-1]
grid[-i+l-1][i+l-1] = inp[-i-1]
grid[i+l-1][-i+l-1] = inp[-i-1]
for x in grid:
for y in x:
out += y
out += "\n"
return out
>>
>>51875997
You're right. It breaks. Windows Mingw GCC.

The pointer it always a null pointer. The way this works on my platform is:

// file1.c
int array[10];


// file2.c
extern int array;

...

printf("main: %d",(&array)[3]); /* prints 4th element */
>>
Can anyone tell me whats wrong with my code? I'm experiencing a heißenbug with new_image() here. The function works just fine, but calling it a second time causes a segfault. Unfortunately, this isn't the case when running it through gdb and I can't use valgrind because I'm on windows. PLEASE HELP.

#define IMG_DATA float

typedef struct _Image
{
IMG_DATA** data;
int w, h;
int max;

} Image;

Image* loaded_image = NULL;

Image* new_image(int w, int h, int max, bool *success)
{
Image* img = malloc(sizeof(Image*));
img->w = w;
img->h = h;
img->max = max;
img->data = malloc(h * sizeof(IMG_DATA*));

if(!img->data)
{
printf("Unable to allocate heap space\n");
*success = false;
return NULL;
}

for(int i = 0; i < h; ++i)
{
IMG_DATA* pixel_row = malloc(w * sizeof(IMG_DATA));

img->data[i] = pixel_row;

if(!pixel_row)
{
if(success)
*success = false;
return NULL;
}

for(int j = 0; j < w; ++j)
img->data[i][j] = 0;
}

if(success)
*success = true;
return img;
}
>>
>>51876105
bump
>>
File: 1433891629140.webm (240 KB, 600x440) Image search: [Google]
1433891629140.webm
240 KB, 600x440
>>51876160
They can't help you anon. I've been posting >>51875991 for a day and a half. Alas, they've all been lost in the abyss that is averaging two ints. :(
>>
>>51876160
>Hasn't even been 10 minutes
>Hasn't even been any replies since your post
I was thinking about maybe giving some insight, but I don't want to anymore.
>>
>>51876105
>sizeof(Image*));
>>
>>51876171
Or fighting over an anime pic.
>>
>>51876174
Hey, fuck you too anon, but I'm short on time here (unlike you fucking NEET).

>>51876178
Oh dear. I'm a retard. Thanks anon-kun.
>>
>>51876105
It works without problem for me. I don't think the problem is in the code.


    bool success1,success2;
Image *x=(Image *)new_image(1000,1000,100,&success1);
Image *y=(Image *)new_image(1000,1000,100,&success2);

printf("%d %p, %d %p\n",success1,x,success2,y);

return 0;


1 1a30ffb0, 1 188b8480
>>
>>51876234
>>51876234
also your code sux, i hope you are still in school or have a learning disability at a minimum
>>
>>51876250
What's wrong with it, aside from the malloc fuckup?
>>
>>51876236
>what is undefined behavior
Just because it works in an isolated case don't mean its working in general.
>>
>>51876259
>defining names for primitives
>getting the sizeof pointers
>using boolean pointers to check if the function failed or not
wew lad
>>
>>51876272
Yeah, I missed it. >>51876178 got it right.
>>
>>51876272
Like immigration.
>>
>>51876259
Apart from all other things, you should use one contiguous array for all pixels.
>>
>>51876279
Well, either the image has to be an out parameter or the boolean. Why does it matter?
>>
>>51876259
lots of little shit. skip having the the bool* success being passed as an argument, just return a null ptr if the function fails.

assuming that the function definition is part of your assignment, there are a few other things.
you don't check to see if the first malloc failed.
you don't check to see if 'success' is null the first time.
the style sucks, i'd use short-circuiting to make it simpler/cleaner.
there are probably performance issues with the way you are allocating the data but i don't feel like thinking about it too hard right now cause i'm a huge faggot pussy
>>
>>51876289
So using a regular array instead of a 2D one?
>>
>>51876303
because your function is either going to return a NULL or valid pointer, use those to check if your function was a success.
>>
>>51876316
Everyone does it this way. Using array of arrays is just too much overhead.
>>
>>51876327
Eh, this is homework, so I don't care much for performance or memory usage.
>>
>>51876352
Yeah, I guess for learning purposes it's even better to try all kinds of ways.
>>
I'm trying to do regex in C# but every tutorial I find is just completely unhelpful, not once have I seen anyone explain how to construct an expression.

I want to match the characters "a", "b" and "v" lower and upper case. along with numbers 0-9 and a period. But there's literally nowhere online that explains how I'd do that.
>>
>>51876400
character class.
usually regex is the same through most languages so it'd be something like
/[abv0-9.]/gi
>>
I am pleased to announce that cuck is back.

We can post cuck again.

It's like Christmas came early.

(no tricks, I promise)
>>
>>51876425
cuck desu senpai?
>>
>>51876441
-_- fuckin' cucks.
>>
>>51876441
Sadly, the other filters haven't been removed yet.
>>
>>51876410
Doesn't seem to work, no version of this seems to work.

I just want to ensure that input isn't anything but abvABV0-9 and a period. But I can't seem to make it stick at all.

Constructing these things is never explained which is a pain in the ass.
>>
>>51876465
i guess iterating each character and check if
/[^abv0-9.]/i
then fail
>>
>>51876425
top cuck
>>
>>51876465
https://regex101.com/r/jH1pF5/1
>>
>>51876493
This is vaguely helpful, but doesn't really give me any code snippets to show how the thing is constructed.

I don't know how I'm meant to store the expression, where I set the options or what inputs might return.

Why is Regex such a confusing mess with absolutely no alternative?
>>
>>51876532
It's piss easy and well documented, anon... What the hell are you doing?

String[] lines ={
"hello",
"abv",
"abv93458345",
"5433b654354",
"aaaaabbbbbbbbbbbbbbvvvvvvvvvvvvvvvv",
"16777216a",
"a.v",
"v.a",
"..........................................",
"Aa",
"aa",
"aAbB",
"aAbBcC",
"...",
};

Regex regex = new Regex("^[abv0-9.]+$", RegexOptions.IgnoreCase);
foreach(String line in lines) {
Console.WriteLine((regex.IsMatch(line) ? "[+]" : "[-]") + " " + line);
}


[-] hello
[+] abv
[+] abv93458345
[+] 5433b654354
[+] aaaaabbbbbbbbbbbbbbvvvvvvvvvvvvvvvv
[+] 16777216a
[+] a.v
[+] v.a
[+] ..........................................
[+] Aa
[+] aa
[+] aAbB
[-] aAbBcC
[+] ...
>>
>>51876452
has hiroshima nagasiki explained the decision to unfilter cuck but not the others?
>>
>>51876599
Maybe they expire automatically.
I'll send him a letter asking to renew the filter.
>>
>>51876584
Thanks, that works perfectly.

Hey if it was really well documented and was explained in a way a novice could understand, I wouldn't have bothered asking here.

I understand the concept but nowhere showed how to construct one in C#.

Thanks though, I understand the construction now.
>>
>>51876624
https://msdn.microsoft.com/en-us/library/ms228595.aspx
Second result in google, literally shows you how to construct regex in C#. I can easily understand that, and I've never even touched C#.
>>
>>51876624
https://www.google.com/#q=how+to+use+regex+in+c%23+stackoverflow
>>
> he's not writing a calculator in Swift
top kek, literally kill yourself
>>
>>51876850
looks like shit
>>
>>51874635
Unoptimized CL.

(defun blank (length)
"Make blank line."
(make-string length :initial-element #\Space))

(defun star-arms (input length n)
"Print star arms."
(let ((char (aref input n)))
(setf line (blank (- (* 2 length) 1)))
(setf (aref line n) char)
(setf (aref line (- length 1)) char)
(setf (aref line (- (* 2 length) n 2)) char)
(write-line line)))

(defun star (input)
"Make star."
(let ((length (length input)))
(loop for n from 0 to (- length 2)
do (star-arms input length n))
(write-line
(concatenate 'string
(loop for n from 0 below length collect (aref input n))
(loop for n from (- length 2) downto 0 collect (aref input n))))
(loop for n from (- length 2) downto 0
do (star-arms input length n))))

(star "meme master")
>>
>>51876867
maybe because I literally started now and it still has no design?
>>
>>51876885
it's cuz you're stupid
>>
>>51876850
Well it's flat as fuck, you're hired!
>>
>>51875569
Please watch this before you learn any more:
https://www.youtube.com/watch?v=uiJycy6dFSQ

If you want to use a language like Scalia that's not a cluster fuck, try f#
>>
File: froggu.jpg (101 KB, 400x600) Image search: [Google]
froggu.jpg
101 KB, 400x600
>>51876913
no design yet you fagget

>>51876890
yeah whatever you say kid
>>
>>51876876
~$ ./lolisp meme.lisp
(()(:))(()(((()))((((*))))(())((()))((((*))))()))(()(((()))(()())(((())(()())))
(()())))()
Meme: 89
Total: 825
Total meme percent: 81.818%
>>
>>51876850
Not gonna lie but that's pretty hip(ster)
>>
To average two numbers in C without overflow:
a/2+b/2+(a%b%2)
>>
>>51877203
a/2+b/2+(a%2+b%2);
quick fix
>>
>>51877239
int a=0xffffffff;
int b=0xffffffff;
int avg=a/2+b/2+(a%2+b%2);
printf("%08x\n",avg);
return 0;


fffffffe
>>
>>51877239
3/2+5/2+(3%2+5%2)=5, not 4.
>>
>>51877265
shit, -3 and 5 works with a%2 + b%2 but 3 and 5 doesn't. i'd rather do branching than figuring out why at this point
>>
>>51877292
Do you honestly have nothing better to do? Convert it to long long or double and do average the obvious way.
>>
>>51875158
>>>/tumblr/
>>
>>51877309
Can anyone check if this solves the averaging two ints problem?

#include <stdio.h>

int main(void)
{
int a, b;
a = -3; b = 5;
if (a % 2 != 0 || b % 2 != 0) {
if (a % 2 != 0 && b %2 != 0) {
if (a < 0 || b < 0) {
printf("%d", a/2 + b/2 + (a%2 + b%2));
} else {
printf("%d", a/2 + b/2 + 1);
}
} else {
printf("%d", a/2 + b/2 + 0.5);
}
} else {
printf("%d", a/2 + b/2);
}
}
>>
>>51877387
int a=0xffffffff;
int b=0xffffffff;
if (a % 2 != 0 || b % 2 != 0) {
if (a % 2 != 0 && b %2 != 0) {
if (a < 0 || b < 0) {
printf("%d", a/2 + b/2 + (a%2 + b%2));
} else {
printf("%d", a/2 + b/2 + 1);
}
} else {
printf("%d", a/2 + b/2 + 0.5);
}
} else {
printf("%d", a/2 + b/2);
}


-2

Does not.

Also you're printing a floating point number with %d mask in one of cases which means you are not a very clever person.
>>
>>51872358
bumping this
>I'd be happy for a little code review on this, is there anything I could have done better?
>Goal: find the number of permutations of a list that will give you the same binary search tree.
>example:
>there are two permutations of [1,2,3] that will give you the binary search tree:
  2 
/ \
1 3

>[2,1,3] and [2,3,1]

from math import factorial
class Tree:
def __init__(self, values = None):
self.left = None #left node
self.right = None
self.lc = 0 #number of nodes on the left tree
self.rc = 0
if type(values) == list: #add initial values to tree, if any
self.root = values[0]
for value in values[1:]:
self.add(value)
else:
if values != None:
self.root = values #add value to root node

def add(self, value):
if self.root > value:
self.lc += 1#incriment left node counter for this tree
if self.left:
self.left.add(value)
else:
self.left = Tree(value)
else:
self.rc += 1
if self.right:
self.right.add(value)
else:
self.right = Tree(value)

def binomial(n,k):
return factorial(n)/(factorial(k)*factorial(n-k))

def permute(tree):
if not tree: #only one way to permute a tree of size 0
return 1
options = permute(tree.right)*permute(tree.left)
choice = binomial(tree.lc + tree.rc, tree.rc)
return options*choice
def answer(seq):
return permute(Tree(seq))
>>
>>51877406
I was printing with %f before, then I changed to %d. I'll figure out what is wrong.
>>
>>51877387
Here's the solution, now stop wasting your time on this bullshit:

int avg(int a, int b) {
return (a >> 1) + (b >> 1) + (a & b & 0x1);
}


>>
>>51876876
>>51874635
Improved

(defun star (input)
"Make star."
(let* ((l (length input))
(lo (- l 1))
(ll (- (* 2 l) 1))
(star (make-array (list ll ll)
:element-type 'char
:initial-element #\Space)))
(dotimes (i l)
(let ((a (+ 0 i))
(b (- ll i 1)))
(map nil (lambda (x y) (setf (aref star x y) (aref input i)))
(list i b lo lo a a b b) (list lo lo i b a b a b))))
(dotimes (i ll)
(dotimes (j ll)
(write-char (aref star i j)))
(write-char #\Newline))
))

(star "meme master")
>>
>>51877521
Thanks, I managed to fix my code too so I guess I'm less of a retard now.
>>
>>51877539
>improved
>still a meme language
aight
>>
To average 2 ints in C# without overflow:
static int Average(int a, int b)
{
unchecked { return ((a+b)/2); }
}

static int Average(int a, int b)
{
return (int)(((uint)a+(uint)b)/2);
}
>>
>>51877630
>C#
Doesn't run on my router, it's shit.
>>
>>51877630
python
def average(a, b):
return (a + b) / 2
>>
But how do you average THREE ints?
>>
im developing motion detection software, and i dont know what would be the best inactivity timeout, i currently have 15 sec, what other software uses?
>>
>>51877699
You need a quantum processor for that shit
>>
>>51874880
>>notepad++
>loads entire file into ram
i. e. you can't load more than a gigabyte or so due to some limit
in its defense, most GUI text editors can't
>>
>>51877719
I have a quantum processor, but I'm using it to make the perfectly toasted toast. The math behind this is fuckin' revolutionary. The perfect heat-to-bread ratio. I gave it a whirl last night, and when i spread peanut butter on the toast, it melted but the bread was still soft enough to absorb a lot of the melted peanut butter, so each bite was like a rush of heaven itself. Good god.
>>
I would never hire a coder who can't code in C. It's not that they need C, but most likely if they can't code in C, they have no idea about how things actually work.

Joel Spolsky has an article on this.
>>
>>51877699
static int average(int a, int b, int c) {
return (a+b+c)/2
}
>>
>>51877630
>>51877663
original challenge is to do it in C.
>>
7get
/dog petting thread/
>>
>>51877779
god fucking damnit you nigger of a white man
>>
>>51877779
>>51877773
def average(a, b, c):
return (a + b + c) / 3
>>
>>51877773
Failure case:
a = b = c = 715827883
Try again
>>
>>51877816
static int average(int a, int b, int c) {
return if(a+b+c<715827883) { (a+b+c)/2} else {nigger}
}
>>
>>51877816
take another look anon. all numbers would fail.
>>
>>51877829
The average of 715827883, 715827883 and 715827883 should be 715827883 but the function returns -1073741823
>>
>>51877816
>taking the bait
>>
>>51877829
Oh you're right
Well it's not so easy to average 3 ints in C after all
>>
>>51877779
c is a dead language
>>
>>51877539
>>51874635
Python in one line because fuck it.
#!/usr/bin/env python3
import sys
(lambda input:(lambda ilen:(lambda m,olen:(lambda star:(lambda f,g:None)(list(map(lambda i:(lambda b:list(map(lambda x,y: star[x].__setitem__(y,input[i]),[i,b,m,m,i,i,b,b],[m,m,i,b,i,b,i,b])))(olen-i-1),range(ilen))),print("\n".join("".join(char for char in row) for row in star))))([[" " for x in range(olen)] for x in range(olen)]))(ilen-1,2*ilen-1))(len(input)))(sys.argv[1])
>>
>>51877914
top cuck
>>
>>51877914
This. Can't spell KEK without C.
>>
>>51877521
doesn't work with 0 and -1
doesn't work with -1 and -1
my code also doesn't seem to work with the first case, because it adds 1 and it goes to positive. working on fixing it.
>>
>>51877958
int avg(int a, int b) {
return ((a & ~(0x1 << 31)) >> 1) | a & 0x1 << 31 + ((b & ~(0x1 << 31)) >> 1) | b & 0x1 << 31 + (a & b & 0x1);
}
>>
>>51878004
1 is the same as 0x1
>>
>>51878015
And?
>>
>>51874635
matlab/octave

#!/usr/bin/octave -qf

if (size(argv())(1) < 1)
printf("Usage: star STRING\n");
endif

function [ y ] = star ( x )
x = int8([x, fliplr(x)(2:end)]);
len = length(x);
spaces = repmat(32, [len len]);
ldiag = diag(x);
rdiag = fliplr(ldiag);
vert = [zeros(len / 2, len); x; zeros(len / 2, len)];
horiz = vert';
y = char(max(spaces, max(max(ldiag, rdiag), max(vert, horiz))));
endfunction

disp(star(argv(){1}));
>>
>>51878004
avg(0, 5) => 0
avg(-1, -1) => 1073741823
ok then
>>
>>51878036
It's redundant.
>inb4 0x1 looks cooler
>>
drop this int averaging bullshit you turboautists.
>>
>>51878088
not why you're responding to. But to me
0x1 << 31

makes it easier to understand what the programmer is trying to achieve. It's more readable.
>>
>>51878114
I got to the point that it works with anything but negatives.
>>
>>51877410
Okay, first question. How the hell does [2, 1, 3] and [2, 3, 1] represent the binary tree you have there?
Would it be quicker to permute [1, 2, 3] and check if the result of the permutation is a correct binary tree?
>>
How do I filter something like 192.168.*.* ?
I think re.findall would work but... meh
        ban = [("192.168.1.1"),("192.168.1.111"),
("192.168.1.3"),("8.8.8.8"),
("192.168.0.1"),("192.168.1.194"),
("192.168.1.4")]#local IP,dns,do not want
d = os.getcwd()
if ip_address1 not in ban:
counter1 = counter1 + 1
if counter1==50:

>python
>>
>>51878165
regex?
192.168.(\d+).(\d+)
>>
>>51878156
>How the hell does [2, 1, 3] and [2, 3, 1] represent the binary tree you have there?

the first number encountered on the list represents the node, the rest of the binary search tree is created from there.
[2,3,1]
  2 

2
\
3

2
/ \
1 3


[2,1,3]

  2 

2
/
1

2
/ \
1 3


>Would it be quicker to permute [1, 2, 3] and check if the result of the permutation is a correct binary tree?

not for longer lists.
>>
>>51878165
from ipaddress import IPv4Network, IPv4Address

net = IPv4Network('192.168.0.0/16')
ip = IPv4Address('192.168.1.234')
net.overlaps(IPv4Network(ip))

yields
True
>>
>>51878267
I don't know, I already use socket and I was just thought of this..
ip = socket.gethostbyname(socket.gethostname())
>>
>>51878294
>I was just thought of this..
>>
>>51876938
It's the third time someone recommended F#, is that you again?
First two times were frustrations about Python.
I feel like F# is "too functional" for what I want to use it for, and it runs on the .net platform.
C# is a nice language though, and I probably would have used that, however the application I'm writing is strictly for Linux. I know Mono exists and the official runtime is being ported, but the tools are behind.
I considered using C++ (or even C) instead, but then I'd lose the accessibility I was initially aiming for.
Java only feels too bulky. Erlang and Elixir are too limited in OOP. Go and Rust are just fads.
I started over for the third time in the thirds language.
It's just that all programming languages suck and it feels very frustrating.
>>
>>51874414
Why is it not possible to do
<F, A, B> F<B> someMethod(F<A>, Function<A, B>) { ... }

in Java or C# with generics?

<A, B> ArrayList<B> someMethod(ArrayList<A>, Function<A, B>) { ... }

however works. Why can't I have the ArrayList be a generic value?
>>
>>51878371
Lel, you're retarded.
>>
>>51878382
Care to specify? You sound like one yourself
>>
File: 3_DR.jpg (835 KB, 4256x2832) Image search: [Google]
3_DR.jpg
835 KB, 4256x2832
>Write a program and continuously ask the user to enter a number or "OK" to exit. Calculate the sum of all the previously entered numbers and display it on the console.
> C#
>Do it as short/fast/understandable and most readable you can while using loops and if/else basics.

I am stuck... how to make it so the numbers add up AFTER I say OK not, right after I enter em'?
>>
>>51878440
You check them before adding together?
>>
>>51878413
How can you hear him?
He replied with text, anon.
>>
>>51878458
>>51878382
I'll assume you both are retarded 12y/o pythonistas until you answer the question
>>
File: 1254823802764.jpg (87 KB, 1024x1004) Image search: [Google]
1254823802764.jpg
87 KB, 1024x1004
Dear C# experts,

is it possible to make the following extension method work for all arrays of structs / value types?
https://gist.github.com/OmerMor/1050703
I'd like to be able to pass all of them as a byte array if needed rather than just a specific type
>>
>>51878454
 while (true)
{
Console.WriteLine(@"Please enter a number or 'OK' to exit");
var input = Console.ReadLine();
if ( input == "OK" || input == "ok")
{
Console.WriteLine(int.Parse(input) + int.Parse(input));
break;
}
else if (String.IsNullOrWhiteSpace(input) || String.IsNullOrEmpty(input))
{
continue;
}


It crashes if I enter OK
>>
>>51878440
Use an array?
>>
>>51878496
* also could there be any issues if I use this on my arrays from multiple threads?
>>
>>51878500
You're trying to parse the text "ok" into an integer
>>
>>51878519
yeah I saw it while posting, sometimes I feel dumb damn it
>>
>>51878486
>I'm retarded please spoonfeed meeeee!
>>>/tumblr/
>>
>>51878500
If the user typed "ok" you then try to parse a number from the input twice and sum the number "ok" together? Your logic makes no sense.
>>
>>51878532
>implying you have any idea about higher kinded types
Fuck off kid
>>
>>51878551
Oh the irony.
>>
>>51878564
why am I even discussing with a person who's only capable of bot-tier meme responses?
>>
>>51878572
Exactly. Let the idiots roll around in their own feces.
>>
Daily reminder that Samsung engineers can't average 2 negative ints.
>>
>>51878582
Math.avg(a, b); //or something like that

I have no time to deal with low level bullshit when developing software
>>
>>51878582
a/2 + b/2
>>
>>51877410
Okay.
In the constructor value in values[1:] is doubly slow, use a set instead, especially seeing as you'll never have repeats in your permutation.
Your binomial function can be slow, although it's correct. You could use something like this:
reduce(op.mul, range(n, n-r, -1))//math.factorial(n)

But I couldn't get it to work in Python 3.
>>
>>51878496
What are you actually trying to achieve?
>>
>>51878665
Shit, the reason is that the denominator should be fact(r).
def binomial(n, r):
return functools.reduce(operator.mul, range(n, n-r, -1))//math.factorial(r)
>>
>>51874414
>>51874414

Which language should I dedicate my time to and master as a first language?

Not sure what I want to do specifically as a developer, but I'm interested in mobile & desktop applications, game development and a decent amount of Web and hacking expertise.

I've spent the last week or so messing around with C. Seems simple but I think what I've learnt is very simple stuff (printf, scanf, strcmp, if, else, char, int, expressions, goto etc.)

Am I better suited to an object oriented language to start with? How can I learn an OOP language whilst also learning about the basics of lower languages?
>>
>>51878729
I'm using shitty 3rd party library (PresentationCore.dll) that only accepts byte/int/uint/long/ulong/float/double arrays as arguments
But my data is in various struct arrays
>>
>>51878878
Python, but fuck mastering that piece of shit. It's a great starting language though, you'll be best off with an easy language so you can focus on general concepts
>>
>>51878878
If you are doing good with C continue on and master it. Soon no one will know how to write C well and C will not be replaced as a library language for Unix systems. This creates a problem.
>>
>>51878921
Seems like the two suggested first languages, Python and C, are two languages that people say are worth learning but not worth learning.
>>
>>51878956
In what way does it create a problem? A lot of people have said that C++ has superseded it and it's just a matter of creating systems that support it.

By the way, does the term "embedded" refer to library related aspects? Like header files?
>>
>>51878974
It's true, you shouldn't be using either for most serious projects
>>
>>51879084
What languages should be used for serious projects?
>>
>>51879080
For application programming yes C++ is easier, as is Java, Go, Python, MATLAB etc. etc. But Unix and C are intertwined and most languages have a way to interface with C code, which makes C important for library code in a way no one other language can be (maybe C++ as there is a compatible interface).
>it's just a matter of creating systems that support it
Throwing away 40 years of accumulated libraries and applications is not likely to happen. And there is too much stratification in the low-level language market now for a new standard to pull through.

>By the way, does the term "embedded" refer to library related aspects?
No it means in low-power purpose-specific platforms, so called "embedded systems" like the dashboard system in some cars, telephones (not smartphones, they are low-power general purpose computers), SmartTVs, etc.
>>
>>51878878
I don't know why people put OOP on a pedestal. You'll be better off if you learn how to program without it being so pervasive.

Once you get somewhat proficient at writing C, you will be writing OOP code when it's absolutely necessary without even realizing it.
>>
>>51878496
MOOOOOOOOOOOODS
MODS
MODS
MODS
>>
>>51879226
typical Ctard, too stupid to understand OOP
>>
>>51879272
>>>/b/
>>
>>51879272
this >>51879293
>>
>>51879226
lel
>>
Learning some C and mysql connections.
How do I include
`mysql_config --cflags --libs`

in CMakeLists file?

I can add that to the parameters of GCC and it compiles without errors. I need to point cmake to mysql header.
>>
>>51878878
learn java. C really isn't all that much more than
>very simple stuff (printf, scanf, strcmp, if, else, char, int, expressions, goto etc.)

https://docs.oracle.com/javase/tutorial/
>>
>>51879279
>>51879310
>>51879328
Samefag
>>
>>51879318
The point of using CMake is so that you don't have to worry about manually plugging in the flags/libs through the pkg config but instead let CMake MySQL module handle it.
>>
>>51879226
The thing is, I think I'm habitually using C to write OOP programming as it is. All I'm doing is building things that take input and do something with it like printing things, adding together integers, or comparing strings and jumping to another command line based on the Boolean return value. I guess it's early days (learning since last Saturday with no prior programming knowledge). I've still taken the time to learn about more indepth stuff like memory (cache, primary, units; bits, nibbles, bytes etc.) and what a CPU is comprised of. Not sure how it helps but I'm sure it is essential. I'm also a Windows 10 user with no inkling of Unix or Linux: this is why I have doubts about learning C as a first language. Yes, I'm picking it up quite quickly but that's because I've always been good with syntax and remembering things. I believe my actual understanding of a lot of programming concepts is extremely loose.
>>
>>51879332
>i have no counter-argument so i'll just call samefag
1v1 fite me fgt
>>
>>51879318
use makefiles like a normal, heterosexual person
>>
>>51879351
Nothing you mentioned has anything to do with OOP. You've already been somewhat brainwashed.

>>51879359
There's no counter-argument without an argument in the first place.
>>
>>51879378
#SHOTSFIRED
>>
chatserver and client in python. Trying to make it as small as possible.
>>
>>51879378
Unbrainwash me then, oh noble hero.

Not brainwashed, I've just been brainfucked as I've gone from working in social networking to learning about L2 cache systems and data structures. I said my knowledge was loose.

Explain what OOP programming is in a short paragraph that would be understood by a noob like myself.
>>
>>51879411
Then don't use python.
>>
What makes a program fast or slow? # of statements executed?
>>
>>51879363
lol I'm using clion
>>
>>51879446
The number of instructions executed, how many cycles each instruction takes and how long each cycle is.
>>
>>51879436
OOP is about objects with fields and methods, encapsulation, polymorphism, and inheritance. Inheritance is the only things of those that you really need to be wary about, but in general the bad parts of OOP are trying to make a model to "fit the real world" even if it doesn't make any sense to do so in code.

It's like having a Circle with only a diameter inherit from an Ellipse with width and height. The is-a relationship you have in real life is not the same is-a relationship that is modeled by OOP. A circle is not an ellipse and MORE (as in OOP with inheritance), it is a special case.
>>
>>51879446
algorithm complexity (BigO)
>>
>>51879293
>>51879308
>pedophiles
gtfo
>>
>>51879272
My image is SFW
>>
File: 1442177684348.png (1 MB, 1004x676) Image search: [Google]
1442177684348.png
1 MB, 1004x676
>>51879436
i'll give you the short version since this is the nth time i'm writing something like this

when you start your car you just turn the key or pres a button, you don't fiddle with the ignition and fuel injectors and whatnot. the car has a relatively simple interface (compared to what goes on inside the car) with the steering wheel and gas pedal and such. apply the same concept to programming: you create objects and all you have to do to use them effectively is use their interface, you don't have to mess around with implementation details. so like if you get an engine upgrade for your car, you can still use it just fine because the interface remains the same. it's the same kind of deal with objects inside your program.
>>
>>51879511
A constant of 1000 still doesn't allow your program to be fast, even if it runs in O(logn) time.
>>
>>51879436
>>51879492
Basically, what I'm trying to say is that the OOP built into most languages is fatally flawed, because inheritance screws things up royally. Subtyping (polymorphism) in general is okay, and so are encapsulation and the idea of objects.
>>
>>51879328
Java? kek.
>>
>>51879492
typical Ctard
>>
>>51879492
>I don't know what OOP is
no wonder, if you can't even average 2 ints
>>
>>51879492
Cmen detected.
Can't spell cuck without C.
>>
>>51879550
epic meme

inb4 you suggest C# which is pretty much the same as java but with ridiculously ugly syntax, with the syntax so ugly only because they didn't want it to look like a 100% identical clone of java
>>
>>51879559
you sure told him, webfag
>>
>>51879547
literally retarded
>>
learn C or C++?
>>
>>51879575
>can't average 2 ints
>programmer
>>>/wdg/
>>
>>51879543
>A constant of 1000 still doesn't allow your program to be fast
just use more powerful CPU also Moore's law
and maybe parallel work
>>
@51879559
@51879563
@51879575
@51879607
all me
>>
>>51879611
C++ definitely. Ctards NEVER learn how to program in C++ properly. prime example: >>51879492
>>
>>51879613
>>51879563
I can average two positive integers without any overflow. Can I join the club yet or do I need to do it with negatives too? :^)
Thread replies: 255
Thread images: 19

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.