[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: 23
File: prog.jpg (155 KB, 850x1003) Image search: [Google]
prog.jpg
155 KB, 850x1003
[Daily Programming] Thread

Pair Programming Bully Edition.

Old thread is +300 (>>51731325)

What are you working on, Anonymous ?
>>
>>51738982
Working on learning muh algorithms
>>
>>51738982
I was just about to make a himegoto /dpt/.
Good save.
>>
>>51738982
godamn i cant take these cute anime memees anymore

also sauc
>>
File: agdg in a nuttshell.png (64 KB, 914x800) Image search: [Google]
agdg in a nuttshell.png
64 KB, 914x800
>>
Html mainframe written with a GUI from visual studio
>>
>>51738803
>How do I force IntelliJ to use this style

File > Settings > Editor > Code Style > Java > Wrapping and Braces > Brace Placement
Set it to next line, shifted.
>>
Should I be trying to reimplement comfy OOP features in C?
>>
>>51739064
Unless you really want to, just use something like C++ or D
>>
>>51739003
this t᠎bh fa᠎m
>>
>>51739057
Also, after you change your format settings, do:
Ctrl + Alt + L
It'll format your source to match your settings. You can do this for individual classes or the entire project at once.
>>
>>51739091
>>51739057
Thanks, man. It's really beyond me why would anyone use anything but that.
>>
>>51739003
>>51739085
You're on an anime site m8.
>>
>>51739064
C is a great sandbox to learn how little you actually need OOP. When it becomes natural to do things in a way that ends up being OOP, then that's fine.
>>
>>51739022

>/dpt/ sucking each others' dicks
Sounds about right.

>>51739064

Don't. If you really need OOP in your systems programming language, there are numerous other languages that allow you to implement just that. Ada has it, C++ has it, I'm pretty sure Rust has it.

C should be programmed like C, and C++ should be programmed like C++.
>>
>>51739113
No, I'm on the technology board on an image board website.
>>
>>51739139
4chan was originally created because moot couldn't post loli on something awful.
>>
File: 1424876697266.png (75 KB, 198x198) Image search: [Google]
1424876697266.png
75 KB, 198x198
>>51739139
I was being ironic m80m8. Annie may is gr8.
>>
File: Untitled.png (44 KB, 452x279) Image search: [Google]
Untitled.png
44 KB, 452x279
>>51739139
>>
Reposting question: what would be a good way to redirect stdout into a tkinter text widget so it updates in real time? This is python 2.7
>>
File: げみ-396769-カイ-8.jpg (854 KB, 1000x667) Image search: [Google]
げみ-396769-カイ-8.jpg
854 KB, 1000x667
anybody have experience with flex/bison?

rev1.l
%{
#include <stdio.h>
#include "rev1.tab.h"
%}
%%
[0-9]+ { yylval.val = atoi(yytext); return NUMBER;};
[ \t] ;
\n return 0;
. return yytext[0];
%%


rev1.y
%{
#include <stdio.h>
#include "rev1.tab.h"
%}
%union {
double val;
}
%token <val> NUMBER
%type <val> expression
%%
statement: expression '\n' {printf("= %f\n", $1);};

expression: expression '+' NUMBER { $$ = $1 + $3; }
| expression '-' NUMBER { $$ = $1 - $3; }
| NUMBER { $$ = $1;}
;
%%


when I compile and run, nothing happens when I enter any numbers, like 2+2 or even just a single number, 2
>>
File: 1429852208959.jpg (682 KB, 600x3300) Image search: [Google]
1429852208959.jpg
682 KB, 600x3300
>>51739003
>weeb
>>
>>51739242
don't know your question, but you should ask in Stack overflow.
>>
I'm creating some basic geometry structs for OpenGL for use with meshes. Do I include the scale of the shape in the struct alongside the offset? I can't decide if that is the most efficient way of doing this. I'm also not sure what else I might need that isn't directly related to the structure of the shape. Like for example things like radius are a given.
>>
Does anyone here draw out their functions before actually writing anything complex?
>>
>>51739374
Something like scale would be part of the transformation matrix, which is separate from the intrinsic mesh properties.
>>
>>51739399
yeah, you should
>>
>>51739399
I usually list what it's going to do step by step and then create it step at a time then when it works optimize it.
>>
>>51739288
There's already a similar question that doesn't work at all, they'll probably tell me to fuck off.
>>
>>51739419
Does that count for offset as well? Because from what I can tell the mesh offset is just zero by default. Or am I fine to just include the offset in the struct.
>>
>>51739265
Why does that language look like complete shit
>>
>>51739456
No. Again, position wouldn't be intrinsic.

Think of the flyweight pattern. Meshes are typically shared between hundreds of individual instances. Separate what is shared and what is unique.
>>
File: logo.png (13 KB, 444x444) Image search: [Google]
logo.png
13 KB, 444x444
>>51738982
The algorithmic language Valutron.

Valutron is my algorithmic language for programming computers. Derived principally from Scheme (as defined in R6RS) and from ISO Lisp it provides an object-oriented and functional environment in which to build software.

The two main features Valutron offers that define it apart from other languages are, first, a powerful object model descended from iLOS (ISO Lisp Object System) and that of Objective-SmallTalk, which permits extreme dynamism and uses total-late-bound multimethods; the second, a code representation called V-expressions, which provide an algebraic syntax option for the language.

The implementation I am working on is called Valutron QuickSilver Performance Engine. It is written in Objective-C. Input is first transformed into Cons trees and then compiled into bytecode, which is executed in a precision virtual machine whose design incorporates influence from Gnu Guile and the SECD Machine. A clean Trace-and-Sweep garbage collector is used to manage memory use; this collector is very efficient and fast, and leaves little reason for anyone to prefer manual management.

Finally, Valutron offers a pleasant interactive REPL environment.

Valutron is hosted at http://github.com/Valutron/Valutron and is not yet ready for mass consumption.
>>
File: げみ-396769-カイ-5.jpg (449 KB, 700x491) Image search: [Google]
げみ-396769-カイ-5.jpg
449 KB, 700x491
>>51739472
it's a preprocessor that compiles regex to a C lex engine
>>
>>51739475
The structs aren't actually related to the rendering process beyond determining a shape's proportions. I'm using them for collision operations primarily but I need to keep things uniform.
>>
Daily reminder not to listen to Andrei.
If you encounter a post shilling D, tell them to fuck off.
>>
>>51739524
I still wouldn't couple that kind of information to the rendering geometry.
>>
File: 1441303847610.gif (2 MB, 176x180) Image search: [Google]
1441303847610.gif
2 MB, 176x180
>>51739499
Was it your intention to make this Fedora: The Language?
>>
>>51739499
I swear, one day you'll regret mentioning Objective C.
>>
>>51739552
Yeah but, say I have a circle and the scale is 2. If that information isn't being passed to the collision detection operation the circle is going to overlap with the thing it is colliding with when it is rendered.
>>
How do I stop a thread in python?
    thread.stop()
NameError: name 'thread' is not defined
>>
>>51739594
You don't stop threads. Let it return.
>>
>>51739593
I already explained how per-instance information should be kept separate from shared information.
>>
>>51739499
do you accept donation ? :3
>>
>>51739594
You can't stop the Daily Programming Thread
>>
I'm at work with nothing to do, please help by giving me something fun to program.
>>
File: Apple-Swift1.jpg (28 KB, 570x379) Image search: [Google]
Apple-Swift1.jpg
28 KB, 570x379
>>51739499
>It is written in Objective-C
Why not write it in a language that's planned to supersede Objective-C in just about every place it's used.
>>
File: 1387749838701.jpg (90 KB, 501x501) Image search: [Google]
1387749838701.jpg
90 KB, 501x501
OH SHIT /G/ ive done fizzbuzz test in python

Does it mean i am not a retard?

 
for i in range(1, 101, 1):
if i % 3 == 0 and i % 5 == 0:
print "FizzBuzz"
elif i % 3 == 0:
print "Fizz"
elif i % 5 ==0:
print "Buzz"
else:
print i
>>
>>51739640
>python
Retard confirmed
>>
File: 1423096306690.jpg (61 KB, 852x480) Image search: [Google]
1423096306690.jpg
61 KB, 852x480
>>51739619
And I already explained how scale is in this instance if only the circle is changing scale. Changing the radius would be stupid.
>>
>>51739640
>range(1, 101, 1)
lel, why specifying step of 1 when it's the default one ?
>>
>>51739678
Sounds like you have it all figured out, then.

Decoupling rendering data from logic data and decoupling shared data from per-instance data are orthogonal.
>>
>>51739640
fixed
for i in range(1, 9001, 1):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 ==0:
print("Buzz")
else:
print(i)

>>
>>51739499
can someone unbuzzwordify this into normal speak?
>>
>>51739594
stopping threads is a bad idea because it isn't deterministic in most cases
do it in this style
http://play.golang.org/p/Ne_4xnJ3mR
>>
>>51739704
tldr: benchmark-fag new troll
>>
>>51739695
>it's not over 9000
>>
>>51739526
thanks
>>
http://adventofcode.com/

Everyone still got 14 stars?
Good.
>>
File: Untitled.png (4 KB, 702x74) Image search: [Google]
Untitled.png
4 KB, 702x74
>>51739768
>Everyone
>>
>>51739768
>wasting time on this shit instead of programming actual useful stuff
>>
>>51738982
Hey, anyone know about security in java? i doingsomething but it's now working.

what i'm doing is basically encrypt a text using AES, then encrypt the AES key with the receiver's public key(RSA), so he can decrypt the AES key using his private key(RSA) and read the message.

but when i decrypt the AES key i cannot use it to decypt the message.
>>
>>51739705
thanks but I don't know shit about python and don't understand it
;_;
I probably shouldn't even be doing threading yet, it's only been a month.
>>
>>51739792
>not knowing the amount of stars you have without registering

>>51739818
>"I swear, I can totally solve them if I wanted to!"
>>
>>51739792
>not having a reddit account

are we still pretending to hate reddit ?
>>
>>51739862
>Registering at all
>Even with a fake account
>>
>>51739818
>wasting time exercising in a gym when you could be lifting actual stuff
>>
Someone explain to a retard what is the point of a linked list?

As I understood it's so that you know which nodes come before and after a certain node?

But I know this just fine with a list?

If I have list[5] I know that list[4] comes before and list[6] after, so what is the point?
>>
>>51739399
For work stuff, I draw out everything. For personal projects I only draw out parts that include multithreading, what is running when, when to sync, etc.
>>
>>51739667
i made it in java as well
so i am not a retard anymore?
public class fizzbuzz {

public static void main(String[] args) {

for (int i = 1; i < 101; i++){
if (i % 3 == 0 && i % 5 == 0){
System.out.println("Fizzbuzz");
}
else if(i % 3 == 0){
System.out.println("Fizz");
}
else if(i % 5 == 0){
System.out.println("Buzz");
}
else{
System.out.println(i);
}
}
}
}
>>
>>51739399
>Does anyone here draw out their functions
you mean classes?
>>
>>51739837
you shouldn't be doing threading then
wrap your head around doing things synchronously, don't start worrying about things running concurrently before you got that figured out
>>
>>51739908
>so i am not a retard anymore?
You have one more closing bracket than there are opening brackets in your code.
>>
File: 1409768689961.jpg (11 KB, 251x242) Image search: [Google]
1409768689961.jpg
11 KB, 251x242
>>51739898
>>
>>51739898
Try adding an item in from of the item at list[0] or somewhere in the middle of the list
>>
>>51739957
It's to ensure it's really closed
>>
>>51739868
The people who bitch about Reddit are like people who go to restaurants for no other reason than to complain.
>>
>>51739898
different implementations of container classes have different space-time costs

for example, it is constant time cost to insert elements into the middle of a linked list, because you just adjust the links before and after. whereas a "list" in Python is a dynamic array, and inserting a new element in the middle requires you to move forward every element that follows in order to make space. so the time is proportionate to the length
>>
>>51739868
>>51740003
You know where you should both go.
>>
>>51739868
>having an account on literally any website
narcissism desu
>>
>>51739898
There is literally no point to a linked list. They're a retarded data structure meant for an architecture that doesn't exist and never will. Use contiguous memory.
>>
>>51739908
>java
double retard, lmao
>>
>>51739768
first day was easy peasy.

enum Instruction : String {
case Up = "("
case Down = ")"
}

func solveFirstDay() -> Int {
return input.characters.reduce(0) {cur, new in
switch Instruction(rawValue: String(new))! {
case .Up:
return cur + 1
case .Down:
return cur - 1
}
}
}
>>
everyone needs to stop memeing

also nothing wrong with at least registering adventofcode with a github account for example, just register so you can join in with the challenges, stop ironically acting like a hipster
>>
>>51740060
why?
>>
File: 12148412.png (5 KB, 73x100) Image search: [Google]
12148412.png
5 KB, 73x100
>>51740051
>There is literally no point to a linked list. They're a retarded data structure meant for an architecture that doesn't exist and never will. Use contiguous memory.
>>
>>51740051
>have to delete the 250000th item in a 1000000 item indexed linked list: index + n steps, then modify a pointer
> have to delete the 250000th item in a 1000000 item array: memcpy a gajillion megabytes around every time this happens
Brilliant.
>>
>>51740091
>everyone needs to stop memeing
Memes have come to far. Now everyone thinks they're hot shit because rather than give an intelligent reply to a post, they can just "LOLOL UR JUST USING A MEME OS/LANGUAGE/PHONE/CONSOLE Xddd"
>>
>>51740094
because it's shit

>>51740091
butthurt
>>
How does one into hacking?
I dont want to be a hacker nor really care for hacking. But to be a hacker I feel like you need godlike cs skills which is something Im interested. Furthermore I just want knowledge of how stuff works.
I know nothing about javascript or web based stuff.
With my understanding if I wanted to hack say a program, with my current knowledge decompile it in C, then look for some error possible through user input which sounds a lot easier than I can imagine implemented.
For things like cracking passwords I imagine thats nothing more than a script used but how would you get around the multiple attempts things.
I dont actually expect you guys to answer me honestly because I dont expect most of you to have the skills for this. But usually theres 1 knowledgeable person here.
>>
>>51740051
>frequently adding, removing, and rearranging items never happens
>>
>>51739957

I counted 7 closing and 7 opening brackets in there, Anon.

>>51739768

Been busy with finals. Do you still have the installgentoo paste links for the input files and problems?
>>
>>51740009
>it is constant time cost to insert elements into the middle of a linked list
In the MIDDLE, it isn't constant time. You have to chase pointers until you reach the place you want to insert it. That will probably take linear time, though it depends on the situation.

Inserting something at the front takes constant time.
>>
>>51740119
Still faster than cache misses.

>>51740136
Define hacking.
>>
>>51740136
No offence, but you sound like a script kiddie
>>
>>51740144
>Do you still have
I'm not that guy.
And no. I save them in README files in my repository though.
>>
>>51740136
First you install Kali
>>
>>51740152
>you need to optimize for linear iteration all the time
>>
>>51740086

For me:
#!/usr/bin/env ruby

floor = 0
reached_basement = false

s = File.read "input.txt"
s.size.times do |i|
c = s[i]
if c == '(' then
floor += 1
else
floor -= 1
if floor < 0 && !reached_basement
puts "Reached basement at position: #{i}"
reached_basement = true
end
end
end

puts "Final floor: #{floor}"
>>
>>51740136
>how do I into hacking
Install cheatengine and play around.
>>
>>51740144
>7 closing and 7 opening brackets in there
now check the curly ones
>>
>>51740136
I use EMacs and ELisp for hacking. E means electronic, like email.
It is the best, you should try it, and it needs skills, not just scripts you find online. I have hacked over 200 accounts with it.
>>
>>51740152
>Still faster than cache misses.
No. An indexed list is far faster than that.
>>
>>51740221
You are wrong.
>>
>>51740152
>Still faster than cache misses.
Sometimes, yes. Not all the time.

The more important thing is ease of use. Even if they aren't the fastest solution, they can certainly be the most intuitive for some algorithms.
>>
>>51740237
>100 cache misses are slower than copying 50 MB of RAM
Do you even realize you fucking retarded you are?
>>
File: mods-are-gay.png (52 KB, 613x410) Image search: [Google]
mods-are-gay.png
52 KB, 613x410
>>51740237
>>51740237
>>51740243
>>51740186
>>51740152
>>51740119
>>51740051
>>51739898
>>51739966
>>51739969
>>51740009
Don't respond, it's a mod gone insane

Pic very much related
>>
>>51740265
>>100 cache misses are slower than copying 50 MB of RAM
Yes, this is exactly what I am saying.
Go and learn how modern processors work.
>>
People ITT aren't even shilling for real linked lists. They're shilling for lists of CONTIGUOUS ARRAYS.
>>
>>51740128
you are shit
>>
>>51740282
I sometimes think we should start a programming board on cripplechan. Give each programming language a thread and create a /dpt/ so people can showcase their projects.
>>
>>51740310
If your access pattern is mostly doing reads, then yes, linked lists are retarded over a contiguous array.

If your access pattern, however, is frequent inserts/removes as well as rearranging, then linked lists are superior.
>>
>>51739898
Inserting an element between list[5] and list[4] would mean to move everything from list[5] and after one space. Not with a linked list.

Either way arrays are faster for most tasks. Bjarne said it, don't bother him about it.
>>
>>51740370
>>51739898
https://www.youtube.com/watch?v=YQs6IC-vgmo
>>
>>51740357
>so people can showcase their projects.

That's to imply anyone in here actually does projects.
>>
>>51740368
>If your access pattern, however, is frequent inserts/removes as well as rearranging, then linked lists are superior.
Even then, in most of the cases arrays are faster.
>>
>>51740313
Linked array lists are good for cache optimizations, mang.
>>
>>51740156
How do I sound like a script kiddie?
>>51740152
>Define hacking.
Right now just a general way of getting around limitations put on the user to access and manipulate data you wouldnt be able to normally. Its a vague definition because Im interested in the way any methods that accomplish this work. I know there are no "methods" but the mindset and skills needed are what interest me.
>>
>>b-but infrequent insertions and deletions
>what are gap buffers
>why don't text editors use linked lists
>>
>>51740407
See
>>51739499
>>
>>51740408
>copying n/k elements is faster than changing a pointer
No, just no. God damn it, you're trolling as fuck, aren't you?
>>
>>51740211
>EMacs and ELisp for hacking. E means electronic
Emacs comes from the Editing MACroS
Elisp comes from Editor LISP
>>
>>51740407
>That's to imply anyone in here actually does projects.
I do, but people ignore it either because it's way above their level or because they simply don't give a fuck.
>>
>>51740441
You have to find the element to change the pointer.
>>
>>51740368
It's mainly the size of the elements that matter.
4 byte elements like ints or floats? Arrays are pretty much always faster, including inserting something into the middle of a million length array.
However if each element is say 1K, then linked lists will be faster, especially if you can index via the pointer value because that means you don't need to load that entire 1K for every element you're iterating.
>>
>>51740391

>My graph has disappeared
>>
>>51740479
And again, the cost of that that depends on your access pattern (and structure of the list). Not to mention the number of elements, and if you can make assumptions about the next access so you don't always traverse from start to end but can "save" the current pointer somehow (for example, if I know that after element k is removed, there is a good chance that element k+1...k+l is going to be rearranged).
>>
>>51739048
Das is proper ikt mayne
>>
>>51740368
>If your access pattern, however, is frequent inserts/removes as well as rearranging, then linked lists are superior.
you might as well use weighted trees
>>
Container idea: make the first half an array and the second half a linked list
>>
>>51740546
>And again, the cost of that that depends on your access pattern
And you end up with 99% of the cases being faster in a array.
>>
>>51740507
>especially if you can index via the pointer value because that means you don't need to load that entire 1K for every element you're iterating.
Then it's no longer a linked list, but a lookup table.
>>
>>51740368
gap buffered array
>>
>>51740562
>first half
>half
nah
fixed number maybe
>>
>>51740557
Yes, but that's not the point.
>>
>>51740458
>Elisp comes from Editor LISP
ELisp for Emacs Lisp
https://en.wikipedia.org/wiki/Emacs_Lisp
>>
>>51740568
>99% of the cases
>making assumptions and pulling random numbers out of your ass based on those assumptions
I'm going to stop responding to you now, you're obviously either trolling, stupid or severely autistic (or even all three).
>>
>>51740562
application:
frequent insertion/deletion of elements at the end
infrequent insertion/deletion of elements at the front
fast access to the front

elements from the linked list eventually get promoted to the array
>>
>>51740571
>Then it's no longer a linked list, but a lookup table.
It's an inherit property of a linked list - you have pointer values as additional meta data.
>>
>>51740136

You sound like you have a great deal of curiosity for how shit works; this is a good thing. I'm not sure what all you know, but it would likely behoove you to learn by reading code made by others. I learned a great deal about C and system programming in general by reading the source code to the Ruby and TinyScheme interpreters (and in turn, a lot more about how these languages work under the hood).

If you want to get into reverse engineering -- that is, being able to take an application binary and find out how it works, possibly modifying it -- you're going to need to learn assembly. This is easier done by using the -S option to GCC to output assembly from your C programs, rather than binary. You will also need to have an understanding of your target operating system's syscall interface.

As for the notion of cracking passwords, typically you aren't sending repeated requests to a server to attempt to log in. That would take forever even if they didn't block repeated failed attempts. Instead, you would obtain the password hash from a compromised database, and you would attempt to brute force the password on that.
>>
>>51740640
an indexing array does not make it a linked list
a linked list requires each element to point to the next
>>
>>51740624
Don't talk, if you do not know.
>>
>>51740635
>what are b-trees
>>
Protip: insertions and removals are O(1) in an unordered vector, neglecting the potential cost of a reallocation when it's filled to capacity. And typically, if insertion order is important, you are just using a stack (vector) or queue (ring buffer) anyways.
>>
>>51739019
Pic is love live!
>>
>>51740051
>>51740051
I'm sorry I started this shit.


>linked lists are still retarded though
>>
>>51740668
>binary trees
>access near the front is remotely comparable to a contiguous array

Maybe if you're storing your binary tree in a contiguous array.
>>
>>51740664
>an indexing array does not make it a linked list
Actually it does, it's one way to implement a linked list (and when you use an arena allocator that's pretty much what you get, all nodes allocated from the same block, and then indexed via chained pointers)
>>
>>51740200

That is what I was counting. And after pasting it into Sublime, I found it also had 7 '{' characters and 7 '}' characters.
>>
>>51740720
No, it doesn't. That's not what a linked list is.
>>
File: vector_vs_list.png (46 KB, 2321x1253) Image search: [Google]
vector_vs_list.png
46 KB, 2321x1253
>>51740543
here
>>
>>51740667
I do know, mang, and where there are frequent inserts and removes and few elements to traverse, linked lists are superior to a linear unordered array.

>hurr durr cache lines
1) You falsely assume that data is just a couple of bytes, and not something bigger like a compound type
2) You falsely assume that linear traversal is the only access pattern
3) You falsely assume that every architecture ever has a cache and that cache misses are expensive always, no exception
4) You falsely assume that n/k cache misses is more expensive than copying n/k elements [you still need to traverse and you still forget to take to account that the objects might have a size larger than a full word]
>>
>>51740507
That has nothing to do with linked list vs. array. Having elements that are too big so that you use the cache more than you need is a problem when iterating through both.

Besides, with an array, access through pointer arithmetic is always O(1). So size doesn't make a difference.
>>
>>51740706
>b trees
>binary trees
They're not the same, retard.

https://en.wikipedia.org/wiki/B-tree
>>
>>51740742
Yes it is.
An ordered index array is a linked list because think of what pointers actually are - they are just integers which index into ram which is one big array.
And if you walk an ordered array of indices you are walking a linked list since each subsequent index is your new link.
>>
>>51740788
GAP
BUFFER

B G
U A
F P
F
E
R
>>
>>51740813
> The B-tree is a generalization of a binary search tree in that a node can have more than two children

>actually a btree is just a generalised binary tree, not just a binary true
>most btrees are binary trees
>hurr durr muh shitty response in the face of facts
>muh more than 2 elements
>>
>>51740820
What did I say about making assumptions, retard?

Gap buffer: Effective when inserts and removals are clustered

Linked list: Effective when inserts and removals are sparse/not clustered/random
>>
>>51740788

>You falsely assume that every architecture ever has a cache and that cache misses are expensive always, no exception

Every architecture worth talking about uses cache. The reason is because RAM is fucking expensive to read from compared to the CPU's speed. If you assume cache misses are not always expensive, I daresay you should inform us of where we can acquire this ultra-high speed RAM.
>>
>>51740788
>I'm going to stop responding to you now
Oh, what happened?

>1) You falsely assume that data is just a couple of bytes, and not something bigger like a compound type
I do not assume that

>2) You falsely assume that linear traversal is the only access pattern
It isn't, but you will have to use it sooner or later, or else, using a linked list would be a waste.

>3) You falsely assume that every architecture ever
Stop
I talked only about modern processors, stop this damage control butthurting

>You falsely assume that n/k cache misses is more expensive than copying n/k elements
It is

>and you still forget to take to account that the objects might have a size larger than a full word
They may do, and?
>>
>>51740795
>That has nothing to do with linked list vs. array.
It has everything to do with it.
Shuffling around couple KB elements is actually expensive, and doing a delete of a range of elements for example only requires you to load sizeof(pointer) * N instead of sizeof(pointer) * N * 1024 - polluting your cache with useless cold data (you don't care about the element data).
>>
>>51740820
>failing the crossword text meme
>>
>>51740882
Well, you did only mention indexing.
>>
>>51740881
>It is
5) You assume cache misses, when small sized objects stored in a linked list may very well fit within a cache line
>>
>>51740912
This is not the case one would use linked lists for.
You also forget that malloc may as well give you memory in the other side of the world.
>>
>>51739242
Loop it in a separate thread
>>
>age when you started doing anything programming related

>main language
>>
>>51740951
9 (now 19)
Haskell
>>
>>51740865
>Gap buffer: Effective with insertions and deletions whenever, depending on how the gaps are done
>Linked list: Effective with insertions and deletions but without largely contiguous memory access and guaranteed to charge speed for speed with access patterns you don't use
ftfy

>>51740890
>i cant into wapanese
>>
>>51740937
You are not forced to use malloc.
>>
>>51740992
I am if I use linked lists properly
>>
>>51740881
Cache lines are what? 64 bytes?

What if your object is larger than a page (aka 4 KiB)? You think it's going to matter then whether or not it is in a contiguous array when traversing linearly?
>>
>>51741005
No, you're not. You can have a pre-allocated pool with memory.

Also, see >>51741011
>>
>>51741011
>what if your object is larger than a page

You mean what if you're /accessing/ more than a page. It may as well not be an object if you're accessing a specific member. You just have padding (still linear transversal).
>>
pls rate.
It's this efficient code?
pls forget my pseudocode.

class character
{
List<Animation>();
}
class Animation
{
List<Frame>();
}
class Frame
{
List <Hitbox>();
}
class Hitbox
{
Rectangle rect;
//other hitbox data such as damage type, damage number and so on
}


Does this data structure has a name?
It's it a tree?
>>
File: 1449441210034.png (158 KB, 310x364) Image search: [Google]
1449441210034.png
158 KB, 310x364
>>51741029
You forgot the word properly.
Also, this is what malloc does.

>>51741011
>Cache lines are what? 64 bytes?
>What if your object is larger than a page (aka 4 KiB)?
>>
>>51741046
>You mean what if you're /accessing/ more than a page
Yes, thank you for that correction. You are of course correct. But yea, lets say the offset of the member you are accessing is so large it always causes a cache miss.
>>
>>51740188
Second
func calculateSurfaceAreaAndSmallestSide(length length: Int, width: Int, height: Int) -> (Int, Int) {
let sa = 2*length*width + 2*width*height + 2*height*length
let smallestSide = min(length*width, width*height , height*length)

return (sa, smallestSide)
}

func solveSecondDay() -> Int {
let input = getInput().componentsSeparatedByString("\n")
let intInputs = input.map({$0.componentsSeparatedByString("x").map({Int($0)!})})

return intInputs.reduce(0) {cur, new in
let (surfaceArea, smallestArea) = calculateSurfaceAreaAndSmallestSide(length: new[0], width: new[1], height: new[2])

return cur + surfaceArea + smallestArea
}
}
>>
>>51740136
http://www.reddit.com/r/netsec/wiki/start
http://www.opensecuritytraining.info/Training.html
>>
Got an interview coming up, how do I ace it?
>>
>>51741072
I don't see how a linked list would benefit you in that case.
>>
>>51741053
>Java
No, it's not efficient. Cut your losses by using ArrayLists, but beyond that, in Java, you can't do much better.
>>
>>51741059
>"You forgot the word properly."
muh no true scotsman

>Also, this is what malloc does.
Yes, which would mean that for very small elements and very small lists, you might very well get your entire linked list within a cache line.

Also, >>51740882
This

Copying and shuffling is expensive, you end up invalidating a lot of stuff.
>>
>>51741104
Bring a gun.
>>
>>51739508
Wtf man, why are you dropping these jewls(the artwork) here? Please source.
>>
>>51740188
/* day 1.1 */

#include <iostream>
#include <fstream>

int main()
{
char ch;
int level = 0;
std::fstream fin("parens.txt", std::fstream::in);
while(fin >> ch)
{
level -= (ch - '(') * 2 - 1;
}
std::cout << level;

return 0;
}
/* day 1.2 */

#include <iostream>
#include <fstream>

int main()
{
char ch;
int level = 0;
int pos = 0;
std::fstream fin("parens.txt", std::fstream::in);
while(fin >> ch && level > -1)
{
level -= (ch - '(') * 2 - 1;
pos++;
}
std::cout << pos;

return 0;
}
>>
>import Control.Arrow ((&&&))

Haskellfags will defend this.
>>
>>51741126
I'm too retarded to use anything else.

I though I was clever by using nested classes with lists.

;u;
>>
>>51741164
Damn right I will. It's a very useful combinator.

>>51741168
It's not really clever, it's a pretty straightforward implementation. I'm just saying that it's inefficient because of Java and you can't really do anything about that.
>>
>>51741194
>le java slow may may
>uses haskell

let me guess

you're either still in uni or you're a NEET
>>
>>51741221
I just answered his question. I never implied that Haskell is more efficient or even that Java's inefficiencies are bad.

>Javafags will be THIS insecure
>>
>>51741221
b-but lazy evaluation
having to apply 50 functions every time i access an element will improve performance
>>
What does this do, exactly?
I'm not familiar with bitwise operations.
    while (num)
{
if (num & 1)
ones++;
num >>= 1;
}
>>
>>51741131
>muh no true scotsman
Nice meme
Linked lists do have some very rare uses, but this is a improper one.

>you might very well get your entire linked list within a cache line.
You would allocate other objects in the mean time. Or else there is no point on using linked lists.

Copying is not expensive, not as long as you stay in cache.
>>
>>51741282
>Copying is not expensive, not as long as you stay in cache.
>not as long as you stay in cache.
So your cache is 500 MB? Please post that CPU.
>>
>>51741259
it counts the number of 1 bits in num
>>
>>51741259
It's called a bitshift. I forget if that's right or left, but the concept is
00010 shift 1 = 00100 or 00001
But googling 'Bitshift' will get you good help.
>>
>>51741259
counts the number of set (1) bits in a number

num & 1
bitwise num AND 1 - used for sign of num

num >>= 1
bitwise num SHR 1 - shift the bits to the right by 1

what this does to the binary number is effectively this:
num = 11011
ones = 0;
num & 1 = true; ones++ (1);
num >>= 1 (1101);
num & 1 = true; ones++ (2);
num >>= 1 (110);
num & 1 = false;
num >>= 1 (11);
num & 1 = true; ones++ (3);
num >>= 1 (1);
num & 1 = true; ones++ (4);
num >>= 1 (0);
(bool) num is now false, loop terminated
>>
>>51741076
I feel this could be cleaner but meh.
#!/bin/python2
from operator import add, mul
import functools

with open("aoc-02.txt") as f:
content = f.readlines();

sum = 0
for line in list([i for i in map(int, line.split('x'))] for line in content):
sum += 2 * ( reduce(add, line ) - max(line)) + reduce(mul, line)
print sum
>>
>>51741259
It's a 1337 h4x0r way of saying this:
while(num) {
// is num odd?
if(num % 2)
ones++;
num /= 2;
}


And it does what >>51741314 said.
>>
>>51739768
What the fuck, I can't get the first one.

int main(int argc, char *argv[])
{
int acc;
acc = 0;
char tmp;
while(read(0, &tmp, 1))
if(tmp == '(')
acc++;
else if (tmp == ')')
acc--;
printf("%d\n", acc);
}

Am I a retard ?
I get -615 with http://pastebin.com/ipTwYW8r but it still won't accept it.
>>
>>51740951

16
Ruby, C.
>>
I'm starting to really understand python, Should I start with C++ or wait until I've mastered python?
>>
>>51741259
>while number is not 0
>check if the first byte is set
>increase ones by one
>right shift by one (trunacate the first byte)
>>
>>51741337
*num AND 1 is **normally** used for sign of num
in this case it's checking if the LSB (the number "on the right" - most of the time) is 1
Shifting moves the next number into position
>>
>>51741354
>mastered python
After that, master Scratch and Game Maker. Then you can move onto a real language like Lego Mindstorms.
>>
The same thing we work on every day.

Design by committee.
>>
>>51739594
break
>>
>>51740951
9
C
>>
Does anyone have the 99 programming challenges image?
>>
>>51741367
The sign bit is usually the MSB. The LSB determines whether the number is even (0) or odd (1).
>>
>>51741420
8 (if basic and batch don't count, 14)
C++
>>
>>51741431
Sorry, I didn't mean sign I meant parity/even/odd lol
>>
>>51740951
16
Java (it'd be C if it weren't for the god fucking awful string api)
>>
File: 1444382718611.png (305 KB, 1920x1080) Image search: [Google]
1444382718611.png
305 KB, 1920x1080
>>51741421
lrn2 search the archive
>>
Why do you use malloc instead of calloc?

When using malloc(), watch out for signed integer and size_t overflow especially when there is multiplication in the size argument.
Signed integer overflow will cause undefined behavior which compilers typically handle by wrapping back around to negative numbers. Depending on the input, this can result in allocating more or less memory than intended.
An unsigned overflow has defined behavior which will wrap back around and return less memory than intended.
A signed or unsigned integer overflow is a security risk if less memory is returned than intended. Subsequent code may corrupt the heap by writing beyond the memory that was allocated. An attacker may be able to leverage this heap corruption to execute arbitrary code.
Consider using calloc() or reallocarray() instead of using multiplication in malloc() and realloc() to avoid these problems /g/.
>>
>>51741459
>Signed integer overflow
size_t is not signed.
>>
>>51741350
I have long ago stopped caring about C's abysmal file handling functions and features.
May God help you.
>>
>>51741451
>search the archive
Didn't it eat shit some weeks ago and lost everything?
>>
>>51741459
Calloc zero initializes
It's slower
>>
>>51741459
>C has either malloc() which is more susceptible to size overflows
>or calloc() which fucking zero-initializes
>>
>>51741475
>C's abysmal file handling functions
What is wrong with it?
>>
>>51741475
I even tried the solutions posted in this thread and it still fails.

Ruby's got -616 but still didn't work.
>>
>>51741350
>Getting stuck on the first one.
You're not gonna make it.
>>
So let me get this straight, In order to get Visual Studio Ultimate from only 40% of the feature set of Eclipse to a barely usable 60%, I have to install Visual Assist, which costs $100 and contains features so basic that it feels laughable that Visual Studio doesn't come with them.

Is that what Microsoft is doing now, taking the EA business model?

> Whole tomato software make 'tabbed browsing' mode for Visual Studio Code, only $100
>>
>>51741459
What if I want to multiply with 3 values?
Calloc is like "fuck you, only 2 values you get"
>>
>>51741504
did you say the file directly or copy and paste?
>>
>>51741282
>Copying is not expensive, not as long as you stay in cache.
You also know what's less expensive, as long as you stay in cache? Modifying pointers.

>muh linear traversel
Your entire linked list can be loaded into cache.
>>
>>51741514
What features are you looking for that are missing from VS ultimate?
>>
>>51741514
Why did you buy Visual Studio?
What is the point of visualassist?
What features are you missing from eclipse?
>>
>>51741509
Can you just say what's wrong with mine, it gives the same result as >>51741156, and is off by one to >>51740188 which is still wrong.

>>51741521
I copy pasted in the terminal.
Used a file for the two solutions I quoted earlier. They are still wrong.
>>
>>51740951
around 14 i think.
C, ASM(only lately has asm been a main language)
>>
>>51741504
ctrl+f ( and ) in the browser gives 3640 and 3360 search results respectively, so -616 and -615 are obviously wrong.
>>
what would be a good language for someone doesnt know anything programming related and is interested in game and app development ? i have a few languages in mind but dont know with which one or with which programs to start
>>
>>51741459
If you're overflowing size_t in an allocation you have bigger problems.
>>
>>51741530
We talked about it.
>>
>>51741551
>game and app development
C# or Java
>>
>>51741541
Are you on the first or second star for day one?
Did you get the file each time you tried or use the same file each time?
>>
>>51741548
-20 didn't work either.

>>51741578
First.
They were the same file every time.
>>
>>51741562
Yes, and your assumption is basically "hurr durr if it fits in the cache you're not supposed to use a linked list", which is horribly wrong because linked lists are pretty much useless, unless the entire list fits into the cache.

Please calm your autism.
>>
>>51741339
Third day, actually got it right the first try which was surprising.

enum Direction : String {
case North = "^"
case South = "v"
case East = ">"
case West = "<"
}

let inside = [Int](count: 10_000, repeatedValue: 0)
var grid = [[Int]](count: 10_000, repeatedValue: inside)
var currently = (x: 5_000, y: 5_000)

func givePresent() {
grid[currently.x][currently.y] = 1
}

func solveThirdDay() -> Int {
givePresent()
for direction in input3.characters {
switch Direction(rawValue: String(direction))! {
case .North:
currently = (currently.x, currently.y + 1)
case .South:
currently = (currently.x, currently.y - 1)
case .East:
currently = (currently.x + 1, currently.y)
case .West:
currently = (currently.x - 1, currently.y)
}

givePresent()
}

var numPresents = 0

for y in 0..<grid.count {
for x in 0..<grid[y].count {
numPresents += grid[x][y]
}
}

return numPresents
}
>>
>C# 6.0 and the .NET 4.6 Framework
>1625 pages

Is... is this the only way?
>>
>>51741588
>-20
wut?
>>
>>51739265
Figured it out. need to define my own main method which calls yyparse explicitly. To those in the future with my problem: don't compile with -ly; define your own main and yyerror methods
>>
>>51741551
Android apps are written in Java, so that would be a good first language to learn. Java is widely used, easy to learn, and despite what /g/ says it's a good language as well.

If you're interested in making iOS apps you'll have to learn Objective-C or Swift.
>>
>>51741588
try giving the opposite of the value you find. So 20 instead of -20 and try getting the file each time you get an answer wrong. I don't know if it changes or not.
>>
No clue what's wrong with your solution, but this one is correct.

import std.stdio: writeln;
import std.conv: to;
import std.file: read;

const string pfile = "input";

int main(string[] argv)
{
string contents = to!string(read(pfile));
int floor = 0;
bool basement_entered = false;
uint basement_enter_time = 0;

foreach(c; contents)
{
if (!basement_entered)
++basement_enter_time;

switch(c)
{
case '(':
++floor;
break;

case ')':
--floor;
if (floor < 0)
basement_entered = true;
break;

default:
}
}

if (!basement_entered)
writeln("Santa didn't go into the basement");
else
writeln("Santa entered the basement at character position ", basement_enter_time);

writeln("Final floor: ", floor);
return 0;
}
>>
Anyone know how I can make an HTTP call for the advent of code input?

When I make a get request it asks me to log in.
>>
>>51741590
... what?
>>
>>51741504

Now, I used a file that was provided on the installgentoo paste the other day, and my output was this:

Reached basement at position: 1782
Final floor: 232
>>
>>51741608
Thank you, i really appriciate it
>>
>>51741628
Or how about you just fucking log in with a fake account, you fucking autist.
>>
>>51741651
i did log in, i'm saying that i'm too lazy to copy the input for each problem. has anyone successfully logged in through HTTP requests in their code?
>>
>>51741599
I planned on doing it that way but didn't want to have a freaking huge array. I think I'll use a set.
>>
>>51741504
>>51741640
Also there are different input files and numbers for different people. My program (>>51741627) spits out the correct answer which (for my input file) is:
Santa entered the basement at character position 1771
Final floor: 138
>>
Coroutines are such an awesome thing. Does your language support coroutines?
Thread replies: 255
Thread images: 23

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.