logic

What can be the efficient approach to solve the 8 puzzle problem?

只愿长相守 提交于 2019-12-03 04:43:53
问题 The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent (horizontally and vertically) tile. The objective in the game is to begin with an arbitrary configuration of tiles, and move them so as to get the numbered tiles arranged in ascending order either running around the perimeter of the board or ordered from

How to prove excluded middle is irrefutable in Coq?

烈酒焚心 提交于 2019-12-03 00:20:54
I was trying to prove the following simple theorem from an online course that excluded middle is irrefutable, but got stuck pretty much at step 1: Theorem excluded_middle_irrefutable: forall (P:Prop), ~~(P \/ ~ P). Proof. intros P. unfold not. intros H. Now I get: 1 subgoals P : Prop H : P \/ (P -> False) -> False ______________________________________(1/1) False If I apply H , then the goal would be P \/ ~P , which is excluded middle and can't be proven constructively. But other than apply , I don't know what can be done about the hypothesis P \/ (P -> False) -> False : implication -> is

What is the combinatory logic equivalent of intuitionistic type theory?

我与影子孤独终老i 提交于 2019-12-03 00:11:27
问题 I recently completed a university course which featured Haskell and Agda (a dependent typed functional programming language), and was wondering if it was possible to replace lambda calculus in these with combinatory logic. With Haskell this seems possible using the S and K combinators, thus making it point-free. I was wondering what the equivalent was for Agda. I.e., can one make a dependently typed functional programming language equivalent to Agda without using any variables? Also, is it

C++ interview preparation [closed]

对着背影说爱祢 提交于 2019-12-03 00:01:51
问题 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 8 years ago . I have a Phone interview coming up next with with a company which works in financial software industry. The interview is mainly going

Split down a number in seconds to days, hours, minutes, and seconds?

一曲冷凌霜 提交于 2019-12-02 23:50:37
I've heard that it's possible to accomplish this using the modulus % operator present in most programming languages. The real question is, how? I'm unfamiliar with how modulus works, so I've had difficulties using it in the past. Given the present time here in seconds since 1970, 1307758473.484 , how can I calculate how many years that is, days that is, hours that is, and minutes that is using modulus? I'm essentially looking to format it like this: "5 years, 10 days, 12 hours, 7 minutes, and 18.56 seconds". How would I do this? I'm really interested in learning the logic behind this and not

What are some practical applications of an FPGA?

こ雲淡風輕ζ 提交于 2019-12-02 21:50:39
I'm super excited about my program powering a little seven-segment display, but when I show it off to people not in the field, they always say "well what can you do with it?" I'm never able to give them a concise answer. Can anyone help me out? flolo First: They don't need to have volatile memory. Indeed the big players (Xilinx, Altera) usually have their configuration on-chip in SRAM, so you need additional EEPROM/Flash/WhatEver(TM) to store it outside. But there are others, e.g. Actel is one big player that come to mind, that has non-volatile configuration storage on their FPGAs (btw. this

Write code to convert given number into words (eg 1234 as input should output one thousand two hundred and thirty four)

我怕爱的太早我们不能终老 提交于 2019-12-02 19:52:22
Write C/C++/Java code to convert given number into words. eg:- Input: 1234 Output: One thousand two hundred thirty-four. Input: 10 Output: Ten Does it require a complete switch case for digits 0 to 10. Adding "teen" after every number name (eg: 14: four "teen".) from 14 to 19. And than adding "ty" and the digits name for a number in the range 20 to 99. And so on. I think there must be some far better approach for solving this. C code is preferred. pr6989 #include<iostream> using namespace std; void expand(int); int main() { int num; cout<<"Enter a number : "; cin>>num; expand(num); } void

How to determine if a date range occurs any time within another date range?

心不动则不痛 提交于 2019-12-02 19:46:59
I have an Event table that specifies a date range with start_date and end_date fields. I have another date range, specified in code, that defines the current week as 'week_start' and 'week_end'. I'd like to query all Events for the week. The cases seem to be: Event begins and ends within the week Event begins before the week, but ends within the week Event begins within the week, but ends after the week Event begins before the week and also ends after the week Events that neither reside within, nor overlap the week at all are ignored I'm attempting to come up with a query that can handle all

Logical condition while subsetting not giving correct values

核能气质少年 提交于 2019-12-02 18:59:25
问题 I wanted to subset data frame project I was working with, using a logical. I am getting a paradoxical result. The part of the logical preceding the ROLL.NO. argument is irrelevant to the question. Sorry, I could not give a reproducible example. Do let me know how can I make this question reproducible without having to show the entire 393 entries of the relevant columns in my data frame. D14 and DC31 are simple integer values, with some values being NA . culprits<-project$ROLL.NO.[(project

highest palindrome with 3 digit numbers in python

故事扮演 提交于 2019-12-02 18:37:21
In problem 4 from http://projecteuler.net/ it says: 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. I have this code here def isPalindrome(num): return str(num) == str(num)[::-1] def largest(bot, top): for x in range(top, bot, -1): for y in range(top,bot, -1): if isPalindrome(x*y): return x*y print largest(100,999) It should find the largest palindrome, it spits out 580085 which I believe to be correct, but project euler doesn't think