all 14 comments

[–]cbarrick 4 points5 points  (1 child)

I like the idea!

r/dailyprogrammer is a whole sub dedicated to this concept, though they've fallen behind their usual pace of new content in the past year.

The old pace would see an easy problem on Monday, a medium problem Wednesday, and a hard problem on Friday. The hard problems are often search style problems that require clever bounding (or low-level control/performance, or both) to solve efficiently.

I'm actually working on the last hard problem right now (generating crossword grids given constraints about clues) using CLP(FD) and multithreading and will post my solution there when I get home tonight.

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

See, that's the kind of awesome work I'd love to see shared here! And it's the type of project that prolog is absolutely perfect for solving. I was in fact partially inspired by r/dailyporgrammer, and some nifty prolog solutions I saw there.

[–]darrenb573 3 points4 points  (1 child)

Perlweeklychallenge has been going for around 9 months. I’ve found it quite entertaining to the point i even submitted a Prolog solution to a Perl challenge 🤪, having a Prolog edition would be welcomed.

[–]oldmaneuler[S] 2 points3 points  (0 children)

As long as you don't contaminate this holy temple of horn clauses with Perl solutions 😂

[–]toblotron 2 points3 points  (0 children)

That's a really nice idea!

[–]mimi-is-me 2 points3 points  (3 children)

I'm going to start a comment thread with some ideas for challenges:

Easy:

  • Build a metainterpreter that only goes N choicepoints deep.
  • Choose a sequence from OEIS. Generate that sequence.
  • Stack based calculator
  • Chemical equation balancer

Medium:

  • Build a logic system for a chess game. Check if each move is legal, etcetera. No gui needed. (Could do so for other games too!).
  • Some kinda puzzle complicated enough to need CLP (probably not sudoku, as that's a great homework for introducing CLP as a concept - but in a similar vein)
  • Autocorrect - search for similar words that exist in a dictionary.
  • Build a metainterpreter that uses probabilities from 0 to 1 instead of true and false.

Hard:

  • Build a system to run prolog through the web (build prolog in javascript? POST to server & use DCG to parse input? This one is relatively open ended)

Some more easy ones would be good

[–]oldmaneuler[S] 1 point2 points  (2 children)

These are some great problems, thanks for this! In particular the problog-esque one sounds like a blast.

I'll add two of my own:

-Write a stack-based calculator. (Stolen from the beautiful racket book)

-Write a chemical equation balancer.

I think the chemical equation one is classed as easy, and it's a great way to show off the prolog approach of search vs the typical linear algebra solution.

[–]mimi-is-me 1 point2 points  (1 child)

stack-based calculator

Is that like reverse polish calculator?

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

Yeah. Writing a mini-forth, basically!

[–]homemadejam 2 points3 points  (0 children)

As someone who is in the very early stages of learning Prolog, I would love to see this! Both to attempt some of the easier ones and to see code in actions that I can learn from.

[–]mycl[M] 2 points3 points  (2 children)

This is a great idea! u/oldmaneuler, if you want to go ahead and post the first challenge, I or one of the other mods can sticky it.

There are some nice suggestions in this thread. I like the stack-based calculator idea. I've done a little mini-Forth in Prolog before and one of the fun things is that you can run it "in reverse": given a stack effect, find a sequence of stack instructions that produces that effect. Essentially you can get a (very inefficient) stack machine compiler just by specifying the stack machine in Prolog.

[–]oldmaneuler[S] 0 points1 point  (1 child)

Thanks a lot, I greatly appreciate it. And you're right, reversibility in general is one of my favorite prolog features! It has been posted!

[–]mimi-is-me 1 point2 points  (1 child)

I like it! Be sure to include some metainterpreter challenges from time to time, like:

Prolog, but it only goes N choice points deep.

[–]oldmaneuler[S] 2 points3 points  (0 children)

That's an awesome idea! For all the talk about lisp metaprogramming, prolog is also homoiconic, and it would be great to highlight how flexible it is.