[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: 17
File: daily programming thread SICP.jpg (211 KB, 612x816) Image search: [Google]
daily programming thread SICP.jpg
211 KB, 612x816
old thread: >>51856207

What are you working on, /g/?
>>
First for C.
>>
A pure functional programming language that is like C with proofs.
>>
D is what C++ should have been
>>
>tfw day 14 AoC

unsigned simulate_objs(Reindeer **objs, unsigned ct, unsigned time)
{
/* simulate objects for time in seconds */
unsigned i, j;
for (i = 0; i < time; i++)
{
for (j = 0; j < ct; j++)
{

}
}
return 0;
}


What now?
>>
>>51862318
Stopping reading at "Functional".
More like dysfunctional. Like your family, which is why you've locked yourself in your basement, self-harming yourself with this memelang.
>>
http://myde.jackhasakeyboard.co/

It half works
>>
First for C#
>>
>>51862385
>I am a programmer :^)
>>
>>51862353
Did a functional programmer kill your parents or something mate?
>>
File: 1310481500822.jpg (36 KB, 805x669) Image search: [Google]
1310481500822.jpg
36 KB, 805x669
>>51862318
>A pure functional programming language that is like C
>>
>>51862294
Am I the only one who thinks proxy tables in Lua are a terrible idea? I'd much rather have __get and __set.
>>
>>51862413
No, and I wouldn't let it kill my paren[keys]ts.
>>
>>51862417
"Like C" in terms of how low level it can go, and what it compiles to. Basically, the only part of C worth retaining.
>>
13th for Haskell is useless garbage
>>
>>51862434
Functional programming doesn't represent how computers work very well.
>>
Go seems nice for networking (and shit for everything else). What's some cool (networking related) application I could code to try that meme out?
>>
>>51862345
I showed you my python reindeer class earlier today lad. I deleted it, but here's the non-class one. It should help with the general algorithm:

from re import search

data=open("Advent14.txt").read().split("\n")

seconds, nums, points, times, distance = 2503, [], [], [], []

for c,i in enumerate(data):
nums.append([])
nums[c]=search("(\d+).+?(\d+).+?(\d+)",i).groups()

points.append(0)
times.append([0,int(nums[c][1]),0])
distance.append(0)

for i in range(seconds):
for i in range(len(data)):
timeType=times[i][0]+1
if times[i][timeType]>0:
times[i][timeType]-=1

if timeType==1:
distance[i]+=int(nums[i][0])

if times[i][timeType]==0:
times[i][0]=1-times[i][0]
times[i][3-timeType]=int(nums[i][3-timeType])

maxD=max(distance)
for i in range(len(data)):
if distance[i]==maxD:
points[i]+=1

print max(distance)
print max(points)
>>
>>51862479
distributed go removal tool
>>
>>51862479
Web scraper.
>>
>>51862479
You don't want to learn Go.
>Lisp could have changed my life, but I ignored it and wrote Go instead. Now I'm several years closer to dying.
– Rob Pike
>>
>>51862448
Sure, why not? The language has no GC. Storage is done with what are essentially just structs and unions. You have to use pointers to implement things like linked lists or trees. Closures are equivalent to objects both in expressive power and implementation. Continuation passing style (functional "assembly") is equivalent to single static assignment form (LLVM).

It isn't some inherent flaw of functional programming that causes most functional languages to operate differently.
>>
>>51862294
 w3m -dump -T text/html http://www.nasdaq.com/symbol/$1/real-time | awk '$1 ~ /\$/ {{print substr($1, 2); exit}}' 
>>
What's a normie proof and easy to parse config file format? I'm thinking of INI files, but I'm open for suggestions.
>>
>>51862493
Great quote! I bet he said that.
>>
>>51862448
The whole point of it is to generate "solutions" to "problems" by making artificial limitations.

Haskell had the I/O "problem" and then they came up with the idea of the IO monad, based on passing the world around and making new copies of the world.
>>
>>51862434
So it's going to be a "pure functional programming language" that lets you directly manipulate all memory with pointers? Good luck with those "proofs"
>>
>>51862436
you can recycle garbage though, haskell is more like nuclear waste
>>
>>51862479
Go is a literal meme language. It's okay at some things, but not best at anything. It has no purpose and will die once the meme-ness wears off.

If you want concurrency, go with Erlang/Elixir. If you just want a general purpose language you may as well go with a mature language such as Java/C#.
>>
>>51862543
There is a formally verified operating system which is free of deadlocks, livelocks, buffer overflows, arithmetic exceptions or use of uninitialised variables and so on you know.
>>
>>51862584
and?
>>
>>51862584
Urbit.
>>
>>51862584
what is the name
>>
Just wrote my own keylogger from scratch.
The only issue is that whenever I hit the return key, tab key, or backspace key and it goes over 50 characters I get something like this in my email
H敬汯ⰠG潯摢祥ⰠG潯搠敶敮楮朠㱲整畲渾†㱲整畲渾�

Here's my code if anyone's interested.
http://pastebin.com/iicmEbu2

http://pastebin.com/iicmEbu2
>>
Go was able to kick off because it's development was backed by google. That's it.
>>
>>51862601
That means you can do proofs even when manipulating memory directly.

>>51862584
seL4

>>51862633
This. If it had been somebodys personal language no-one would have cared.
>>
>>51862559
this guy understands
>>
Does a C with strong typing and type safety exist?
>>
>>51862318
can it average 2 ints and prove it correct?
>>
What should I get for christmas, /g/?
>>
>>51862664
yeah, it is called C
>>
>>51862677
a dragon dildo
>>
>>51862658
>That means you can do proofs even when manipulating memory directly.
does it always mean that though? Or do you need to use certain kinds of languages and certain coding patterns to allow it to be provably safe?
>>
>>51862559
>go with Meme/Meme++
m8...
>>
>>51862677

a gf
>>
>>51862624
My name is not Eugene and I have a Windows machine so that means I'm safe from your keylogger.
>>
>>51862677
gud
>>
>>51862685
two dragon dildos
>>
>>51862584
Formal verification has nothing to do with functional programming in particular. It can be applied to languages that don't have functions (i.e. just loops or labels).
>>
>>51862677
a life
>>
>>51862677
We don't consumerism here.
>>
>>51862608
Urbit is a clean-slate, full-stack redesign of system software. In 25K lines of code, it's a packet protocol, a pure functional language, a deterministic OS, an ACID database, a versioned filesystem, a web server and a global PKI. Urbit runs on a frozen combinator interpreter specified in 200 words; the rest of the stack upgrades itself over its own network.

Architecturally, Urbit is an opaque computing and communication layer above Unix and the Internet. To the user, it's a new decentralized network where you own and control your own general-purpose personal server, or "planet." A planet is not a new way to host your old apps; it's a different experience.
>>
File: 1438300136315.jpg (2 MB, 3664x3688) Image search: [Google]
1438300136315.jpg
2 MB, 3664x3688
>>51862708
Topkek
>>
>>51862708
I'm not trying to get it installed on anyone's machine. I just wanted to see what your thoughts on it were. It's my first script that actually does something more than finding the median, etc.
>>
Django, web2py or Flask?
>>
>>51862776
flask
>>
>>51862776
Django
>>
>>51862772
have you got a script that can average 2 ints?
>>
File: dlang.png (9 KB, 120x91) Image search: [Google]
dlang.png
9 KB, 120x91
What does /dpt/ think of D?
>>
>>51862754
>meme overload
>>
>>51862776
Flask
>>
>>51862608
>requires "jets" written in C to optimize Peano numbers
KEK
>>
>>51862796
It's fucking awesome desu

C++ done right
>>
>>51862772
Now make it an actual keylogger Eugene.
>>
>>51862664
R U S T
>>
>>51862796
yours isn't long enough
>>
>>51862796
How well does it integrate with C?
>>
>>51862795
Yeah.
def average(x,y):
return (x+y)/2


Is that good?
>>
>>51862795
this is the same fag that posts about this every day

you need to get a job or something dude
>>
>>51862865
first good one in a while

for autism purposes:
average=lambda x,y:(x+y)/2


>>51862879
I already have a job in IT lad
>tfw pestering coworkers about finding the average of 2 ints in C
pretty sure I'm going to get fired soon
>>
>>51862831
I will, but first does anyone know why the entire thing ends up being Chinese characters when return, tab, or backspace fall partially on the 50 character limit?

Also, how do I fix that?
>>
>>51862927
The chinese have patented your keylogger, and are warning you of the consequences of sharing it

trust me, I teach chinese
>>
literally what is the point of a lambda if all you are doing is tying it to a name
>>
>>51862927
Sounds like a conversion from ASCII to UTF. They don't mix well together.
>>
>>51862520
http://nakamotoinstitute.org/static/docs/taoup.pdf

"Data file metaformats"

If you show me how your data needs to be arranged I can give you my recommendation.
>>
>>51862962
for cheeky one-liners m8
>>
>>51862962
to make your code less readable

for job security and such
>>
Best book to learn Python? It will be my third language, so something quick and dirty is good.
>>
>>51862673
fail bait
R E K T
E
K
T
>>
>>51863027
>so something quick and dirty
ur nan lmao
>>
>>51863055
Not funny. My nan died in a car accident a week ago.
>>
>>51863081
so quick and really dirty.
>>
>>51862972
Thnx. Looks like I'm going for the 'Unix Textual File Format Conventions' flavor.
>>
>>51863081
sounds like a quick and dirty way to go
>>
>>51863027
Dive into Python 3 is good for confident programmers.
>>
>>51863094
>>51863103
Stop. Seriously, it hurts.
>>
Who /28star/ club here?

>tfw will legitimately compete for the leaderboard on christmas
>>
>>51863133
--her last words
>>
>>51863110
thanks friend, I'll check it out
Do people actually use python 3 by the way? I thought everyone hated it and stuck with python 2.7
>>
>>51863149
Fuck you. I'm reporting this post.
>>
>>51863149
kek
>>
I made a fizz buzz program in C

<code>
#include<stdio.h>

int main() {
int x;
for (x=1; x < 100; x=x+1) {
if (x % 3 == 0 && x % 5 == 0) {
printf("FizzBuzz!\n");
}
else if (x % 3 == 0) {
printf("Fizz!\n");
}
else if (x % 5 == 0) {
printf("Buzz!\n");
}
else {
printf("%d\n",x);
}
}
}
</code>
>>
>>51863234
><code></code>
lad why?
>>
>>51863234
fuck how do you tag code
>>
>>51863234
>x < 100
>>
>>51863282
[] not <>
>>
>>51863153
I only use Python 3. I hate porting anything I write to Python 2.7.
>>
>>51863312
>I only use Python 3
I'm so sorry
>>
>>51863333
Python 3 is better than Python 2, but Haskell is my favorite :^)
>>
>>51863333
nice python 3 quads, lad
>>
File: finished.png (350 KB, 320x386) Image search: [Google]
finished.png
350 KB, 320x386
wewee
>>
>>51863289
#include<stdio.h>

int main() {
int x;
for (x=1; x < 100; x=x+1) {
if (x % 3 == 0 && x % 5 == 0) {
printf("FizzBuzz!\n");
}
else if (x % 3 == 0) {
printf("Fizz!\n");
}
else if (x % 5 == 0) {
printf("Buzz!\n");
}
else {
printf("%d\n",x);
}
}
}

sorry am newfag
>>
>>51862664
No. C++ is much more strongly type-checked than C, but it will still effectively allow to do all the same things C will if you choose to. Both languages assume the developer knows what they are doing. A new C++ core guidelines was recently introduced and if strictly adhered to, will in fact give you perfect type safety.

>>51862684
Lol
>double-nope.jpg
>>
>>51863466
>x=x+1
Make that x++ or ++x for optimal performance.
>>
>>51863466
that only prints up to 99
and
if (x % 3 == 0 && x % 5 == 0) {

can just be
if (x % 15 == 0) {
>>
File: milk.webm (3 MB, 1280x720) Image search: [Google]
milk.webm
3 MB, 1280x720
Ask your beloved programming literate anything.
>>
>>51863597
KILL YOURSELF TETSUMI.
Annoying twat.
>>
>>51863597
how do you average 2 ints in C
>>
>>51862294
>What are you working on, /g/?
Trying to average not just two but many numbers in VB.Net
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num, count As Integer
count = 0
num = 0
While num >= 0 ' here we have to check it that the num is not negative then to start
Dim temp As Integer
temp = InputBox("Please enter number")
If temp < 0 Then
Exit While
End If
count += 1 'this will calculate how many times number added
num += temp
End While
MsgBox("Average is " & (num / count))
End Sub
>>
>>51863597
source?
>>
>>51863619
float c = (float(a)+b)/2
>>
>>51863597
Are you the faggot making those gay traps threads?
Regardless you should kill yourself faggot.
>>
In python, is there an easy way to convert a number to a string of characters. Like what chr() would return, but for each byte in the number.

Like, say I have the number 0x9E9D9C9B9A, I want the string '₧¥£¢Ü'. I can easily get this sort of string when reading a file in binary mode, but I can't figure out a way to convert a number like it.
>>
>>51863734
so just write your number into a file and read it then? problem solved
>>
>>51862479
Go is a one of Google's labor shortage memes meant to make developers fungible.
>>
>>51863633
>more than 2 numbers
absolute madman
>>
>>51862796
If I'm going to bother learning a language with crazy syntax and complicated semantics, why wouldn't I just learn C++?
>>
>>51863734
What encoding is that, that yields
₧¥£¢Ü from 0x9E9D9C9B9A?
Do you have a real example?
>>
>>51863734
Mask and shift.

loop 4 times for a 32 bit number:

c = chr(num & 0xFF)
num >>= 8 (right shift by 8)

That will give you the bytes with least significant byte first, just reverse it if you want the other way:
c = char((num >> 24) & 0xFF)
num <<= 8
>>
I don't get it.
My day 14 AoC solution works perfectly with their example input, but when I try my input, the site tells me I cheated because "you got someone else's answer".
>>
>>51863794
## THANKS LARRY!!!
use List::Util qw(sum);
print (sum(@ARGV) / @ARGV)
>>
>>51863848
>their example input
>my input
Literally what? The input they gave you gives you your answer, you're clearly either using someone else's input or someone else's answer
>>
>>51863892
function average(li) { return li.reduce(function(a,b) { return a + b; }) / li.length; }
>>
Working on designing an implementation of List where add is always done in O(1) time for an assignment. I'm fucking clueless.
>>
>>51863942
linked list
>>
>>51863942
That's just a linked list.
>>
>>51863913
the example on the site that ends at 1000 seconds with Comet winning with 1120 km?
If it gets that correctly, it should be able to get my real input correctly too.
>>
>>51863942
(Java)
>>
>>51863597
>programming literate
what does that even mean? anyone who has read a beginners Python book can consider themselves programming literate
>>
>>51863955
>>51863957
Is get and put also O(1)?
>>
File: tfw.png (980 KB, 960x540) Image search: [Google]
tfw.png
980 KB, 960x540
>Study computer science
>haven't written a line of code all semester
>did write an essay on why I shouldn't exclude the disabled from my projects though
>tfw it's costing me £9,000 a year
>>
>>51863989
No.
>>
>>51863942
Should have specified get/add/put are all O(1)
>>
>>51863958
Then it might be possible that your answer is somehow wrong, but it also matches an answer given from the set of predefined inputs-answers

If not, I have no idea
>>
>>51863989
Retrieval in a linked list is O(n), that is if you want to access it with an index
Insertion is O(1)

http://bigocheatsheet.com/
>>
>>51862776
web2py
>>
>>51863989
'get' and 'put' aren't O(1). Inserting at the beginning only is O(1), otherwise it's O(n).
There is no such list that is O(1) insert and O(1) index.
>>
>>51863999
What shit school do you go to and how can we avoid it?
>>
>>51863819
Yeah, I guess that works.
num = 0x9E9D9C9B9A
numstr = ''
tmp = num
while tmp > 0:
numstr += chr(tmp & 0xFF)
tmp >>= 8
numstr = numstr[::-1] #reverse string
>>
>>51863999
Drop out and self-educate
>>
>>51863999
Daily reminder that cs is not a course in programming. If you wanted a programming course, you should do one.
>>
>>51864011
nothing like that exists

>put
are you sure this is a list and not a map?
>>
>>51864011
>Should have specified get/add/put are all O(1)
The perfect ordered collection.
>>
>>51864011
What the fuck is put?
Also, there is no data structure that can get and add in O(1). A dynamic array can get in O(1) and is extensible, but adding still takes O(n) time.
>>
>>51864051
Not sure that exists in the UK outside of those coding academies.
>>
>>51862664
>Does a C with strong typing and type safety exist?
no, that would destroy the purpose for C to exist. C is a typeless language, even chars are numeric types and strings are just arrays of chars and pointers cast to numeric type. If C were to make choices as to what types are, this would ruin C's ability to be good at systems programming that must be able to cast to arbitrary bits that dont follow any language definition of type, it would also ruin C's ability to be a good language for writing compilers as the type system of a language will bleed into the compiler and influence the language its compiling into
>>
>>51864053
That's what the notes say.
>>
>>51864063
>Also, there is no data structure that can get and add in O(1).
Hash tables are pretty much O(1), and O(1) for all intents and purposes if you have a good hash function
>>
>>51864124
That's wrong though, get is O(n)
Just try it out on paper

Retrieve the 5th element of a linked list.
You will have to walk through the first 4 to find it
>>
>>51864124
Option 1 - That's wrong
Option 2 - The names are just counter-intuitive and they actually mean something other than what they seem to mean, which would also make it be wrong
Option 3 - You're supposed to implement a List as a hash table, which is retarded and counter-intuitive, and yet that would still be wrong because adding (putting) isn't *always* O(1) in hash tables
Option 4 - Whoever wrote that is going to be rich, or at least very, very famous when they disclose what implementation of a list has these characteristics
>>
>get is O(1)
Am I missing something?
>>
>>51864124
What are 'get' and 'put' and 'add' supposed to be anyway? Why doesn't he use standard terminology like insert, index, push (or cons).
>>
>>51862294
>>51862294
>>51862417
>>51863619

Do people hate on C because they're not smart enough to understand it, contain it and/or use it properly? Because that's what it sounds like. I can sympathise though, seeing as this is how a lot of Python plebs feel.
>>
Looking for five programming book suggestions to buy an intermediate-level programmer for Christmas.

What are the /dpt/ reference essentials?
>>
>>51864137
Define 'good hash function'. For a guaranteed O(1) for get, you would need a perfect hash function which always avoids collisions. While this may be possible in some situations, it certainly isn't always. I guess it depends on the problem statement.
>>
>>51864079
http://www.theguardian.com/technology/2013/oct/14/learn-how-to-code
>>
>>51864147
I see what you mean, but perhaps he means get and put can usually be O(1) and add should always be O(1)?

My friend said he modified skip list so it fit the constraints somehow, but it was a very unique solution so I can't just use his.
>>
>>51862294
Hey /g/, how do I refactor the if-statements and the case to be shorter or more eloquent in this program?
#include <stdio.h>
#include <curses.h>
void main(void) {
short x = 0, y = 0;
short mx, my;
int ch;
initscr();
mvprintw(y, x, "O");
noecho();
curs_set(FALSE);

while(1) {
getmaxyx(stdscr, my, mx);
if ( y < 0) y = 0;
else if (y >= my) y = my;
if (x < 0) x = 0;
else if (x >= mx) x = mx;

mvprintw(y, x, "O");
refresh();

switch (ch = getch()) {
case 'A':
case 'w':
y-=1;
break;
case 'B':
case 's':
y+=1;
break;
case 'C':
case 'd':
x+=1;
break;
case 'D':
case 'a':
x-=1;
break;
case 'q':
endwin();
return;
}

erase();
}
endwin();
}
>>
>>51864217
>Do people hate on C because they're not smart enough to understand it

Actually, it hasn't got a lot to do with the language itself. It's that C users are insufferable.
>>
>>51864234
'get' definitely can be O(1) usually.
...If you 'usually' look for the first element.
>>
>>51864221
That's why I said "for all intents and purposes". With a good enough hash function, even if it's not perfect, your buckets will never get all that full, meaning your accesses are pretty much O(1).

>>51864124
I forgot a 5th option in >>51864197
There are other properties to this implementation of a list (e.g. max number of elements that may be added to it) that you're not disclosing
>>
>>51862757
I read that they made a patch for pre Win10 that enables the same Telemetry.

http://www.forbes.com/sites/gordonkelly/2015/08/30/windows-10-spying-on-windows-7-and-windows-8/
>>
>>51864234
The problem is that "get" can mean many things. You can iterate over a list, with a complexity of O(1) per "get". But what's the point then, that's true for almost all data structures.

Usually terms like "search" are used instead.
Searching a list is definitely O(n)
>>
>>51864220
SICP
Tour of C++
Land of Lisp

I'm done.
>>
>>51863283
> >x < 100

>implying that FizzBuzz is necessarily restricted to 1 .. 100.

Fizzbuzz is a child's game that can go arbitrarily high. The maximum number is defined by whoever is asking. Also, formatting must be specified.

1
2
Fizz
4
Buzz

or

1, 2, Fizz, 4, Buzz, Fizz

or

1 2 fizz 4 buzz fizz

or 12fizz4Buzzfizz

Whatever.
>>
>>51864284

get is almost certainly O(n). In fact, it's the word that Java uses for its lists, and it takes an index.
>>
>>51864256
In what ways are they insufferable?

Total newfag here. I'm learning C currently to get a basic knowledge of lower level stuff but I'm keeping my options open. I intend not to become "insufferable".
>>
>>51864307
The FizzBuzz that /g/ practices is from [1,100], not [1,100) is what he's implying.
>>
>>51863027
I was in the same position as you and just ended up using python docs and programming problems from foo.bar/codeeval/euler/etc

if you're on your third language, all you really need to know is syntax.
>>
>>51864349
>In what ways are they insufferable?

Browse this thread for a while and you'll see.

C is a fine language. Doesn't have quite the same productivity as more modern languages, but there aren't that many things wrong with it.

Just don't fall into the "OH WOW U DON'T USE C FUK U!" trap.
>>
>>51864307
It's generally from 1 to 100 inclusive though, I'm just nitpicking
>>
Some anon posted
local s = arg[1] and table.concat(arg, " "):upper() or "LONDON"

local function q(n)
return (" "):rep(n)
end

local sl = #s
local sr = s:reverse()

print(s:sub(1, 1)..q(sl-2)..sr)
for i = 2, sl-1 do
print(s:sub(i, i)..q(sl-2)..sr:sub(i, i))
end
print(sr..s:sub(2))
for i = 2, sl-1 do
print(q(sl-1)..s:sub(i, i)..q(sl-2)..sr:sub(i, i))
end
print(s..q(sl-2)..s:sub(1, 1))

to make
M   SEMEM
E E
M M
E E
SEMEMEMES
E E
M M
E E
MEMES M

a few threads ago, so I made a Python version
def swastext(s):
print ("\n".join([(s[0] + " " * (len(s)-2) + s[::-1]) if i == 0 else s[i+1] + " " * (len(s)-2) + s[::-1][i+1] if i < (len(s)-1) else s[::-1]+s[1:] if i == (len(s) - 1) else " " * (len(s)-1) + s[i-len(s)] + " " * (len(s)-2) + s[::-1][i-len(s)] if i != (2 * len(s) - 2) else (s[0] + " " * (len(s)-2) + s[::-1])[::-1] for i in range(2 * len(s) - 1)]))
>>
>>51864372
>C is a fine language
Many tasks are difficult to implement in C, for instance averaging two ints.
>>
Currently Im working on building a handheld n64 emulator but I can't find a screen thats a good size and doesnt break the bank. Anyone know where I can get a cheap simple display?
>>
>>51864386
Have you ever tried adding two ints together in C? Literally impossible.
>>
>>51864386
>Many tasks are difficult to implement in C

I know, that's why I said it doesn't have the same level of productivity as many modern languages, which is true.

And for embedded stuff that doesn't yet support C++ (or is unable to), it's pretty much standard
>>
>>51864399
Yes it requires external libraries
>>
>>51863848
I had the same problem then I realized I'm a dumbass because when I was going through the seconds I didn't immedietely stop at the end mark but instead I still kept adding (stamina * speed), instead of doing math.min(stamina, seconds - i) * speed.
>>
>>51864399
>what is integer division duuuuuh
python pleb, pls go
>>
>>51864386
>difficult to implement in C, for instance averaging two ints.
int average(a, b) {
return (a+b) / 2;
}
>>
>>51864372
Does C still have vital uses in the modern era? I'm not asking if it's "essential" but is it still an important language to have an extensive knowledge of?

I'm learning it particularly due to the breadth of information that comes with it, providing a solid foundation for other languages and concepts. I don't believe it's superior or inferior as such. Also, I'm a very verbose and detailed individual so being able to understand every fragment of things is important to me; which is something that C seems to accommodate.

And don't worry, I won't fall into that trap. Being a newfag, I'm not exactly in a position to have an opinion on things.
>>
>>51864437
>result is an integer
Dropped.
>>
>>51864446
>Does C still have vital uses in the modern era?

See:
>>51864412
>for embedded stuff

Thanks to this faggy Internet of Things, it's everywhere.

It's probably in your god damned toaster.
>>
>>51864437
I'm a newfag and I'm learning C but I can still see that you're taking the bait, friend.
>>
>>51864475
>>51864437
Sorry, I mean, it fails with
1073741824
which is a valid signed int.
>>
>>51864457
So bread is a variable argument and a toaster is a function that returns toast?
>>
>>51864454
Result was never specified.
float average(a, b) {
return (float)(a+b) / 2;
}

>>51864471
I have nothing better to do right now, anon.

>>51864475
>>51864493
It can be casted. Actually, this may be better suited for a macro.
>>
>>51863942
Might need to make my own thread for this..
>>
>>51864514
Shit, I forgot to end the code tag.
>>
>>51864514
The result was specified as the average of two integers.
The code of
>>51864437
int average(a, b) {
return (a+b) / 2;
}

does not calculate the average of two integers.

Try it with
printf("%d\n", average(1073741824, 1073741824);

Wrong result
>>
>>51864220
Anything that NoStarch sells and looks difficult. (You don't have to buy it from them, but if you do, you'll get a coupon and an anime post card.)
>>
>>51864533

Look, don't worry about the presentation. It's wrong.
>>
>>51864514
>>51864534
test
test

>>
>>51864551
test
test

test

test
>>
>>51864575
test
testtest
>>
>>51864575
apparently it can't go deeper
>>
>>51864493
>>51864514
>>51864534
>>51864542
Alright, I've fixed it to handle
1073741824
.
 float average(int a, int b) {
return (float)((long)a + (long)b) / 2;
}
>>
>>51864625
Macro version.
#define avg(a, b) (float)((long)a+(long)b)/2
>>
Hey, can anyone help me write a program to solve the quadratic formula?
I have it kinda working right now but it's spitting out wrong answers and I don't know why. Here's my code:
?→A:?→B:?→C◢
(-b+(b^2)√(4AC))÷(2A)◢
(-b-(b^2)√(4AC))÷(2A)

Putting in 3,4, and 1 should give me -1 and -0.3repeating, but instead it gives me 1, 8.571, and-9.904. I have no idea why its returning three values or why none of them are right. What am I doing wrong here?
>>
>>51864625
meanwhile in python
average = lambda x, y: (float(x)+y)/2
>>
>>51864709
>?→A:?→B:?→C◢
>(-b+(b^2)√(4AC))÷(2A)◢
>(-b-(b^2)√(4AC))÷(2A)

(-b+(b^2)√((4AC) ÷(2A))

Your parenthesis around the square root are non-existant; the square root needs to enclose 4AC ÷ 2A. I'll test this on my casio calculator and make sure, though
>>
>>51864625
Now average two longs :^)
>>
>>51864709
>quadratic formula
underageb&
>>
>>51864745
>the square root needs to enclose 4AC ÷ 2A
erm
https://en.wikipedia.org/wiki/Quadratic_equation
>>
>>51864709
What language is that?
>>
Is there any random programming challenge websites like the /dpt/ roll?
>>
>>51864775
Oh fuck, it's been so long since I've used the quadratic equation, my bad.
(-b + √((b^2) + (4AC))) ÷ (2A)


>>51864811
Casio BASIC
>>
I wrote an O(1) sorting algorithm in Python. It only supports lists up to 15000 items though.

There's one problem with it however: I seem to end up with lots of extra 1's. Do you know how to remove these without changing the complexity of the algorithm?

def bigOhOneSort(p):
p+=[1]*(15000-len(p))
return sorted(p)
>>
>>51864386
(a>>1) + (b>>1) + (a&b&1)
>>
>>51864746
stand next to me
>>
>>51864817
I recommend topcoder.
Some bretti challenging problems.
>>
>>51864832
>O(1) sorting
what
>>
>>51864817
https://www.codingame.com/
>>
>>51864862
The complexity doesn't change as the problem gets larger. Though only up to 15000 in this case.
>>
There's only one O(1) sorting algorithm, and that's mine.
def sort(lst):
return lst # our world is dictated by capitalism and corruption and you seek order? the thing you call 'chaos' is the only real order since that's nature
>>
Can an infinitely skilled programmer write infinitely fast code?
>>
>>51864834
neat
>>
File: 1327948738062.png (220 KB, 518x644) Image search: [Google]
1327948738062.png
220 KB, 518x644
Been struggling with binary tree algorithms problem for the last few days and close to just giving up after trying many different solutions to a part of it that involves writing a method to get an index from the left of the tree so 0 would be far left node, and size-1 would be far right node.

End up deciding to try and write it differently, so I start writing this method while trying to work through it whilst looking at an image of a binary tree, but give up because recursion hurts my head and just hash the method together to get it to compile and then start fixing the inevitable errors it will throw

>mfw the method I just hashed together mostly by guessing works perfectly first time and I have no idea why
>>
>>51864834
That's patented by Samsung
>>
>>51864907
Only on infinitely quick systems
>>
>>51864903
Your first mistake was using python. Your second mistake was being a worse coder than me.
function f(x)
return x
end

Not only is this an extremely efficient O(1) sorting algorithm, but this function also checks the value of a boolean expression and then returns that value! I am truly a programming genius.
>>
>>51864709
>>51864825
Alright, after butchering this two times, I got it right.
(-b + √(b^2 - 4AC)) ÷ (2A)
>>
>>51864291
>>51864549

thanks for the suggestions, I have SICP, Tour Of C++ and Think Complexity so far. Land Of Lisp looks good but has a lot of adult content (he's 11)

Also added the NoStarch press Make a Game In HTML5 book just for funs
>>
>>51864709

I'm not going to do your homework for you, but I'll give you equivalent python code as a hint.

def quadratic(a,b,c):
return ((-b + (b**2 - 4*a*c)**.5)/(2*a),(-b - (b**2 - 4*a*c)**.5)/(2*a))
>>>quadratic(3,4,1)
>>>(-0.3333333333333333, -1.0)
>>
>>51864958
Yeah I figured out that I actually typed it in totally wrong the first time and then just copied for the second line.
Now it works great and I can start cheating on all my tests. Thanks for your help!
>>
>>51864892
What you are saying is literally impossible

provide source
>>
>>51864979
I did
>>51864832
>>
>>51864962
I'm aware of how it works. I've made 'solving the quadratic formula' kind of my goto toy program when I want to get into a new language. So far I've done it in C++, C#, Haskell, F#, Lua, and now Casio Basic. One of these days I'll move up to x86asm or maybe Go.
>>
>>51864991
you do realize that sorted(p) isn't O(1), right?
>>
>>51864991
I don't write python, so I'm going to presume sorted is part of its stdlib and you were just making a funny joke
>>
>>51865006
What's the point? The only thing you get to practice is math operators and they are essentially the same in every language.
>>
>>51864838
>>51864875
Thanks
>>
>>51864832
>calls someone elses code to do all the work
>says "i made a miracle function"
python coders in a nutshell
>>
>>51865019
Read the line above?
>>
>>51865025
I'm bored and like programming. Not really much more to it.
>>
>>51865037
sorted()
is O(n lg n) though. I changed it to be constant with the line above it.
>>
>>51864355

Irrelevant.

>>51864383

So was I, but you're still wrong.
>>
>>51864927
Show me one case where they have successfully defended this patent.
>>
>>51865041
so you append [1] to the list to make it 15000 items long, and then call the python sorted function which is O(n log n)
adding more items to a list doesn't magically reduce the time complexity, you're a disgrase
>>
>>51865059
That's not how O works. If you have a O(n^3) algorithm and only feed it problems with n = 1, that doesn't magically make it O(1). The algorithm is the exact same.
>>
>>51865088
If we keep the length (n) constant O(n lg n) is a constant. I assume you have multiplied constants and calculated logarithms before?
>>
>>51864927
Is that not just for their one cycle hardware version?
https://www.google.com/patents/US6007232
>>
>>51865101
I transfer the problem so it is constant. Lots of algorithms start by sorting for instance to do it faster.
>>
>>51865126

Brilliant trolling or utterly retarded.
>>
>>51864837
Great reply.
>>
Making a super retarded FizzBuzz

#include <stdio.h>

int count_digits(int i)
{
int count = 0;

do
{
count++;
i = i / 10;
} while (i != 0);

return count;
}

// I don't have itoa or to_string, so I'm rolling my own.
// Caller is responsible for having the necessary buffer length.
char *itoa(int i, char *buffer)
{
int digits = count_digits(i);
for (int d = digits - 1; d >= 0; d--)
{
buffer[d] = i % 10 + '0';
i = i / 10;
}
return buffer;
}

int main(void)
{
char s[4] = "";

for (int i = 1; i <= 100; i++)
{
printf("%s\n",
i % 15?
i % 3?
i % 5?
itoa(i, s) :
"Buzz" :
"Fizz" :
"FizzBuzz"
);
}

return 0;
}


Also, I just noticed a nice fat bug in my itoa that doesn't matter for this program. :-)
>>
File: 2015-12-14_22-44-39_.webm (377 KB, 342x318) Image search: [Google]
2015-12-14_22-44-39_.webm
377 KB, 342x318
how do I randomly generate more advanced memes?
>>
>>51865146
your argumentation is flawed.
O notation examines the asymptotic growth of a function. if you only look at one value of your function then yes it's always the same, but that's not how algorithm analysis works. it looks at the entire function and thus you can't use your silly 'but if i keep n = 15000 then the runtime is constant!!!' argument
>>
>>51865126
import random
import time
def bigOhOneSort(p):
p+=[1]*(15000-len(p))
return sorted(p)

for n in range(1,4):
proof = [random.randint(1,15000) for i in range(15*n**10) ]
start = time.time()
bigOhOneSort(proof)
print time.time()-start


I don't know about you, but I'm getting
0.00004
0.005
0.4

it's not constant
>>
>>51865215
Make a genetic algorithm and let it post the memes on 4chan
As the fitness function use the number of replies your post gets, or how often it is reposted
>>
I'm going to simplify average two ints for everyone here. It won't get simpler than this.

1. If both numbers are even, do (a/2) + (b/2)
2. If one is odd, and one is even: (a/2) + (b/2) + 0.5
3. If both are odd: (a/2) + (b/2) + 1
>>
>>51865215
>>51865234
A genetic algorithm alone is too stupid, connect it to a neural network for maximum shitposting.
>>
>>51865216
What do you suppose we have n mean if not the size of input data?
>>
>>51864959
Don't understand why people recommend land of lisp.
The book is shit, it does not teach the language and it's not good book if you want to make a game.
If you want to give the 11 year old kid "easy" programming related book give him the little schemer.
It teaches the basics of scheme/lisp and recursion.
>>
>>51865255
top zoz
>>
>>51865262
i never said it's not the size of input data, all i said is you can't magically limit n to get a different runtime. sorted() is O(n) regardless of whether you always feed it the same shit or not.
Thread replies: 255
Thread images: 17

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.