puzzle

Two generals' agreement

旧城冷巷雨未停 提交于 2019-12-04 11:57:52
I am trying to figure an agreement protocol on an unreliable channel. Basically two parties (A and B) have to agree to do something, so it's the two generals' problem . Since there is no bullet-proof solution, I am trying to do this. A continuously sends a message with sequence 1 When B receives seq 1 it continuously replies with sequence 2 At this point A receives seq 2 so it starts sending seq 3 ... My question. When can the two parties conclude that they can take the action ? Obviously I can't set a condition: " do it after receiving 10 messages " since the last sender won't have any

How can I create a threshold for similar strings using Levenshtein distance and account for typos?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 11:29:59
We recently encountered an interesting problem at work where we discovered duplicate user submitted data in our database. We realized that the Levenshtein distance between most of this data was simply the difference between the 2 strings in question. That indicates that if we simply add characters from one string into the other then we end up with the same string, and for most things this seems like the best way for us to account for items that are duplicate. We also want to account for typos. So we started to think about on average how often do people make typos online per word, and try to

Java Puzzler- What is the reason? [closed]

眉间皱痕 提交于 2019-12-04 07:06:13
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center . Closed 6 years ago . I wrote following code. class String { private final java.lang.String s; public String(java.lang.String s){ this.s = s; } public java.lang.String toString(){ return s; } public static void main(String[] args) { String s = new String("Hello world"); System

Why swap with xor works fine in c++ but in java doesn't ? some puzzle [duplicate]

狂风中的少年 提交于 2019-12-04 04:16:41
Possible Duplicate: Why is this statement not working in java x ^= y ^= x ^= y; Sample code int a=3; int b=4; a^=(b^=(a^=b)); In c++ it swaps variables, but in java we get a=0, b=4 why? By writing your swap all in one statement, you are relying on side effects of the inner a^=b expression relative to the outer a^=(...) expression. Your Java and C++ compilers are doing things differently. In order to do the xor swap properly, you have to use at least two statements: a ^= b; a ^= (b ^= a); However, the best way to swap variables is to do it the mundane way with a temporary variable, and let the

QCRs vs functional property

情到浓时终转凉″ 提交于 2019-12-04 02:38:56
问题 I have question based on the topic: SOF - Einstein puzzle in OWL In the owl, all cardinality restrictions are based on functional and inverse functional properties of Object Properties. I have remodeled it using QCRs. Old model (example): man drinks some beverage; drinks -> functional, inferse functional New model /EDITED/ : man drinks exactly 1 beverage; beverage drinkedBy exactly 1 man; drinks -> domain:man, range:beverage drinkedBy -> domain:beverage, range:man drinks inverseOf drinkedBy I

Puzzle.. solving product of values in array X

…衆ロ難τιáo~ 提交于 2019-12-03 22:53:33
问题 Can you please help me solving this one? You have an unordered array X of n integers. Find the array M containing n elements where Mi is the product of all integers in X except for Xi. You may not use division. You can use extra memory. (Hint: There are solutions faster than O(n^2).) The basic ones - O(n^2) and one using division is easy. But I just can't get another solution that is faster than O(n^2). 回答1: Let left[i] be the product of all elements in X from 1..i . Let right[i] be the

A Dynamic programming problem

雨燕双飞 提交于 2019-12-03 18:42:31
问题 Can anyone help me find an optimal Dynamic programming algorithm for this problem On the way to dinner, the CCC competitors are lining up for their delicious curly fries. The N (1 ≤ N ≤ 100) competitors have lined up single-file to enter the cafeteria. Doctor V, who runs the CCC, realized at the last minute that programmers simply hate standing in line next to programmers who use a different language. Thankfully, only two languages are allowed at the CCC: Gnold and Helpfile. Furthermore, the

Set every cell in matrix to 0 if that row or column contains a 0

末鹿安然 提交于 2019-12-03 18:16:47
问题 Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. Given a NxN matrix with 0s and 1s. Set every row that contains a 0 to all 0 s and set every column that contains a 0 to all 0 s. For example 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 results in 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 A Microsoft Engineer told me that there is a

Puzzled over palindromic product problem

烂漫一生 提交于 2019-12-03 15:54:15
I've been learning Ruby, so I thought I'd try my hand at some of the project Euler puzzles. Embarrassingly, I only made it to problem 4... Problem 4 goes as follows: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. So I figured I would loop down from 999 to 100 in a nested for loop and do a test for the palindrome and then break out of the loops when I found the first one (which should be the largest one): final=nil range = 100...1000

Puzzle: Need an example of a “complicated” equivalence relation / partitioning that disallows sorting and/or hashing

本小妞迷上赌 提交于 2019-12-03 13:53:08
From the question " Is partitioning easier than sorting? ": Suppose I have a list of items and an equivalence relation on them, and comparing two items takes constant time. I want to return a partition of the items, e.g. a list of linked lists, each containing all equivalent items. One way of doing this is to extend the equivalence to an ordering on the items and order them (with a sorting algorithm); then all equivalent items will be adjacent. (Keep in mind the distinction between equality and equivalence .) Clearly the equivalence relation must be considered when designing the ordering