Cheryl's birthday: Difference between revisions
m
syntax highlighting fixup automation
No edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 31:
{{trans|Nim}}
<
String month
Int day
Line 91:
print()
print(‘So birthday date is ’month‘ ’day‘.’)</
{{out}}
Line 105:
=={{Header|Ada}}==
{{trans|C}}
<
procedure Main is
Line 229:
print_answer;
end Main;</
{{out}}
<pre>
Line 241:
=={{header|AppleScript}}==
<
use framework "Foundation"
use scripting additions
Line 862:
filteredArrayUsingPredicate:(ca's ¬
NSPredicate's predicateWithFormat:"0 < length")) as list
end |words|</
{{Out}}
<pre>"[('july', '16')]"</pre>
Line 868:
=={{header|Arturo}}==
<
[May 15] [May 16] [May 19]
[June 17] [June 18]
Line 900:
print ["\t-> remaining:" dates]
print ["\nCheryl's birthday:" first dates]</
{{out}}
Line 921:
=={{header|AutoHotkey}}==
<
,"Jun" : [ 17, 18]
,"Jul" : [14, 16]
Line 973:
else
return m " " obj.1
}</
{{out}}
<pre>Jul 16</pre>
=={{header|AWK}}==
<
# syntax: GAWK -f CHERYLS_BIRTHDAY.AWK [-v debug={0|1}]
#
Line 1,064:
printf("\n\n")
}
</syntaxhighlight>
{{out}}
<pre>
Line 1,087:
=={{header|C}}==
{{trans|C#}}
<
#include <stdio.h>
Line 1,212:
printAnswer();
return 0;
}</
{{out}}
<pre>10 remaining.
Line 1,220:
=={{header|C sharp|C#}}==
<
{
public static void Main() {
Line 1,249:
}
}</
{{out}}
<pre>
Line 1,260:
=={{header|C++}}==
{{trans|Go}}
<
#include <iostream>
#include <vector>
Line 1,370:
return 0;
}</
{{out}}
<pre>Cheryl's birthday is Jul 16</pre>
=={{header|Common Lisp}}==
<
;; Author: Amir Teymuri, Saturday 20.10.2018
Line 1,405:
(cheryls-birthday *possible-dates*) ;; => ((16 . JULY))
</syntaxhighlight>
=={{header|D}}==
<
import std.algorithm.searching : canFind;
import std.algorithm.sorting : sort;
Line 1,447:
// print the result
writeln(birthDay.month, " ", birthDay.day);
}</
{{out}}
<pre>jul 16</pre>
=={{header|F_Sharp|F#}}==
<
//Find Cheryl's Birthday. Nigel Galloway: October 23rd., 2018
type Month = |May |June |July |August
Line 1,462:
let _,e = List.concat g |> List.groupBy fst |> fN
printfn "%A" e
</syntaxhighlight>
{{out}}
<pre>
Line 1,469:
=={{header|Factor}}==
<
sequences sets.extras ;
Line 1,494:
! print a date that looks like { { 16 7 } }
first first2 month-name write bl .</
{{out}}
<pre>
Line 1,501:
=={{header|Go}}==
<
import (
Line 1,596:
fmt.Println("Something went wrong!")
}
}</
{{out}}
Line 1,605:
=={{header|Groovy}}==
{{trans|Java}}
<
class Main {
Line 1,678:
}
}
}</
{{out}}
<pre>There are 10 candidates remaining.
Line 1,687:
=={{header|Haskell}}==
<
import Data.List as L (filter, groupBy, head, length, sortOn)
Line 1,758:
M.fromList $
((,) . fst . L.head) <*> fmap snd <$>
L.groupBy (on (==) fst) (L.sortOn fst xs)</
{{Out}}
<pre>[("July","16")]</pre>
Line 1,764:
=={{header|J}}==
'''Solution:'''
<
15 May
16 May
Line 1,787:
uniqueMonth=: ~.@] #~ (1=#)/.~ NB. list of months with 1 unique day
isUniqueMonth=: (] e. uniqueMonth)/@getDayMonth NB. mask of dates with a month that has 1 unique day</
'''Usage:'''
<
+-------+
|16 July|
+-------+</
===Alternative Approach===
Line 1,798:
The concepts here are the same, of course, it's just the presentation that's different.
<
Albert=: {."1 NB. Albert knows month
Line 1,818:
months=: {."1 possibleB
invalidmonths=: (1<#/.~months)#~.months
echo ;:inv (months e. months -. invalidmonths)#possibleB</
This gives us the July 16 result we were expecting
Line 1,824:
=={{header|Java}}==
{{trans|D}}
<
import java.util.Collection;
import java.util.List;
Line 1,909:
}
}
}</
{{out}}
<pre>There are 10 candidates remaining.
Line 1,918:
=={{header|JavaScript}}==
<
'use strict';
Line 2,094:
// MAIN ---
return main();
})();</
{{Out}}
<pre>[["July","16"]]</pre>
Line 2,104:
A Birthday is represented by a JSON object {month, day} where {month:0} represents January.
<
reduce stream as $i (0; if $i|cond then .+1 else . end);
Line 2,167:
end;
solve</
{{out}}
<pre>
Line 2,174:
=={{header|Julia}}==
<
[14, "July"], [16, "July"], [14, "August"], [15, "August"], [17, "August"]]
Line 2,189:
println("Cheryl's birthday is $(bday[2]) $(bday[1]).")
</
<pre>
Cheryl's birthday is July 16.
Line 2,196:
=={{header|Kotlin}}==
{{trans|Go}}
<
val months = listOf(
Line 2,246:
else
println("Something went wrong!")
}</
{{output}}
Line 2,254:
=={{header|Lua}}==
<
local function Date(mon,day)
Line 2,324:
if count(subset) > 1 then apply(subset, invalidate) end
end)
listValidChoices()</
{{out}}
<pre>Cheryl offers these ten choices:
Line 2,339:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
monthsdelete = Select[GatherBy[opts, Last], Length /* EqualTo[1]][[All, 1, 1]];
opts = DeleteCases[opts, {Alternatives @@ monthsdelete, _}]
removedates = Catenate@Select[GatherBy[opts, Last], Length /* GreaterThan[1]];
opts = DeleteCases[opts, Alternatives @@ removedates]
Select[GatherBy[opts, First], Length /* EqualTo[1]]</
{{out}}
<pre>{{"July", 14}, {"July", 16}, {"August", 14}, {"August", 15}, {"August", 17}}
Line 2,351:
=={{header|Nim}}==
<
import sets
import strformat
Line 2,427:
echo ""
echo fmt"So birthday date is {month} {day}."</
{{out}}
Line 2,438:
=={{header|Perl}}==
<
my($test,@dates) = @_;
my(%M,%D,@filtered);
Line 2,477:
my ($m, $d) = split '-', $dates[0];
print "Cheryl's birthday is $months[$m] $d.\n";</
{{out}}
<pre>Cheryl's birthday is July 16.</pre>
=={{header|Phix}}==
<!--<
<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,507:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">choices</span>
<!--</
Iterating backwards down the choices array simplifies element removal, or more accurately removes the need for "not increment i".<br>
Step 1&2 is months with unique days, step 3 is days with unique months, step 4 is unique months.
Line 2,517:
=== functional/filter ===
(this can also be found in demo\rosetta\Cheryls_Birthday.exw)
<!--<
<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,563:
<span style="color: #0000FF;">{</span><span style="color: #000000;">td</span><span style="color: #0000FF;">[</span><span style="color: #004600;">DT_MONTH</span><span style="color: #0000FF;">],</span><span style="color: #000000;">td</span><span style="color: #0000FF;">[</span><span style="color: #004600;">DT_DAY</span><span style="color: #0000FF;">]}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">choices</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Cheryl's birthday is %s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">td</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Mmmm ddth"</span><span style="color: #0000FF;">)})</span>
<!--</
{{out}}
<pre>
Line 2,572:
===Functional===
{{Works with|Python|3}}
<
from itertools import groupby
Line 2,699:
if __name__ == '__main__':
main()</
{{Out}}
<pre>[('July', '16')]</pre>
Line 2,705:
=={{header|R}}==
{{libheader|dplyr}}
<
day = c(15, 16, 19, 17, 18, 14, 16, 14, 15, 17))
Line 2,724:
for(i in unique(remaining$mon)){
if(sum(remaining$mon == i) == 1) {print(remaining[remaining$mon == i,])}
}</
{{Out}}
<pre># A tibble: 1 x 2
Line 2,733:
=={{header|Racket}}==
{{trans|Kotlin}}
<
(define ((is x #:key [key identity]) y) (equal? (key x) (key y)))
Line 2,762:
;; Albert now knows the answer too.
;; So the month must be unique within the remaining choices
[filter (unique albert)])</
{{out}}
Line 2,772:
(formerly Perl 6)
<syntaxhighlight lang=raku
{ :15day, :5month },
{ :16day, :5month },
Line 2,795:
my @months = <'' January February March April May June July August September October November December>;
say "Cheryl's birthday is { @months[$birthday<month>] } {$birthday<day>}.";</
{{out}}
<pre>Cheryl's birthday is July 16.</pre>
=={{header|REXX}}==
<
/*──────────────────────── 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,834:
end /*k*/
end /*j*/
return $</
{{out|output|text= when using the internal default input:}}
<pre>
Line 2,842:
=={{header|Ruby}}==
{{trans|C#}}
<
["May", 15],
["May", 16],
Line 2,876:
.map { |k,v| v }
.flatten
print dates</
{{out}}
<pre>10 remaining
Line 2,883:
["July", 16]</pre>
=={{header|Rust}}==
<
// This version is based on the Go version on Rosettacode
Line 3,002:
}
</syntaxhighlight>
{{out}}
<pre>
Line 3,010:
=={{header|Scala}}==
==={{trans|D}}===
<
import java.time.{LocalDate, Month}
Line 3,054:
printf(birthDay.format(DateTimeFormatter.ofPattern("MMMM dd")))
}
}</
{{out}}
<pre>July 16</pre>
Line 3,066:
{{libheader|Scastie qualified}}
{{works with|Scala|2.13}}
<
private val possiblerDates = Set(
Line 3,098:
println(clou3)
}</
=={{header|Sidef}}==
{{trans|Raku}}
<
Date.parse("#{day} #{month}", "%d %B")
}
Line 3,129:
}.group_by{ .month }.values.first_by { .len == 1 }[0]
say "Cheryl's birthday is #{birthday.fullmonth} #{birthday.day}."</
{{out}}
<pre>
Line 3,139:
{{trans|Kotlin}}
<
static let months = [
"January", "February", "March", "April", "May", "June",
Line 3,194:
}
print("Cheryl's birthday is \(birthday)")</
{{out}}
Line 3,201:
=={{header|VBA}}==
<
Dim number_of_dates(31) As Integer
Dim months_to_exclude As New Collection
Line 3,260:
exclude_non_unique_months v
Debug.Print v(1)(0); " "; v(1)(1)
End Sub</
<pre>July 16</pre>
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<
Structure MonDay
Line 3,310:
End Sub
End Module</
{{out}}
<pre>10 remaining.
Line 3,319:
=={{header|Vlang}}==
{{trans|Go}}
<
struct Birthday {
Line 3,412:
println("Something went wrong!")
}
}</
{{out}}
Line 3,421:
=={{header|Wren}}==
{{trans|Kotlin}}
<
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
Line 3,470:
} else {
System.print("Something went wrong!")
}</
{{out}}
Line 3,478:
=={{header|zkl}}==
<
T("June", 17), T("June", 18),
T("July", 14), T("July", 16),
Line 3,496:
// print birthday such that muliples are shown, if any
println("Cheryl's birthday is ",theDay.flatten().flatten().concat(" "));</
{{out}}
<pre>
|