CC BY-SA 3.0 by David Lazich

005: Colorized Rummy

Series:	CodeGolfings
Submission due:	Sat. Nov 28th 2020 at 3pm
Event:	Sat. Nov 28th 2020 at 4pm
Details:	005 CodeGolfing v0.2 [PDF]
Venue:	https://meet.jit.si/005CodeGolfing PW: v0x201
Contact:	max at vspace.one

NOTE: Previous description: 005 CodeGolfing v0.1 [PDF]

(some) Testcases

[
{ "in": "rkyb", "out": 0},
{ "in": "rkybky", "out": 0},
{ "in": "rkybr", "out": 1},
{ "in": "rrrkyb", "out": 1},
{ "in": "rrkkyyb", "out": 0},
{ "in": "rrkkyybb", "out": 0},
{ "in": "rrkkyy", "out": 0},
{ "in": "k", "out": 1},
{ "in": "kb", "out": 1},
{ "in": "kkbb", "out": 1}
]

Solutions

Ruby (>=2.7)

69B, max

Beschreibung: 005 Code Golfing Solution [pdf]

s=$*[0].chars.tally.values+[0,0,0].sort
exit(s[3]>=2*s[0]-s[1]-s[2])

Python

83B, chris

import sys
a,b,c,d=sorted(sys.argv[1].count(x) for x in "rybk")
1/(2*d-c<=a+b<=d*2)

Python

85B, max

import sys
c=sorted([sys.argv[1].count(x)for x in"yrbk"])
exit(c[0]<2*c[3]-c[1]-c[2])

Perl

86B, max

for(yrbk=~/./g){$r[$i++]=()=$ARGV[0]=~/$_/g}@r=sort@r;exit(@r[0]<2*@r[3]-@r[2]-@r[1])

Python

172B, m0rix

import sys
i=sys.argv[1]
l=sorted([i.count("b"),i.count("y"),i.count("r"),i.count("k")])
while l[0]!=l[3]and l[0]>=0:
l[1]-=1;l[2]-=1;l[3]-=1;l=sorted(l)
exit(l[0]!=l[3])

Python

226B, nikax

import sys
x=sys.argv[1]
y=[]
for l in ['b','y','k','r']:y+=[x.count(l)]
y.sort()
o=1
while y[0]!=0:
if y[2]<y[3]:y[2]+= 1
elif y[1]<y[3]:y[1]+= 1
else:break
y[0]-=1
if(y[1]==y[2]==y[3]):o=0
exit(o)

Tests not passed

PHP

105B, marc

<?php $s=$argv[1];$c=[0,0,0,0];foreach(str_split($s)as$x)$c[$x]-=1;sort($c);exit($c[3]>$c[0]*2-$c[1]-$c[2]);

Java

1.7KB, alexander

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class Alex {
private static ConcurrentHashMap<Integer, List<Character>> lists = new ConcurrentHashMap<>();
private static ConcurrentHashMap<Integer, Character> chars = new ConcurrentHashMap<>();
public static void main(String[] args) {
for (char c : args[0].toCharArray()) {
if (!(c == 'r' || c == 'y' || c == 'b' || c == 'k')) return;
chars.put(chars.size(), c);
}
lists.put(0, new ArrayList<>());
lists.get(0).add(chars.get(0));
chars.remove(0);
for (int i : chars.keySet()) {
for (int j : lists.keySet()) {
if (!lists.get(j).contains(chars.get(i)) && lists.get(j).size() < 3) {
lists.get(j).add(chars.get(i));
chars.remove(i);
} else if (chars.size() >= 3 && isEverythingMin()) {
lists.put(lists.size(), new ArrayList<>());
lists.get(lists.size() - 1).add(chars.get(i));
chars.remove(i);
}
}
}
for (int k : lists.keySet()) {
for (int l : chars.keySet()) {
if (!lists.get(k).contains(chars.get(l))) {
lists.get(k).add(chars.get(l));
chars.remove(l);
}
}
}
System.out.println((chars.size() > 0 ? "Error" : "Success"));
}
private static boolean isEverythingMin() {
for(int i : lists.keySet()) {
if(lists.get(i).size() < 3) {
return false;
}
}
return true;
}
}

Außer Konkurrenz

PHP

78B, chris,max

import sys
a,b,c,d=sorted(sys.argv[1].count(x) for x in"rybk")
1/(a>=2*d-b-c)

Preformance Award

FOLGT

~~DISCUSSION~~