[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/ALGO/

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 76
Thread images: 25

File: p.png (173KB, 2000x2000px) Image search: [Google]
p.png
173KB, 2000x2000px
Mods are napping. Post algorithms you've programmed.

More languages the better.
>>
Why would the mods care about algorithms?
>>
File: GCD.png (5KB, 341x138px) Image search: [Google]
GCD.png
5KB, 341x138px
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.
>>
File: SQRT.png (13KB, 486x181px) Image search: [Google]
SQRT.png
13KB, 486x181px
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.
>>
File: pb188.png (6KB, 254x352px) Image search: [Google]
pb188.png
6KB, 254x352px
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.
>>
File: image.jpg (140KB, 604x539px) Image search: [Google]
image.jpg
140KB, 604x539px
>>7783765
Lurk more faggot
>>
>>7783928
#!/bin/bash
cat $0
>>
>>7783763
>>>/g/tfo
>>
>>7783928
>>7783890

I'm sure most of /sci/ does have quite of bit of work to do and isn't entirely willing to lend their time.

However, if pictures of these programs can be made available on this Botswanian trading card image forum that would be grand.
>>
>>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.
>>
File: cfizzbuzz.png (39KB, 722x434px) Image search: [Google]
cfizzbuzz.png
39KB, 722x434px
>>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
>>
File: perceptron.png (77KB, 740x488px) Image search: [Google]
perceptron.png
77KB, 740x488px
>>7784019
I've also written a really shitty perceptron algorithm implementation in haskell.
>>
>>7784019
>program fizzbuzz
i hate this meme
>>
File: average programmer.jpg (21KB, 391x400px) Image search: [Google]
average programmer.jpg
21KB, 391x400px
>>7783974
No, you are monkeys. GET THE FUCK OUT!
>>
File: gen_algo.png (24KB, 511x436px) Image search: [Google]
gen_algo.png
24KB, 511x436px
>>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"
>>
File: your future.gif (142KB, 948x543px) Image search: [Google]
your future.gif
142KB, 948x543px
>>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
>>
File: pathfindingForMyGame.png (276KB, 931x1676px) Image search: [Google]
pathfindingForMyGame.png
276KB, 931x1676px
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
>>
File: leadership.png (25KB, 781x476px) Image search: [Google]
leadership.png
25KB, 781x476px
>>7783763
Fuck it
>>
File: print_own_code.png (2KB, 344x112px) Image search: [Google]
print_own_code.png
2KB, 344x112px
>>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...
>>
>>7784676
>>7784631
https://en.m.wikipedia.org/wiki/Quine_(computing)

He should've specified in his post that the program should take no input.
>>
>>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/
>>
File: Euler.png (30KB, 924x700px) Image search: [Google]
Euler.png
30KB, 924x700px
>>7783763
My literal implementation of Euler's method.
>>
>>7786367
1
>>
>>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.
>>
File: basicconstructionconvexhull.png (81KB, 896x550px) Image search: [Google]
basicconstructionconvexhull.png
81KB, 896x550px
>>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.
>>
File: 2016-01-15-212006_211x54_scrot.png (1KB, 211x54px) Image search: [Google]
2016-01-15-212006_211x54_scrot.png
1KB, 211x54px
>>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.
>>
File: inttounsignedbytearray.jpg (27KB, 466x273px) Image search: [Google]
inttounsignedbytearray.jpg
27KB, 466x273px
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.
>>
File: FizzBuzz.jpg (63KB, 1090x434px) Image search: [Google]
FizzBuzz.jpg
63KB, 1090x434px
>>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
>>
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.
>>
File: pi_monte.png (8KB, 268x392px) Image search: [Google]
pi_monte.png
8KB, 268x392px
>>7788935
Little bit more complicated than it needed to be senpai.
>>
File: why.png (670KB, 1200x1152px) Image search: [Google]
why.png
670KB, 1200x1152px
>>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
>>
File: expm.png (15KB, 480x326px) Image search: [Google]
expm.png
15KB, 480x326px
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?
>>
File: mesh refinement.png (21KB, 623x679px) Image search: [Google]
mesh refinement.png
21KB, 623x679px
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?
>>
File: ackerman.png (32KB, 590x330px) Image search: [Google]
ackerman.png
32KB, 590x330px
Thread posts: 76
Thread images: 25


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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 content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.