Show newer

@billstclair

lol not efficient if **all** you need is the count, but it does work of course.

@Absinthe

@Absinthe BTW i intentionally chose to list them not count them. I could probably optimize further if I counted only. In fact that would be trivial, so i think ill solve that too.

@Absinthe BTW i intentionally chose to list them not count them. I could probably optimize further if I counted only.

Show thread

This was a really fun programming challenge originally proposed by @Absinthe I want to paste it here, along with my solution, so everyone who is interested can check it out.

Here is the link to his original post: qoto.org/@Absinthe/10289580109


Another Freebie...

This problem was asked by Facebook.

Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded.

For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'.

You can assume that the messages are decodable. For example, '001' is not allowed.

Here is the link to my solution: qoto.org/@freemo/1028986298217

My solution. This should be a somewhat space-optimized solution in ruby based off the modified concept of a Trie.

git.qoto.org/snippets/4

If i made this into a Radix Trie by compressing nodes with single children down I could reduce this further.

But since it does work I thought I'd share it as is. I'll update everyone if i decide to finish optimizing this particular solution.

It does however do a fairly decent job at compressing the tree by making sure no subtree is a duplicate of any other part of the tree (a node of any specific length/id will be the only node with that length.

For clarity I attached a picture from my notes of what the Trie would look like for the encoded string "12345" where the value inside each circle/node is the "length" value of that node, and the value attached to an arrow/vector/edge is the "chunk" associated with that link. The end result is any path from the minimum node (0) to the maximum node (5). This diagram does not include incomplete paths which my program does right now.

Incomplete paths can also be trimmed to further reduce the space. But since incomplete paths each add only a single leaf node to the tree, and might be useful for various use cases I decided to keep it.

@Absinthe My solution. This should be a somewhat space-optimized solution in ruby based off the modified concept of a Trie.

git.qoto.org/snippets/4

If i made this into a Radix Trie by compressing nodes with single children down I could reduce this further.

But since it does work I thought I'd share it as is. I'll update everyone if i decide to finish optimizing this particular solution.

It does however do a fairly decent job at compressing the tree by making sure no subtree is a duplicate of any other part of the tree (a node of any specific length/id will be the only node with that length.

For clarity I attached a picture from my notes of what the Trie would look like for the encoded string "12345" where the value inside each circle/node is the "length" value of that node, and the value attached to an arrow/vector/edge is the "chunk" associated with that link. The end result is any path from the minimum node (0) to the maximum node (5). This diagram does not include incomplete paths which my program does right now.

Incomplete paths can also be trimmed to further reduce the space. But since incomplete paths each add only a single leaf node to the tree, and might be useful for various use cases I decided to keep it.

@Absinthe My solution. This should be a somewhat space-optimized solution in ruby based off the modified concept of a Trie.

git.qoto.org/snippets/4

If i made this into a Radix Trie by compressing nodes with single children down I could reduce this further.

But since it does work I thought I'd share it as is. I'll update everyone if i decide to finish optimizing this particular solution.

It does however do a fairly decent job at compressing the tree by making sure no subtree is a duplicate of any other part of the tree (a node of any specific length/id will be the only node with that length.

For clarity I attached a picture from my notes of what the Trie would look like for the encoded string "12345" where the value inside each circle/node is the "length" value of that node, and the value attached to an arrow/vector/edge is the "chunk" associated with that link. The end result is any path from the minimum node (0) to the maximum node (5). This diagram does not include incomplete paths which my program does right now.

Incomplete paths can also be trimmed to further reduce the space. But since incomplete paths each add only a single leaf node to the tree, and might be useful for various use cases I decided to keep it.


Another Freebie...

This problem was asked by Facebook.

Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded.

For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'.

You can assume that the messages are decodable. For example, '001' is not allowed.

@Absinthe Since the main complexity issue here becomes space complexity im going to tackle this as a space optimized solution. Sould also be pretty close to ideal on time complexity if i do it right too.

@saxnot Wait what? They make you take a literal IQ test in germany and based on those results decide if they want to help you? That sounds messed up.

"Gifted intelligence" makes perfect sense in its own right it just has nothing to do with IQ. If they are using your performance abilities at solving real qorld problems others can as a measure as to who to give more resources to in order to solve problems, I see no problem with that.

@saxnot I wouldnt say im an opponent of it or support it. I find it to be a silly little meaningless thing some people like to do.

To me its in the same category as those little physical puzzles you need to assemble or disassemble. They are fun and measure a very narrow and specific aspect of intelligence.

@saxnot I often say "IQ is simply a measure at your proficiency at taking IQ tests"

RT @FungalSquirrel@twitter.com
Wife sent me this fig and asked if scientists would find it funny.

I dunno about you, but I giggled until I wheezed.

@saxnot

Biking has a lot to do with infrastructure. In the USA i tried to bike to work and simply couldnt. I t was dangerous, took way too much time, and i was lucky if there was even a legal pathway there.

In the netherlands with their amazing infrastructure it is a no brainer for everyone.

@Nikita

Show older
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.