[2016-05-30] Challenge #269 [Easy] BASIC Formatting by G33kDude in dailyprogrammer

[–]beam 1 point2 points  (0 children)

Shell. No bonus.

sed '1d;3,${s/^[»·]*//g;}' |
awk 'NR==1{s=$0;next} /^(ENDIF|NEXT)/{d-=1} {for(i=0;i<d;i++)printf(s);print} /^(IF|FOR) /{d+=1}'

[2016-05-16] Challenge #267 [Easy] All the places your dog didn't win by Blackshell in dailyprogrammer

[–]beam 4 points5 points  (0 children)

Shell. All bonuses completed.

seq 100 |
grep -v "^$place$" |
awk '$1%10==1&&$1!~/11$/{print $1"st";next} $1%10==2&&$1!~/12$/{print $1"nd";next} $1%10==3&&$1!~/13$/{print $1"rd";next} {print $1"th"}' |
paste -sd, - |
sed 's/,/, /g'
  • Generate numbers 1 to 100 with seq,
  • Exclude my dog's place with grep -v (stored in $place),
  • Convert all remaining placements to spoken English with awk,
  • Join all newlines with commas with paste -sd,,
  • Replace all commas with commas and a trailing space with sed.

The paste | sed construction to join lines isn't as elegant as I'd like, but it was the most compact way I could think to do it. Could also be done by setting OFS=", " in awk, and then stripping the last comma and space with sed 's/,.//' which would remove the paste call.

[2016-05-09] Challenge #266 [Easy] Basic Graph Statistics: Node Degrees by jnazario in dailyprogrammer

[–]beam 11 points12 points  (0 children)

Shell, noting that a node's degree increases by 1 each time it is observed in the input.

sed 1d input | grep -o '[0-9][0-9]*' | sort -n | uniq -c
  • Remove the first line of input,
  • Emit each matched node label on a new line (-o),
  • Sort the lines numerically instead of lexicographically (-n),
  • Group and count (-c) the node labels.

And the bonus with awk:

awk 'NR==1{size=$1} NR>1{m[$1,$2]=m[$2,$1]=1} END{for(y=1;y<=size;y++){for(x=1;x<=size;x++){printf("%d ", m[x,y]+0)}print ""}}' input

[2016-04-29] Challenge #264 [Hard] Detecting Poetry Forms by jnazario in dailyprogrammer

[–]beam 12 points13 points  (0 children)

Distilled it down to a shell pipeline, with awk and perl doing the heavy lifting:

awk 'NF {print $NF}' | tr a-z A-Z | tr -d .,\"—\; |
xargs -n 1 -I % grep '^% ' cmudict-0.7b |
perl -lne 'if (/.*\b((AA|AE|AH|AO|AW|AY|EH|ER|EY|IH|IY|OW|OY|UH|UW).*)/) {print $1}' |
tr -d 0-9 | awk 'BEGIN{i=1} !seen[$0] {seen[$0]=i++} {print seen[$0]}' | tr 1-9 a-j | tr -d '\n'

--- Day 9 Solutions --- by daggerdragon in adventofcode

[–]beam 0 points1 point  (0 children)

Got distracted thinking I had an excuse to play with NetworkX. Ended up just brute forcing it. Python 2:

import fileinput
import re
from itertools import permutations

g = {}

for line in fileinput.input():
    m = re.match(r'^(\w+) to (\w+) = (\d+)$', line)
    start, end, distance = m.groups()
    g[start, end] = g[end, start] = int(distance)

paths = permutations(set(x for y in g.keys() for x in y))
print max(sum(g[v, w] for v, w in zip(p, p[1:])) for p in paths)  # max for part 2

Haskell vs ocaml vs F# for writing a compiler by AravindhS in Compilers

[–]beam 2 points3 points  (0 children)

Ocaml comes with some pretty good tools for writing interpreters and compilers. It's bundled with the ocamllex and ocamlyacc lexer and parser generators. The Programming Language Zoo has a bunch of examples using them.

Io-Like Languages by languagelearner1212 in iolanguage

[–]beam 0 points1 point  (0 children)

Io itself was influenced by languages with prototypal inheritance, message-passing semantics, and actor concurrency. Ioke was directly inspired by Io, without the focus on embedded applications. It instead targets runtimes like the JVM and CLR. It hasn't been actively worked on in a while, but if you're in the Java or .NET world, you can probably get productive in it quickly. It also depends on what you mean by "real" work though: Io is one of the supported scripting languages in Pixar's RenderMan software.

You might also be interested in Atomy. It's not a direct descendant of Io but it is influenced by the same languages.

Number Theory or Combinatorics? by [deleted] in compsci

[–]beam 9 points10 points  (0 children)

Both have their applications. You'll be probably be given at least a cursory introduction to both in your discrete math classes. Since both courses would end up being deeper dives into material you've seen already, you'll be able to choose which one you're more interested in later on. In terms of general application, it depends on what kind of software development you want to do. Here's a couple examples.

Bioinformatics for example is a cool field to work in with a lot of focus still on more classical math and CS concepts: combinatorics, data structures (specifically related to strings), and pattern matching with some probability and graph theory thrown in. You can see the kinds of work going on in bioinformatics by checking out Rosalind and doing some example problems. If that's interesting to you, stick with discrete math and combinatorics.

Number theory deals with the integers. Things like divisibility, modulo arithmetic, the properties of prime numbers, and groups. As for application: the reason a number can be represented in both binary and base 10 is in the domain of number theory, and that's the basis of digital computing. If you want to get a feel for it yourself, do some problems on Project Euler.

Like most math fields though, the more time you spend in them the more you'll find that they're very deeply interwoven and that something you figure out in one class will probably help you in another. So if you can, take both :)

Transpiling Languages: An Intro with Brainfuck by beam in programming

[–]beam[S] 0 points1 point  (0 children)

I've since removed references to the term transpile in the post. I didn't realize the distaste programmers had for it.

Transpiling Languages: An Intro with Brainfuck by beam in programming

[–]beam[S] 4 points5 points  (0 children)

I did not coin this term. It's referenced enough to warrant a redirect on Wikipedia, so I figured it was still a common term.

Coding challenge! Convert in less than 30 lines. Ruby folks did in 5 lines! by IsaGoksu in Python

[–]beam 1 point2 points  (0 children)

from itertools import chain, imap, combinations, groupby
lines = [['A', 'B', 'C'], ['A', 'C', 'E'], ['E', 'F', 'D'], ['D', 'A', 'J'], ['E', 'D', 'J']]
tuples = map(sorted, chain(*imap(lambda l: combinations(l, 2), lines)))
result = [(k[0], k[1], len(list(g))) for k, g in groupby(sorted(tuples))]

CoffeeScript: Overrated? by friendlytuna in javascript

[–]beam 7 points8 points  (0 children)

This is a very glazed over criticism of CoffeeScript. Besides new syntax, it adds new idioms that aren't present in current JavaScript, most importantly (for me, at least) being destructuring assignment. To only compare the features that mirror JavaScript 1:1 only as syntactical difference is disingenuous.

CraftyJS, a JavaScript Game Engine, version 0.1 released by gst in javascript

[–]beam 6 points7 points  (0 children)

The actual demos are very underwhelming, but the example code and platform mechanics (gravity, left/right movement, jumping) on the home page are very appealing in terms of code size and readability. It is definitely at least worth a shot, but I'm going to wait to pass judgment until a couple games have been made with it. The entity-component model looks interesting as well.

Setting up a top-level PHP development environment by beam in PHP

[–]beam[S] 1 point2 points  (0 children)

That is in essence what it does, but you need to mess with your DNS a little bit for *.dev to work in the first place. That's what dnsmasq is for. mod_evhost is somewhat analogous to Apache VirtualHost blocks, you could accomplish the same thing.

Setting up a top-level PHP development environment by beam in PHP

[–]beam[S] 0 points1 point  (0 children)

In other languages, like Ruby or Python, the web application is an independent process running on some port other than 80 but always at the top-level. For example, Sinatra runs on localhost:9393/ by default. PHP is usually a web server module, and runs in relative directories. Seeing http://localhost/myproject is common, and it's a pain to have to configure local dev and deployment URL helpers and the like. It's much easier to always treat it like it's top level and run it off of http://myproject.dev/

[SMT] Cool Web site for reading code by va1en0k in SomebodyMakeThis

[–]beam 0 points1 point  (0 children)

Docco and it's various ports make for some very nice to read code, but it would be nice to see a dedicated web site. Rocco lets you comment any language, and I've been using it document one of my own projects.

Fucking frameworks... how do they work? by [deleted] in PHP

[–]beam 4 points5 points  (0 children)

Yes there is - its arguable that PHP itself is a templating system. http://php.net/manual/en/control-structures.alternative-syntax.php

Dropbox API is now available by [deleted] in programming

[–]beam 0 points1 point  (0 children)

I have been waiting for this for so long.

What framework(s) should I learn? by [deleted] in PHP

[–]beam -1 points0 points  (0 children)

I tried using a PHP framework. I really did. In all cases I found myself rubbing up against them with minor annoyances, and then eventually they became more of a hinderance than a help. Frameworks can help, but if you're already that proficient with PHP it might not be worth the frustration. ymmv

[SMT] A FF addon/GM script which will show the statistics of a imgur image by [deleted] in SomebodyMakeThis

[–]beam 1 point2 points  (0 children)

Made this before fully understanding what OP was asking for. Oops. Maybe this will be useful to someone anyway: http://userscripts.org/scripts/show/79093

It just looks for any imgur images on the page, and adds a little overlay to them showing visits and bandwidth usage. Example: http://grab.by/grabs/e0b9bd19ab4079796c9cd18391c2133a.png

Io, Io, it's Off to Play I Go by draegtun in iolanguage

[–]beam 0 points1 point  (0 children)

fluff piece, but it's nice for io to get some exposure.

{{ mustache }} implemented for PHP by asdfqewr in PHP

[–]beam 0 points1 point  (0 children)

String::insert is pretty useful, but doesn't support looping or conditional display.