computer-science

What is a lambda (function)?

坚强是说给别人听的谎言 提交于 2019-12-16 19:56:29
问题 For a person without a comp-sci background, what is a lambda in the world of Computer Science? 回答1: Lambda comes from the Lambda Calculus and refers to anonymous functions in programming. Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this. Python def adder(x): return lambda y: x + y add5 = adder(5) add5(1) 6 As you can see from the snippet of Python, the function

java program - divisibility test with varification - how do i write this in textpad [closed]

﹥>﹥吖頭↗ 提交于 2019-12-14 00:07:36
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . i have the program written however I have two problems and need assistance to correct. the problems are 1) i do not want the counter i

Error Help: 'tuple' object has no attribute 'getx'

只愿长相守 提交于 2019-12-13 23:03:46
问题 I'm having trouble debugging my code. class Point: def __init__(self, x, y): self.x = x self.y = y def compare(self, other): x1 = self.x y1 = self.y x2 = other.x y2 = other.y n = 512 if (x1 == x2) and (y1 == y2): return 0 found = False while found == False: if ((x1 // n) != (x2 // n)) or ((y1 // n) != (y2 // n)): found = True c1 = ((x1 // n), (y1 // n)) c2 = ((x2 // n), (y2 // n)) else: if x1 >= n and x2 >= n: x1 = x1 - n x2 = x2 - n if y1 >= n and y2 >= n: y1 = y1 - n y2 = y2 - n n = n / 2

Number of binary tree shapes of N nodes are there with height N-1?

笑着哭i 提交于 2019-12-13 22:02:32
问题 How many binary tree shapes of N nodes are there with height N-1? Also, how would you go about proofing by induction? So binary tree of height n-1 with node n means all node will have only 1 child, sort of chain like structure? So number of binary tree will be different permutation of n numbers which is n. Am I thinking in the right direction? 回答1: You are thinking in the right direction and you have correctly transformed the original problem to a simple one. However what is strange is that

merge sort recursion tree height

我的梦境 提交于 2019-12-13 20:14:44
问题 I am learning about recursion tree's and trying to figure out how the height of the tree is log b of n where n = 2 and one has 10 elements as input size. I am working with Merge sort. The number of times the split is done is the height of the tree as far as I understood, and the number of levels in the tree is height + 1. But if you take (for merge sort) log2 of 10 you get 1, where if you draw the tree you get at least 2 times that the recursion occurs. Where have I gone wrong? (I hope I am

Tracking multi-touch movements inside the frame with transmitters and receivers

馋奶兔 提交于 2019-12-13 12:48:14
问题 The problem with tracking multi-touches (at least two finger touches) on the following frame device. White circles are LEDs and black circles are receivers. When user moves fingers inside this frame we can analyze which receivers received light from the LEDs and which has not received. Based on that we need to track movements of the fingers somehow. First problem that we has separate x and y coordinates. What is the effective way to combine them? Second problem concerns analyzing coordinates

Expectation Maximization coin toss examples

醉酒当歌 提交于 2019-12-13 11:41:41
问题 I've been self-studying the Expectation Maximization lately, and grabbed myself some simple examples in the process: http://cs.dartmouth.edu/~cs104/CS104_11.04.22.pdf There are 3 coins 0, 1 and 2 with P0, P1 and P2 probability landing on Head when tossed. Toss coin 0, if the result is Head, toss coin 1 three times else toss coin 2 three times. The observed data produced by coin 1 and 2 is like this: HHH, TTT, HHH, TTT, HHH. The hidden data is coin 0's result. Estimate P0, P1 and P2. http://ai

Keyboard events java

本小妞迷上赌 提交于 2019-12-13 08:10:40
问题 I have recently started learning java.I want to make a game like https://sites.google.com/site/millseagles/home/Games/multiplayer/tron I have made it in c++ once using a simple graphics lib. I have the graphics part down i plan to use small images and use http://horstmann.com/sjsu/graphics/ this basic graphics lib.I can't figure out keyboard input i want it so if you press an arrow the picture adds a small green square(I have a green.png).I can't figure out to use keyboard listeners.I get all

What Are Functions/Closures/Lambdas, From A Data Structures Perspective?

≡放荡痞女 提交于 2019-12-13 07:39:00
问题 I got into a discussion the other day about some nitty-gritty details of programming languages, and one topic that was brought up was what a function (or closure/lambda/etc.) actually 'is' from a data structures perspective. To be clear, I am not asking what functions do or how they are used, but rather how they are represented in code 'behind the scenes'. When a function is 'called', what is happening as the code executes? Is a function a struct or object of some kind that is passed around

Finding Strongly Connected Components?

北慕城南 提交于 2019-12-13 04:34:35
问题 My book defines a method to find the strongly connected components of a directed graph in linear time. In addition several other algorithms to find strongly connected components (i.e. Tarjan's algorithm) is also able to find the components in linear time. However all of these algorithms require the vertices of the graph to be ordered in decreasing post values (time the vertex is left). Common ordering algorithms such as Mergesort take O(n log n) time. Therefore how do these algorithms manage