Dating agency: Difference between revisions

Added FreeBASIC
(Added 11l)
(Added FreeBASIC)
 
(2 intermediate revisions by 2 users not shown)
Line 22:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V sailors = [‘Adrian’, ‘Caspian’, ‘Dune’, ‘Finn’, ‘Fisher’, ‘Heron’, ‘Kai’, ‘Ray’, ‘Sailor’, ‘Tao’]
 
V ladies = [‘Ariel’, ‘Bertha’, ‘Blue’, ‘Cali’, ‘Catalina’, ‘Gale’, ‘Hannah’, ‘Isla’, ‘Marina’, ‘Shelly’]
Line 39:
print(‘ Sailor ’sailor‘ should take an offer to date her.’)
E
print(‘Dating service should NOT offer a date with ’lady)</langsyntaxhighlight>
 
{{out}}
Line 71:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang="factor">USING: formatting io kernel math math.primes math.vectors
prettyprint qw sequences sets ;
 
Line 104:
lovable ladies. nl
sailor "But just between us, only the following ladies are compatible with %s:\n" printf
compatible ladies.</langsyntaxhighlight>
{{out}}
<pre>
Line 131:
Robin
</pre>
 
=={{header|FreeBASIC}}==
{{trans|Phix}}
<syntaxhighlight lang="vbnet">Function digitalRoot(n As Integer) As Integer
Assert(n >= 0)
While n > 9
Dim As Integer tot = 0
While n > 0
tot += (n Mod 10)
n \= 10
Wend
n = tot
Wend
Return n
End Function
 
Type Lady
nombre As String
Declare Function lovable() As Integer
Declare Function love(s As Any Ptr) As Integer
End Type
 
Function Lady.lovable() As Integer
Return (Asc(this.nombre) Mod 2)
End Function
 
Function Lady.love(s As Any Ptr) As Integer
Return (digitalRoot(Asc(this.nombre)) > 4)
End Function
 
Function newLady(nombre As String) As Lady
Dim As Lady l
l.nombre = nombre
Return l
End Function
 
Function ladyNames(ladies() As Lady) As String
Dim As String res = ""
For i As Integer = Lbound(ladies) To Ubound(ladies)
If ladies(i).nombre <> "" Then res &= ladies(i).nombre & ", "
Next i
Return Left(res, Len(res)-2) ' remove last comma and space
End Function
 
Type Marinero
nombre As String
Declare Function love(l As Any Ptr) As Integer
End Type
 
Function Marinero.love(l As Any Ptr) As Integer
Return Cast(Lady Ptr, l)->lovable()
End Function
 
Dim As String nombres(9) = {"Ada", "Crystal", "Elena", "Euphoria", "Janet", "Julia", "Lily", "Miranda", "Perl", "Ruby"}
Dim As Lady ladies(Ubound(nombres))
For i As Integer = Lbound(nombres) To Ubound(nombres)
ladies(i) = newLady(nombres(i))
Next i
Dim As Marinero sailor
sailor.nombre = "Pascal"
Dim As Integer eligiblesCount = 0
Dim As Lady eligibles(Ubound(ladies))
 
For i As Integer = Lbound(ladies) To Ubound(ladies)
If ladies(i).love(@sailor) Then
eligibles(eligiblesCount) = ladies(i)
eligiblesCount += 1
End If
Next i
 
Print "lady loves sailor lovable"
Print "---- ------------ -------"
 
For i As Integer = Lbound(ladies) To Ubound(ladies)
Print Using "\ \ & &"; ladies(i).nombre; Iif(ladies(i).love(@sailor), "True ", "False"); Iif(ladies(i).lovable(), "True ", "False")
Next i
 
Print !"\nBased on this analysis:"
Print "The dating agency should suggest the following ladies:"
Print ladyNames(eligibles())
 
Print !"\nand "; sailor.nombre; " should offer to date these ones:"
Print ladyNames(eligibles())
 
Sleep</syntaxhighlight>
 
=={{header|Julia}}==
{{trans|Python}}
<langsyntaxhighlight lang="julia">sailors = ["Adrian", "Caspian", "Dune", "Finn", "Fisher", "Heron", "Kai",
"Ray", "Sailor", "Tao"]
 
Line 156 ⟶ 241:
end
end
</langsyntaxhighlight>{{out}}
<pre>
Dating service should NOT offer a date with Ariel
Line 186 ⟶ 271:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
 
Line 219 ⟶ 304:
$matches{$_} < $max or $max = $matches{$_} for keys %matches;
print 'Best match(s): ' . join(', ', sort grep { $matches{$_} == $max } keys %matches) . "\n\n";
}</langsyntaxhighlight>
{{out}}
<pre>Elizabeth will like: Adam, Conrad, Ian, Jake, Larry, Bob, Drew, Quincy, Mike, Victor
Line 247 ⟶ 332:
Booleans in Phix are just integers, and need to be printed with %t rather than %s.
Of course all this is open source, yada-yada-ya.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">structs</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 318 ⟶ 403:
<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;">"\nand %s should offer to date these ones:\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">sailor</span><span style="color: #0000FF;">.</span><span style="color: #000000;">name</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;">"%s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lady_names</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #000000;">eligibles</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sailor_love</span><span style="color: #0000FF;">)))</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 344 ⟶ 429:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">"""
Jokes about courtesans aside, the selection process is by the letters of the names.
If the integer corresponding to the ASCII character of the first letter of the
Line 372 ⟶ 457:
else:
print("Dating service should NOT offer a date with", lady)
</langsyntaxhighlight>{{out}}
<pre>
Dating service should NOT offer a date with Ariel
Line 403 ⟶ 488:
Welcome to the '''Arbitrary and Capricious Dating Agency''', (We don't use zodiacs, but we're just as arbitrary!)
 
<syntaxhighlight lang="raku" perl6line>use Digest::SHA1::Native;
 
my %ladies = < Alice Beth Cecilia Donna Eunice Fran Genevieve Holly Irene Josephine Kathlene Loralie Margaret
Line 430 ⟶ 515:
say 'Best match(s): ' ~ %matches.grep(*.value == %matches.values.max)».key.sort.join(', ');
say '';
}</langsyntaxhighlight>
 
<pre> Ahab will like: Eunice, Ursula, Irene, Holly, Fran, Genevieve, Zoey, Donna, Cecilia, Alice
Line 447 ⟶ 532:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int, Nums
import "./fmt" for Fmt
 
Line 510 ⟶ 595:
System.print(eligibles)
System.print("\nand %(sailor) should offer to date these ones:")
System.print(eligibles.where { |e| sailor.love(e) }.toList)</langsyntaxhighlight>
 
{{out}}
2,130

edits