Show newer

@freemo @serra what I was thinking might be that if you set the prices using base 8 then you would have two letters left over so in the previous example a-h could be the only numbers used in the actual base price and i and j 8 and 9 could indicate whether or not to apply a consistent discount. best case you could have 89 meaning that rest of the price is standard and 98 means divide for a x% discount. I think that would be doable. Then if you could represent it with base 5 or 6 you would have 4 or 5 letters left over to have a modifier. I think it is a doable math issue once solved would make for some interesting "word" choice problems with fun meaningful anagrams.

@freemo When I was interviewing candidates for jobs in SQL my idea was to have them solve a problem like how to design a database to manage WIlly Loman's missionary book.

However, when I would get some of these young guys in, they will have never seen or read the play. Or never done old school sales where they used a "missionary book."
So for a 15 minute interview I ended up trying to explain the Play or Sales techniques to someone instead of moving forward with questions about table design and so forth. I had to learn to make much simpler examples. Because things you assume are common knowledge, aren't always so common.

@freemo @serra single word.

The base premise is that you would have picked a word you could remember like "UPHOLSTERY" then you would be able to look at the sticker and see Yyy and know it was 9.99 without having to have a decoder ring and calculator :)

But as a coding problem I am moving away from that and letting a computer do all the work. With that in mind just wondering if I could simply change the letters around to accomplish an overall discount or markup. Hey, it might not be possible, but it sounded like it should be.

(This is starting to remind me of my "Death of a Salesman" interview question fiasco :) remind me to tell you that story some time)

@freemo @serra

what I was thinking was something like using the word "ABCDEFGHIJ" to encode a price BAjj as 10.00 if I were to change the word to "BCDEFGHIJA" then decoded the same price it would be $09.99.

I wonder if there is a system whereby encoding with one word, and decoding with another would be capable of effecting a change of some reasonable % like 10%, 15%, 35%.

I kind of thought you would have to change bases like base(*) or something, or if you had a pair of numbers that would be multiiplied or otherwise functionally modified. The problem being that you only have 10 numbers to play with.

I am not saying it is possible, but it seems like you could do it. I don't have a problem just trying to make one. Otherwise I don't have a real problem for this week yet. :)

@freemo @serra just a sticker with a sku#. Hey buddy how much for this thing? It should seem like you have all the prices memorized or made up on the spot :)

@serra not sure if it is possible, @freemo would know.. Might involve using different bases or something

@serra that just begs for a rick roll :) I was thinking something more like encoding with one word, and then switch the letters around in the word and effect a 15, 20, 30% discount. Or something like that.

@twee@patch.cx no love for spacemacs or Spacevim but I do like evil mode on Emacs.

Okay, maybe you can help me come up with a problem. I can feel it coming on, so here is where I am going:

A trick for pricing things for negotiation is to hide the price encoded. One of the ways of doing this is using a 10 letter isogram such as "upholstery" to convert 0=u, 1=p, 2=h...9=y. So then you could mark a tag or sticker with Tly for $6.49 (with the capitols for dollars and the lower case for cents) Alternatively, you could have an asking price and hide a lowest taking price TlyLuu Meaning that you could ask 6.49 but settle for 4.00. This way someone else could negotiate with the customers, from the person that set the prices.

So writing a program should be unnecessary, the reason for using the isogram is to make it easy to remember and figure it out simply.

So how hard would a program to do this be? Ideas?

This is not a programming question per-se. It, was however, quite interesting and fun to figure out. I am still looking for a new program for this weekend. Unfortunately, no one seemed too interested in last weekend's one, so I may let it float. But I am still looking for one anyway.

An evil warden holds you prisoner, but offers you a chance to escape. There are 3 doors A, B, and C. Two of the doors lead to freedom and the third door leads to lifetime imprisonment, but you do not which door is what type. You are allowed to point to a door and ask a single yes-no question to the warden. If you point to a door that leads to freedom, the warden does answer your question truthfully. But if you point to the door that leads to imprisonment, the warden answers your question randomly, either saying "yes" or "no" by chance. Can you think of a question and figure out a way to escape for sure?

@freemo I like this way of examining the data. I may give it a try after all.

Octave solution 

@Absinthe

Linear in time and space by taking advantage of the Fibonacci numbers.

function count = interpretations(string)
ambig = string(1:end-1) == '1' | (string(1:end-1) == '2' & string(2:end) <= '6');
ambig &= string(1:end-1) ~= '0' & string(2:end) ~= '0' & [string(3:end) '1'] ~= '0';
ambig = [false ambig false];
consec = find(ambig(1:end-1) & !ambig(2:end)) - find(!ambig(1:end-1) & ambig(2:end));

fibo = zeros(max(consec), 1);
fibo(1:2) = [2 3];
for i = 3:max(consec)
fibo(i) = fibo(i - 1) + fibo(i - 2); end;
count = prod(arrayfun(@(x)fibo(x), consec)); end;

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.

@namark @khird sometimes bruter force is the right answer.

There is a quote by Herodotus "Force has no place where there is need of skill." However, I paraphrase it a little when I say "Brute force is only rarely a substitute for finesse"

@namark @khird ultimately in a real serialization using a format like JSON or XML or something with a DOM and library to handle it. Then it can be used from something else as well. But these problems however, are meant to be quick enough to accomplish in a job interview. I thought of a different way to try also. I think I can create a geenrator and just use next() then maybe I can avoid the idx. But this seemed like a fun enough way to solve the problem.

What did you think of this weekend's problem? The "One to Nine" one?

The freebie today is pretty annoying too. Debating if I want to try to solve it or not yet.


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.

@namark yeah, I fixed the comma thing, made it into RS 0x1E. I guess I could change the 'None' to either actual None or another control character. But FWIW I think I may have to just leave it be, as close enough for government work :) I found some other people solve similar problems with # for the None value. I think I am ready to move on to the next problem. Got a new one today, seems like a real PITA.

Show older
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.