Cheryl's birthday: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 27:
* [https://en.wikipedia.org/wiki/Tuple_relational_calculus, Tuple Relational Calculus]
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<syntaxhighlight lang="11l">T Date
String month
Int day
Line 105 ⟶ 104:
=={{Header|Ada}}==
{{trans|C}}
<syntaxhighlight lang=Ada"ada">with Ada.Text_IO; use Ada.Text_IO;
 
procedure Main is
Line 237 ⟶ 236:
JULY, 16
</pre>
 
 
 
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
Line 865 ⟶ 861:
{{Out}}
<pre>"[('july', '16')]"</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">dates: [
[May 15] [May 16] [May 19]
[June 17] [June 18]
Line 919 ⟶ 914:
 
Cheryl's birthday: [July 16]</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang=AutoHotkey"autohotkey">oDates:= {"May" : [ 15, 16, 19]
,"Jun" : [ 17, 18]
,"Jul" : [14, 16]
Line 976 ⟶ 970:
{{out}}
<pre>Jul 16</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f CHERYLS_BIRTHDAY.AWK [-v debug={0|1}]
#
Line 1,084 ⟶ 1,077:
07/16
</pre>
 
=={{header|C}}==
{{trans|C#}}
<syntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
 
Line 1,218 ⟶ 1,210:
3 remaining.
Jul, 16</pre>
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">public static class CherylsBirthday
{
public static void Main() {
Line 1,257 ⟶ 1,248:
(July, 16)
</pre>
 
=={{header|C++}}==
{{trans|Go}}
<syntaxhighlight lang="cpp">#include <algorithm>
#include <iostream>
#include <vector>
Line 1,373 ⟶ 1,363:
{{out}}
<pre>Cheryl's birthday is Jul 16</pre>
 
=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">
;; Author: Amir Teymuri, Saturday 20.10.2018
 
Line 1,406 ⟶ 1,395:
(cheryls-birthday *possible-dates*) ;; => ((16 . JULY))
</syntaxhighlight>
 
=={{header|D}}==
<syntaxhighlight lang="d">import std.algorithm.iteration : filter, joiner, map;
import std.algorithm.searching : canFind;
import std.algorithm.sorting : sort;
Line 1,450 ⟶ 1,438:
{{out}}
<pre>jul 16</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
//Find Cheryl's Birthday. Nigel Galloway: October 23rd., 2018
type Month = |May |June |July |August
Line 1,467 ⟶ 1,454:
[[(July, 16)]]
</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: assocs calendar.english fry io kernel prettyprint
sequences sets.extras ;
 
Line 1,499 ⟶ 1,485:
July 16
</pre>
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
 
import (
Line 1,602 ⟶ 1,587:
Cheryl's birthday is July 16
</pre>
 
=={{header|Groovy}}==
{{trans|Java}}
<syntaxhighlight lang="groovy">import java.time.Month
 
class Main {
Line 1,685 ⟶ 1,669:
There are 1 candidates remaining.
Cheryl's birthday is JULY 16</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-}
 
import Data.List as L (filter, groupBy, head, length, sortOn)
Line 1,761 ⟶ 1,744:
{{Out}}
<pre>[("July","16")]</pre>
 
=={{header|J}}==
'''Solution:'''
<syntaxhighlight lang="j">Dates=: <;._2 noun define
15 May
16 May
Line 1,789 ⟶ 1,771:
isUniqueMonth=: (] e. uniqueMonth)/@getDayMonth NB. mask of dates with a month that has 1 unique day</syntaxhighlight>
'''Usage:'''
<syntaxhighlight lang="j"> isUniqueMonth keep isUniqueDayInMonth keep isMonthWithoutUniqueDay keep Dates
+-------+
|16 July|
Line 1,798 ⟶ 1,780:
The concepts here are the same, of course, it's just the presentation that's different.
 
<syntaxhighlight lang=J"j">possible=: cut;._2 'May 15, May 16, May 19, June 17, June 18, July 14, July 16, August 14, August 15, August 17,'
 
Albert=: {."1 NB. Albert knows month
Line 1,821 ⟶ 1,803:
 
This gives us the July 16 result we were expecting
 
=={{header|Java}}==
{{trans|D}}
<syntaxhighlight lang="java">import java.time.Month;
import java.util.Collection;
import java.util.List;
Line 1,916 ⟶ 1,897:
There are 1 candidates remaining.
Cheryl's birthday is JULY 16</pre>
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 2,097 ⟶ 2,077:
{{Out}}
<pre>[["July","16"]]</pre>
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
Line 2,104 ⟶ 2,083:
 
A Birthday is represented by a JSON object {month, day} where {month:0} represents January.
<syntaxhighlight lang="jq">def count(stream; cond):
reduce stream as $i (0; if $i|cond then .+1 else . end);
 
Line 2,172 ⟶ 2,151:
Cheryl's birthday is July 16.
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">const dates = [[15, "May"], [16, "May"], [19, "May"], [17, "June"], [18, "June"],
[14, "July"], [16, "July"], [14, "August"], [15, "August"], [17, "August"]]
Line 2,193 ⟶ 2,171:
Cheryl's birthday is July 16.
</pre>
 
=={{header|Kotlin}}==
{{trans|Go}}
<syntaxhighlight lang="scala">// Version 1.2.71
 
val months = listOf(
Line 2,252 ⟶ 2,229:
Cheryl's birthday is July 16
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">-- Cheryl's Birthday in Lua 6/15/2020 db
 
local function Date(mon,day)
Line 2,337 ⟶ 2,313:
3) After Bernard's revelation, Albert now knows, so month must be unique, leaving only:
July 16</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">opts = Tuples[{{"May"}, {15, 16, 19}}]~Join~Tuples[{{"June"}, {17, 18}}]~Join~Tuples[{{"July"}, {14, 16}}]~Join~Tuples[{{"August"}, {14, 15, 17}}];
monthsdelete = Select[GatherBy[opts, Last], Length /* EqualTo[1]][[All, 1, 1]];
opts = DeleteCases[opts, {Alternatives @@ monthsdelete, _}]
Line 2,349 ⟶ 2,324:
{{"July", 16}, {"August", 15}, {"August", 17}}
{{{"July", 16}}}</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang=Nim"nim">import tables
import sets
import strformat
Line 2,436 ⟶ 2,410:
 
So birthday date is July 16</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">sub filter {
my($test,@dates) = @_;
my(%M,%D,@filtered);
Line 2,480 ⟶ 2,453:
{{out}}
<pre>Cheryl's birthday is July 16.</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Cheryls_Birthday.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 2,517 ⟶ 2,489:
=== functional/filter ===
(this can also be found in demo\rosetta\Cheryls_Birthday.exw)
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">enum</span> <span style="color: #000000;">MONTH</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">DAY</span>
Line 2,568 ⟶ 2,540:
Cheryl's birthday is July 16th
</pre>
 
=={{header|Python}}==
===Functional===
{{Works with|Python|3}}
<syntaxhighlight lang="python">'''Cheryl's Birthday'''
 
from itertools import groupby
Line 2,702 ⟶ 2,673:
{{Out}}
<pre>[('July', '16')]</pre>
 
=={{header|R}}==
{{libheader|dplyr}}
<syntaxhighlight lang=R"r">options <- dplyr::tibble(mon = rep(c("May", "June", "July", "August"),times = c(3,2,2,3)),
day = c(15, 16, 19, 17, 18, 14, 16, 14, 15, 17))
 
Line 2,730 ⟶ 2,700:
<chr> <dbl>
1 July 16</pre>
 
=={{header|Racket}}==
{{trans|Kotlin}}
<syntaxhighlight lang="racket">#lang racket
 
(define ((is x #:key [key identity]) y) (equal? (key x) (key y)))
Line 2,768 ⟶ 2,737:
'((July 16))
</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
 
<syntaxhighlight lang="raku" line>my @dates =
{ :15day, :5month },
{ :16day, :5month },
Line 2,798 ⟶ 2,766:
{{out}}
<pre>Cheryl's birthday is July 16.</pre>
 
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX pgm finds Cheryl's birth date based on a person knowing the birth month, another */
/*──────────────────────── person knowing the birth day, given a list of possible dates.*/
$= 'May-15 May-16 May-19 June-17 June-18 July-14 July-16 August-14 August-15 August-17'
Line 2,839 ⟶ 2,806:
Cheryl's birthday is July 16
</pre>
 
=={{header|Ruby}}==
{{trans|C#}}
<syntaxhighlight lang="ruby">dates = [
["May", 15],
["May", 16],
Line 2,883 ⟶ 2,849:
["July", 16]</pre>
=={{header|Rust}}==
<syntaxhighlight lang="rust">
// This version is based on the Go version on Rosettacode
 
Line 3,007 ⟶ 2,973:
Cheryl's birthday is Birthday { month: July, day: 16 }
</pre>
 
=={{header|Scala}}==
==={{trans|D}}===
<syntaxhighlight lang="scala">import java.time.format.DateTimeFormatter
import java.time.{LocalDate, Month}
 
Line 3,066 ⟶ 3,031:
{{libheader|Scastie qualified}}
{{works with|Scala|2.13}}
<syntaxhighlight lang=Scala"scala">object Cheryl_sBirthday extends App {
 
private val possiblerDates = Set(
Line 3,099 ⟶ 3,064:
println(clou3)
}</syntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Raku}}
<syntaxhighlight lang="ruby">func f(day, month) {
Date.parse("#{day} #{month}", "%d %B")
}
Line 3,134 ⟶ 3,098:
Cheryl's birthday is July 16.
</pre>
 
=={{header|Swift}}==
 
{{trans|Kotlin}}
 
<syntaxhighlight lang="swift">struct MonthDay: CustomStringConvertible {
static let months = [
"January", "February", "March", "April", "May", "June",
Line 3,199 ⟶ 3,162:
 
<pre>Cheryl's birthday is July 16</pre>
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">Private Sub exclude_unique_days(w As Collection)
Dim number_of_dates(31) As Integer
Dim months_to_exclude As New Collection
Line 3,262 ⟶ 3,224:
End Sub</syntaxhighlight>{{out}}
<pre>July 16</pre>
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<syntaxhighlight lang="vbnet">Module Module1
 
Structure MonDay
Line 3,316 ⟶ 3,277:
3 remaining.
(July, 16)</pre>
 
=={{header|Vlang}}==
{{trans|Go}}
<syntaxhighlight lang="vlang">import time
 
struct Birthday {
Line 3,418 ⟶ 3,378:
Cheryl's birthday is July 16
</pre>
 
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascript">var Months = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
Line 3,476 ⟶ 3,435:
Cheryl's birthday is July 16
</pre>
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">dates:=T(T("May", 15), T("May", 16), T("May", 19),
T("June", 17), T("June", 18),
T("July", 14), T("July", 16),
10,343

edits