Murder puzzle in ASP - answer-set-programming

So under the tag prolog I found this puzzle (original post) and I thought: this would be even better in ASP. So I put this here as a question for anyone who wants to solve a puzzle with me. I will answer this question as soon as I found a solution myself, and I would be happy to compare my code with yours. Thank you.
jean was killed on Tuesday; the only suspects are:
Luc, Paul, Alain, Bernard and Louis.
The rules to follow are:
The murderer is somebody who has a motive to kill jean, who owns a
gun, and who does not have an alibi for Tuesday.
An alibi provided by a person who is not trustworthy is not
accepted.
Somebody has a motive to kill jean if he has a special interest in
killing jean or he wants revenge.
Somebody has a special interest in killing jean is he is the
beneficiary of jean’s fortune, or if he owns money to jean, or if jean
surprised him committing a crime.
Here are the facts established by the investigation:
Luc has an alibi for Tuesday given by Bernard
Paul has an alibi for Tuesday given by Bernard
Louis has an alibi for Tuesday given by Luc
Alain has an alibi for Thursday given by Luc
Alain is not a trustworthy person
Paul wants to take revenge on Jean
Luc wants to take revenge on Jean
Bernard is the beneficiary of Jean’s fortune
Jean is the beneficiary of Louis’s fortune
Louis owns money to Jean
Luc owns money to Jean
Jean has seen Alain committing a crime
Luc owns a gun
Louis owns a gun
Alain owns a gun

person(luc; paul; alain; bernard; louis).
alibi(luc,tuesday,bernard).
alibi(paul,tuesday,bernard).
alibi(louis,tuesday,luc).
alibi(alain,thurday,luc).
ntw(alain).
revenge(paul,jean).
revenge(luc,jean).
beneficiary(bernard, jean).
beneficiary(jean, louis).
owns(louis,jean).
owns(luc,jean).
seen(jean,alain).
gun(luc;louis;alain).
{murderer(M):person(M)} == 1.
murderer(M) :- person(M), motiv(M,jean), gun(M), not validalibi(M,tuesday,_).
validalibi(M,D,A) :- alibi(M,D,A), tw(A).
{ntw(P);tw(P)} == 1:- person(P).
motiv(P,O) :- revenge(P,O).
motiv(P,O) :- interest(P,O).
interest(P,O) :- beneficiary(P,O).
interest(P,O) :- owns(P,O).
interest(P,O) :- seen(O,P).
#show tw/1.
#show murderer/1.
My solution assumes that there is only one murderer and every person is either trustworthy (tw/1) or not (ntw/1). The output is
Answer: 1
murderer(alain) tw(bernard) tw(luc) tw(paul)
Answer: 2
murderer(alain) tw(bernard) tw(luc) tw(paul) tw(louis)
Answer: 3
murderer(alain) tw(bernard) tw(luc)
Answer: 4
murderer(alain) tw(bernard) tw(luc) tw(louis)
SATISFIABLE
Which more or less states: if there is only one murderer then it is Alain and it does not matter if Paul or Louis are trustworthy.

I tried this problem , and and this is my solution . I hope it will help you and if does , so please click on check and rank solution.
alibi(luc,bernard,tuesday).
alibi(paul,bernard,tuesday).
alibi(louis,luc,tuesday).
alibi(alain,luc,thursday).
notrust(alain).
revenge(paul,jean).
revenge(luc,jean).
benefit(bernard,jean).
benefit(lean,louis).
owns(louis,jean).
owns(luc,jean).
crime_seen(alain,jean).
gun(luc).
gun(louis).
gun(alain).
special_interest(X,jean):- benefit(X,jean);owns(X,jean);crime_seen(X,jean).
true_alibi(X):- alibi(X,Y,tuesday), \+ notrust(Y).
motive(X,jean):- special_interest(X,jean);revenge(X,jean).
murderer(X,jean):- gun(X),motive(X,jean),\+ true_alibi(X).
solve(X):-murderer(X,jean).

Related

Multiple results when identifying

When IDing the song "Love Invaders - Fatima Yamah" I get the below results:
python test.py ~/MusicID/File5.mp3
https://pastebin.com/YAdAru7A
None of which are actually correct, although some of the scores report 100. How can one song report back so many results? Is there a way to fix this?
Thanks
Thanks for pointing out this issue, it seems we don't have the song "Love Invaders - Fatima Yamah" in our database (but we've added it), we are looking to the issue of score 100. You can try again now. Sorry for the inconvenience.

How to update/display data (for example image) based on the time range?

For example I want the Image named "Something" to be displayed from 9:00 till 11:00. Then, Image will be changed, and a new Image "Something else" will be displayed from 11:00 till 13:00 and so on.
I found some related solutions : here and here, but they have an old syntax and a bit different purpose.
Could You help me please.
Thank You in advance.
Found the solution, when You are using calendar date components and using the switch for hour and minutes.

Is there any audio ads for iPhone audio apps?

my app is like podcast for web articles. https://apps.apple.com/app/id1273954643
I plan to make a free version and am curious if there is audio ads for iPhone apps.
Since most users of my app don't see the screen, banner ads doesn't fit well.
I want to insert audio ads like spotify.
I checked http://www.medialets.com/ and http://www.greystripe.com/, but their show cases
are quite vague. I sent emails to them, but no reply yet.
Any help will be greatly appreciated.
Thanks!
Hmmm... this seems like an awesome business opportunity that hasn't been properly executed yet.
I have also seen mentions of audio ads being served up into client iPhone apps by TargetSpot.
I really like your idea.And after searching for a while i came across this helpful tutorial-
Though its kind of commercial but hope it will help you.
http://advertising.about.com/od/smallbusinesscampaigns/a/podcastweb.htm
if you're willing to use an API. You could use something like this
https://docs.api.audio/recipes/programmatic-audio-ads
#Check that you are using python 3.8 or further
#pip install -U aflr
import aflr
aflr.api_key = "APIKEY"
audience = [
{"number": "33", "location": "Buckingham"},
{"number": "22", "location": "Sunshine"},
]
text = """
<<soundSegment::effect1>>
<<sectionName::hello>>
If you have any plans for today, cancel them!
<<soundSegment::intro>>
<<sectionName::hello2>>
This really is the final call for {{location}} Hyundai's massive clear out sale! Only until midnight tonight, so come on down!
<<soundSegment::main>>
<<sectionName::main>>
We're clearing out all remaining 2020 Hyundais at Ottawa's top volume Hyundai dealers. These are the last days for clear out pricing and amazing clear out incentives. Zero percent financing for up to 84 months, and up to 7700 in cash price adjustments on all 2020 Hyundais at Hyundai on {{location}}. Pick one of the {{number}} Santa Fays in stock, a family-sized SUV with all-wheel drive and back-up cameras from just $85 weekly, zero down!
It's the easiest time to get into a new Hyundai, but these deals won't be around for long, ONLY until midnight TONIGHT!
<<soundSegment::outro>>
<<sectionName::outro>>
Get into a new Hyundai today. At {{location}} Hyundai, better cars for passionate car drivers. <break time="1s"/>
"""
script = aflr.Script().create(scriptText=text, scriptName="helloworld", moduleName="hello", projectName="hello")
print(script)
for item in audience:
r = aflr.Speech().create(
scriptId=script.get("scriptId"),
voice="en-US-GuyNeural",
speed=120,
silence_padding=0,
audience=[item],
)
print(r)
template = "hotwheels"
print(template)
for item in audience:
r = aflr.Mastering().create(
scriptId=script.get("scriptId"), soundTemplate=template, audience=[item]
)
print(r)
url = aflr.Mastering().download(
scriptId=script.get("scriptId"),
parameters=item,
destination=".",
)
print(f"✨ Mastered file for template {template} ✨")
print(url)
```
That way you could serve this, this is in python. You could also do it in Swift (but there's no sdk for this atm you'd need to write it yourself).
Disclamier - I work for www.api.audio

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date rolls over from December 26th to December 27th, the year changes to 2010.
I even rolled it forward to 2011... and it changes when December 25th changes to the 26th.... but wait... in 2012, it correctly rolls over on December 31 - January 1... and then its back to 29th-30th in 2013. Is there some kind of astronomical phenomenon I am not aware of going on or does Apple run on some crazy Heechee calendar I don't know of? The calendar app works correctly...
The most likely explanation is I am missing something so obvious that I will slap myself when I realize it. But hey, I haven't slept in... wow I don't remember if its been two days or three. Take pity and help me out here.
UPDATE: So maybe it wasn't something simple. Still looking for an answer here! Am I really the only person who has experienced this?? I'll bet when the end of December rolls around, more people will hit the same roadblock.
UPDATE2: Anyone? Still looking, still not finding...
UPDATE3: Still haven't found a solution. Come on! This is an interesting puzzle!
UPDATE4: Still no answer found. I have submitted the app and it is now in the appstore. Would still like to see this problem solved so I can update the app.
There may be this problem, that when you are on the last week of the month and the week has fewer than 7 days left in current month, then perhaps the API treated the week as the first week of the next month. Since december of 2012 has already 7 days in its last week there is no problem in that month.
I was getting the same problem here, and I solved it.
- (int) currentWeekOfMonth
{
return CFCalendarGetOrdinalityOfUnit (
CFCalendarCopyCurrent(),
kCFCalendarUnitWeek,
kCFCalendarUnitMonth,
[self absoluteTime]);
}
my requirement is to show week number and for this i calculate the week number of first week of month and the add this to the total number of week in month.
int currentWeekNumberInYear = [_calendarInfo currentWeekOfYear];
int currentWeekNumberInMonth = [_calendarInfo currentWeekOfMonth];
currentWeekNumberInYear = currentWeekNumberInYear-currentWeekNumberInMonth +1;
currentWeekNumberInYear = currentWeekNumberInYear<0 ? (NSInteger)[_calendarInfo weeksInMonth] ==5 ?49:48 : currentWeekNumberInYear;
I hope it will be useful to you.
Turns out its the Date format string used to set up the NSDateFormatter that was causing this for me.
"yyyy" corresponds to the 4-digit year, while YYYY corresponds to the year starting from the Sunday of the 1st week of year. Why anyone would want this is anyone's guess, and it would really help if Apple provided a link to their list of format specifiers, but there you go.
Just make sure your format string has the year component in lowercase and it should be sorted.
This post on TUAW describes a similar problem in PhotoBooth on Mac OS X:
http://www.tuaw.com/2009/12/29/beware-photo-booth-time-stamps-its-a-bug-not-a-feature/
One commenter agrees with vikas that it's an end-of-week issue.

Count-Up Timer Required, iPhone Programming

I am new to iPhone programming so am hoping someone can help me out here. I have searched the web, but can only find information on count down timers.
What I am looking to do is start a count up timer when a button is pressed and then stop it when a certain value drops by, say 5, and finally display that time. I can display values on screen once I have them, but getting the time in the first place is proving difficult for me.
I apologize if this is a simple question, but I look forward to reading your responses.
Thanks in advance,
stu
NSDate will provide the current date. You can use - (NSTimeInterval)timeIntervalSinceNow
to get the time since the first call and now.
There's no difference between an up-counter and down-counter. Just change the order of your subtraction.
UpcounterElapsedTime = UpcounterCurrentTime - UpcounterStartTime;
DowncounterElapsedTime = DownCounterStartTime - DownCounterCurrentTime;