/ALGO/

Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /sci/ - Science & Math

You are currently reading a thread in /sci/ - Science & Math

Thread images: 25

Anonymous

/ALGO/ 2016-01-14 21:05:53 Post No. 7783763

[Report] Image search: [iqdb] [SauceNao] [Google]

/ALGO/ 2016-01-14 21:05:53 Post No. 7783763

[Report] Image search: [iqdb] [SauceNao] [Google]

Mods are napping. Post algorithms you've programmed.

More languages the better.

>>

Why would the mods care about algorithms?

>>

Starting off very simple, GCD of two numbers.

Euclid method.

Math enthusiasts welcome, post some hardcore algorithms.

Programming enthusiasts welcome, post some hardcore algorithmic code.

>>

Still keeping it simple, square root function, more python jargon however.

Newtonian method if I'm not mistaken.

The conditional statements [if statements] are there just for error handling, and do not really play a part into the algorithm.

>>

Another simple one: hyperexponentiation, but we're only interested in the last 8 digits of the result (for a ProjectEuler problem) so we do everything mod 10^8.

>>

>>7783772

Euclid method is really succinct in stack languages:

: gcd begin dup while tuck mod repeat drop ;

also, daily reminder about RosettaCode.

>>

>>7783861

Holy shit RosettaCode is amazing, can't believe I just found out about it.

>>

>>7783792

Nah that's not Newton's method.

>>

>>7783763

cba to post it but I programmed the minimax with alpha beta pruning and lookup tables in python for an AI project.

>>

When I was learning recursion theory I made a program that output its own syntax.

Try to do that.

>>

>>7783765

Lurk more faggot

>>

>>7783928

#!/bin/bash

cat $0

>>

>>

>>7783960

I was under the impression that technology is a sub-category of science.

Nonetheless, programming algorithms can be oh so tricky, and I'm sure that /g/ isn't quite on the same mathematics level as /sci/.

>>

>>7783928

Those programs are called Quines, if by syntax you mean source code.

>>

>>7783974

>Nonetheless, programming algorithms can be oh so tricky, and I'm sure that /g/ isn't quite on the same mathematics level as /sci/.

/g/ reporting in, I did what we can do best, program fizzbuzz

>>

>>7784019

I've also written a really shitty perceptron algorithm implementation in haskell.

>>

>>7784019

>program fizzbuzz

i hate this meme

>>

>>7783974

No, you are monkeys. GET THE FUCK OUT!

>>

>>7784069

Found the guy who tried programming and couldn't.

But seriously, this is /b/ level shit-posting.

Contributing to the conversation with a less than advanced attempt at genetic algorithms.

Program starts out as a random string, and through several generations [reiterations], the string is updated to eventually display 'Hello World'.

Running this program yields different results [# of total generations] every time [attributed to import random], and its quite interesting to see even at a basic stage what python can accomplish in terms of genetic algos.

>>

>>7784141

Having global variables with the same names add local variables will cause you problems. Shit, having global variables themselves will cause problems.

>>

>>7783763

(format t "~{~{~:[~;Fizz~]~:[~;Buzz~]~:[~*~;~d~]~}~%~}"

(loop as n from 1 to 100

as f = (zerop (mod n 3))

as b = (zerop (mod n 5))

collect (list f b (not (or f b)) n)))

>>

Latest "algorithm" I wrote had to do with determining indirect recursion for a compiler I wrote that included type inference (without needing the "rec" in "let rec").

Not gonna post it here since very "API dependent"

>>

>>7784141

>Found the guy who tried programming and couldn't.

This is what retards seriously believe

>>

>>7783763

>heavy-light decomposition of a tree into non-commutative lazy-propagating segment trees

the memes weren't ever this good

>>

I tried to implement Dijkstra's algorithm for my game @ joeburger.ax.lt/TowerDefense2

>>

Made a program in Java that finds all paths in a directed graph by looking for loops, then finding loops of those loops, and then finding loops of those loops of loops, etc... Of course there could be infinitely many paths, so w/e.

>>

>>7784613

>tried

Dijkstra's easy as fuck, check Competitive Programming by Halim, it has a nice implementation

additionally, dijkstra in a grid? just do bfs

>>

>>7784621

why don't you find all strongly connected components first instead of doing something blind like this? see tarjan's / kosaraju's algorithm

>>

>>7783763

Fuck it

>>

>>7783928

What now?

>>

>>7784624

I say tried because I'm not sure that what I ended up with is actually Djikstra's. See line 148

I'll google 'bfs'.

Yeah, I'm pretty sure that's what I did.

>>

>>7784629

Holy shit, I was started to actually get pissed at how stupid this was before I realized I was getting trolled. Good job on the comments, it tricked me into thinking it was a genuine attempt.

>>

>>7784646

>le trolling meme

trolling is so 2007

>>

>>7783928

Can't you just set a reader input stream from the file that you saved and print every line of it?

>>

>>7784663

> 14 lines of code when it could have taken just 4 with trivial simplifications

> "Hey guys, what's the sum of the first n integers? Wait, I know, it's sum(range(0,n+1)), I'm so clever! Good thing I never learned anything in math.

> 15 lines of poorly redacted comments with no punctuation

> Shitty error message and function name

And I'm the one who's trolling...

>>

>>

>>7785570

That's not trolling. THIS is trolling!

>>

If I am interested in computational chemistry, is there any point in learning Fortran?

>>

>>7785757

If someone wrote "(7-(x-7))-1" or "sum(range(0,6))" without trolling, then they have a lot to work on. They're probably self-taught, in which case I don't blame them for not knowing everything, but they should seriously consider taking classes. If they aren't self-taught, then either they didn't study for shit or they're complete morons.

>>

whats the difference between python 2 and python 3

>>

>>7786284

>14

Sorry lad but 4chan is specifically 18 or older

>>>/leave/

>>

>>7783763

My literal implementation of Euler's method.

>>

>>

>>7783772

>not doing it recursively in Haskell

>>

>>7786367

print is a function instead of a statement, and a couple objects became iterators instead of straight lists. that's about it.

>>

>>7783763

Convex Hull!

>>

>>7786473

>weakly typed languages

This never ceases to be a pain in my ass.

>>

An exact TSP solver using the Held-Karp variation of branch-and-bound. Incredibly fast...

>>

>>7784627

I know nothing about graph theory and I had fun just coming up with everything on my own from the bottom up. It was just to waste an afternoon. But hey, now that you pointed me towards some stuff I'll better appreciate simpler ways to solve the same problem and in a way it kinda will make it worth while.

>>

>>7786442

Forgot my image.

>>

>>7785768

Yes, it's almost a certainty that any legacy code (and maybe even some modern code) will be written in Fortran. Moreover Fortran has been optimised over the decades to work and be incredibly efficient with numerical computations and array processing. Also it's not very hard to pick up, so yes there's some point to learning Fortran.

Obviously it has some down sides, it's not very general, so you can do some quick and efficient computations but not much else; in my experience there's (surprisingly for such an old language) not that much useful documentation around.

It's probably worth your time to learn Fortran and Python, then use f2py to join them together.

>tl;dr Yes it'll be worth your time to learn it.

>>

Because java hates unsigned bytes, I had to write pic related, it takes an integer as input and returns the corresponding unsigned little-endian byte array. I needed it in my program to create WAV file headers. Works for positive integers up to 2^16-1. I didn't use short for a reason.

There should exist a more elegant solution I think.

>>

>>7784019

>program fizzbuzz

I don't get it, is it supposed to be hard? Just googled fizzbuzz and wrote the program in less then a minute. It's fucking easy and I only had 1 programming class.

>>

>>7788234

Anecdotally, a surprising number of people who claim to be professional programmers choke on the fizzbuzz question during interviews. There's a lot of unqualified people out there.

>>

>>7788234

It's a /g/ "meme."

>>

>>7786473

>convex hull

>posts inferior 2d algorithm

3d or more or gtfo

>>

File: Bildschirmfoto 2016-01-16 um 23.38.07.png (27 KB, 364x294)
Image search:
[iqdb]
[SauceNao]
[Google]

27 KB, 364x294

bringing the heat

>>

>>7788234

It was an interview question designed to filter out people who can't even program. The person who asked it wrote a blog post complaining about all the candidates who failed.

>>

>>7788234

Could've appended to the string to save on comparisons.

>>

>>7788935

Little bit more complicated than it needed to be senpai.

>>

>>7784019

>stdint

>>

>>7783772

Speaking of which, does anyone know of an extended euclidean algorithm which can solve for x in

[math] a \cong bx \: mod \: y [/math]

Assuming values for a, b, and y are all known.

>>

>>7783928

The first step in learning recursion is to learn recursion.

>>

>>7789034

I know but the way I did it is easier to comprehend.

>>

>>7784019

A classic

>>

>>7784019

why do it that retarded way when

#include <stdio.h>

int main(void) {

for(int i=1;i<101;i++) {

if(i%15 == 0)

printf("FizzBuzz ");

else if(i%5 == 0)

printf("Buzz ");

else if(i%3 == 0)

printf("Fizz ");

else

printf("%d ",i);

}

return 0;

}

is fine

>>

>>7789744

This is why retarded CS majors aren't allowed here.

>Use EEA to get g*b+h*y=1

>g=b^-1 mod y

>>

fast matrix exponentiation for matrices of the shape

a b

b -a

>>

are there any game programmers here :o

>>

I'm writing on a program that will take two greyscale images and search for occurrences of one of them within the other. I've got that working pretty much using correlation. But is there a better way besides correlation that will also let me find occurrences of the small image that have been rotated and/or scaled? I suppose I could scale / rotate the small image and repeat the correlation but that is silly and takes a long time. Using octave by the way.

>>

>>7792657

look up feature extraction, for example SIFT.

Also openCV and dive into the unending rabbit hole of computer vision

>>

>>7792671

Nice, thanks. I was hoping to get around shit like that but I guess you can only get so far with pixel-based algorithms. Any book suggestions?

>>

refinement of a 2 dimensional triangular mesh for a fem implementation

>>7792651

just out of curiousity, what did you need the matrix exponentiation for?

Are you trying to solve linear odes?

Thread images: 25

Thread DB ID: 434584

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.

This is a 4chan archive - all of the shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.

If a post contains personal/copyrighted/illegal content, then use the post's