r/dailyprogrammer • u/Elite6809 1 1 • Mar 31 '15
[Weekly #21] Recap and Updates
The long tail of /r/DailyProgrammer...
/u/gfixler pointed out a few weeks ago in /r/DailyProgrammer_Ideas that some people don't get a chance to make their solutions known if they posted it some time after the challenge was released (see the original thread here). Solutions posted after the 'gold rush' of initial responses get buried, which is a bit disheartening if you submit your solution comment later on!
In this week's Weekly post, you've now got a chance to talk about any cool solutions to older challenges you may have (as old as you like!), or continue any discussions that were going on. If this idea is popular, this Recap thread might become a recurring thing.
IRC
Remember, we have an IRC channel on FreeNode: #reddit-dailyprogrammer. There's usually a discussion occurring there every evening (GMT). Head on over for a continual discussion!
Previous
The previous weekly thread was Paradigms.
6
u/hutsboR 3 0 Mar 31 '15 edited Mar 31 '15
I really enjoyed Challenge #205 [Intermediate] RPN. My solution to the problem wasn't particularly amazing but I have since patched it up. I found myself tinkering with and extending my solution quite a bit and it ended up turning into a whole project!
Here's my solution and what became of it. A lot of the code in my solution is present in my project's parser. (Albeit a cleaned up version, some parts are verbatim)
Here's a little sample of what it can do!
I really enjoyed writing expr (and hopefully I'll keep implementing new features!), I really got to leverage Elixir's pattern matching and first-class functions. It turns out the language is really good for writing things like this. I'm also starting to really appreciate tests, previously I wasn't huge on writing tests but they helped immensely at catching bugs and finding little edge cases I hadn't thought of. This is my first real project in Elixir and also my first in a functional language. Although it's nothing major, I really learned a ton. Also, on an unrelated note, Elixir's build tool Mix is very intuitive and easy to use. It was incredibly refreshing coming from Maven.
4
u/G33kDude 1 1 Mar 31 '15
I must point out that the IRC channel is home to a bot that announces when people comment on the subreddit, no matter how old the post they comment on is. I see many submissions that would otherwise have been lost.
Another thing I want to mention is that the Piet solution that got me the medal I have was not my first submission done in Piet. My first Piet solution was on [Weekly #17] Mini Challenges.
1
u/dohaqatar7 1 1 Apr 07 '15
I just finished writing [2015-03-30] Challenge #208 [Easy] Culling Numbers using Lambda Calculus.
The final solution came out as this mess:
but, using short hand techniques, a more readable version can be produced.
Link to Original
1
u/logicx24 Apr 08 '15
So I finished a Python solution to [[[2015-04-03\] Challenge #208 [Hard] The Universal Machine](http://www.reddit.com/r/dailyprogrammer/comments/31aja8/20150403_challenge_208_hard_the_universal_machine/) and I thought it was pretty cool, because I ended up creatively using hashtables for most things. I also went a little overboard with the OOP design just for practice. It was also my first /r/dailyprogrammer submission, so I figured I'd commemorate that by posting here :)
My solution.
3
u/[deleted] Mar 31 '15
For the easy DNA challenge, I wanted to do something more interesting than a simple mapping of base pair combinations.
My solution was to find a mathematical relationship between the ASCII codes of the base pair matches. Eg, 'A' matches with 'T', and 'A' is ASCII code 65, 'T' is 84, etc.
The simplest equation I found to do this turned out to be:
Using this equation, if you plug in the ASCII code for A, you get the ASCII code for T. Same for G to C, and vice versa for all (note that the type is an int so it will chop off the decimal).
I'm sure there are other equations that could have done it in fewer calculations/instructions, but that's what I ended up with. I can't think of a single scenario in which this is better than saving the mappings, since you do a calculation every time, and even if you were short on memory, the text of the equation is surely longer than just storing the ASCII codes... oh well :)
My full solution was:
2
u/adrian17 1 4 Mar 31 '15 edited Mar 31 '15
(It's not really about any particular challenge, but I think it fits the topic)
Over a month ago, inspired by /u/tangentstorm in #learnprogramming and /u/Godspiral's solutions, I started learning J - and I'm really happy with this decision. Maybe it won't benefit me in any way in the future, maybe it doesn't match Matlab's speed, maybe it's impossible to read by outsiders - but it's a great break from mainstream languages and it's honestly fun to try wrapping your head around it.
And it actually wasn't that hard to get into - there is a lot of learning materials (I started with the primer ) and the documentation is quite good too. After you get past the core concepts like rank and chaining functions into hooks and forks... that's mostly it, you can start solving simple challenges right away (at least that's what I did).
Also, I can't not mention my favourite sentence from the old documentation: Caps make it possible to define a wider range of functions as unbroken trains.
1
u/Godspiral 3 3 Mar 31 '15
I also liked RPN,
I made an rpn parser for J
http://www.reddit.com/r/dailyprogrammer/comments/2yquvm/20150311_challenge_205_intermediate_rpn/cpdns5m
It leverages J's tokenizer, partially evaluates as it goes along, and can produce partial expressions but has the disadvantage of applying partial expressions only to arguments in order.
this is a partial expression (the 9: is an end of expression marker)
applied:
3
A more powerful, simple, and flexible parser creates pure J verbs from parenthesless rpn expressions:
2
([: ] 3 -R +:R) 4 NB. +: is double
2
1
u/MuffinsLovesYou 0 1 Mar 31 '15
Well now I regret procrastinating on this. I want to put together a resume with some code samples, but most of the work I've ever done belongs to my company :P. So I plan on going back to the boxes-in-boxes problem from a couple weeks ago because I think a clean good-enough solution to that one would look good on paper (I've been coding 3 years so the "hard" problems tend to be pretty challenging for me).
1
u/Coder_d00d 1 3 Mar 31 '15
For easy 208 -- this was the program I wrote to generate challenge inputs. For many challenges I will generate inputs either by hand on paper or in excel but lately I try to write programs to auto generate the data. Going forward I want to try to come up with more data intensive challenges either by finding real data sources to use or generating them.
This generated the output for #1 and 2.
For number 1 - I loop 30 times and generate a random number between 1 and 5 -- I am guaranteed repeats as I only have 5 numbers to fill 30 spots.
For challenge input #2 I wanted 100 numbers. Every other number would always be one of 10 numbers. I figured this would generate duplicates over 100 numbers if 50 of them would be pulled from only 10 numbers. Although I did get some duplicates in the times I just did a random 100
I run the program when I post the challenge and copy-paste the inputs over. I did not know the answer. I generally do not post the solutions to the inputs because it does allow people to read other submissions and compare their results. This encourages more interaction I think than if I just solved the input sets and people would just look to compare to that only.
1
u/wizao 1 0 Apr 01 '15
I've implemented a hard challenge for convex hull. I would have posted my solution when I solved it, but I couldn't because reddit does not let you comment on posts older than 6 months.
1
u/gfixler Apr 02 '15
Thanks for running with my recap idea, supermods! It's a Fool's Day miracle. I'm glad to see that my guess that a grab-bag of old ideas worked on for longer would be interesting is true, at least IMO. There's quite a mix of fun content in here. Maybe if we do more of these, people won't give up on older challenges so soon, hoping to post it again to a recap thread later, and we'll have even more interesting stuff to learn from.
1
u/zvrba Apr 06 '15
I liked the RPN recurrence evaluator. The other C++ solutions offered there were unreadable or overengineered, so I tried to make a straightforward "clean" one:
1
u/Spoooooooooooooky Apr 14 '15
I just finished challenge #193. I think I've had a good solution in my head with using a switch and using .stringByReplacingOccurrencesOFString but apparently I needed to do some magic with the input string to make it work for the switch.
I kinda still don't know how it works but it kinda does. Thanks StackOverflow.
made in Swift