20
4
Write a full program with a source code of 256 bytes or less that looks at an image of a flag and determines what country that flag is from. A zip file containing the 196 different flags in the challenge can be downloaded from here. Source: [Flagpedia]. These 196 flag images are the only inputs your program has to handle.
Your program will take no input. The flag image will be in the same directory as your program and named "f.png". Your program will open this file, identify it, and print the two letter abbreviation for that country. If you use a language that can't open files, it's also acceptable to run your program as ./program < f.png
.
Each flag file is named the same as the expected output. All output above 2 letters will be ignored.
Here is a list of all the outputs/filenames:
ad, ae, af, ag, al, am, ao, ar, at, au, az, ba, bb, bd, be, bf, bg, bh, bi, bj,
bn, bo, br, bs, bt, bw, by, bz, ca, cd, cf, cg, ch, ci, cl, cm, cn, co, cr, cu,
cv, cy, cz, de, dj, dk, dm, do, dz, ec, ee, eg, eh, er, es, et, fi, fj, fm, fr,
ga, gb, gd, ge, gh, gm, gn, gq, gr, gt, gw, gy, hn, hr, ht, hu, id, ie, il, in,
iq, ir, is, it, jm, jo, jp, ke, kg, kh, ki, km, kn, kp, kr, ks, kw, kz, la, lb,
lc, li, lk, lr, ls, lt, lu, lv, ly, ma, mc, md, me, mg, mh, mk, ml, mm, mn, mr,
mt, mu, mv, mw, mx, my, mz, na, ne, ng, ni, nl, no, np, nr, nz, om, pa, pe, pg,
ph, pk, pl, pt, pw, py, qa, ro, rs, ru, rw, sa, sb, sc, sd, se, sg, si, sk, sl,
sm, sn, so, sr, st, sv, sy, sz, td, tg, th, tj, tl, tm, tn, to, tr, tt, tv, tw,
tz, ua, ug, us, uy, uz, va, vc, ve, vn, vu, ws, ye, za, zm, zw,
Scoring
Here is a short python script that I will use to score each submission.
import os
import subprocess
import random
botlist = []
with open("bots.txt") as bots:
for line in bots:
line = line.split(", ")
if len(line) >= 2:
botLine = line + [0]
botlist.append(botLine)
files = os.listdir(os.getcwd() + "/flags")
random.shuffle(files)
def test(bot_command):
score = 0
for filename in files:
command = "COPY flags\\{} f.png".format(filename)
os.system(command)
print bot_command
result = subprocess.check_output(bot_command, shell = True)
if result[:2] == filename[:2]:
score += 1
return score
for i in range(len(botlist)):
command = botlist[i][1]
botlist[i][2] = test(command)
with open("output.txt", "w+") as output:
for bot in botlist:
output.write("{} got a score of {}.".format(bot[0], bot[2]))
os.system("del f.png")
Your score is the total number of flags correctly identified. In case of a tie, the earlier submission wins.
Rules
For my testing convenience, any language with a freely available interpreter/compiler for Windows 10 or Ubuntu can be used.
Image processing libraries are allowed, but any builtins related to flags or countries are not allowed. (cough Mathematica cough)
Please provide the full command needed to run your program along with links to any necessary libraries.
Submissions may not interact with any file except "f.png".
I don't have any hard time-limit on submissions, but please keep it relatively quick. I don't want the scoring script to take hours.
4The byte limit is really low. Just storing the 196 two-letters codes uncompressed requires 392 bytes – edc65 – 2016-03-26T22:48:09.460
2@edc65 The point is that you're only going to get a small number of the flags. – isaacg – 2016-03-26T23:14:32.000
1@edc65 I intentional picked a number that would make a perfect score of 196 basically impossible. It's more about compression of recognizing images then codegolf. – James – 2016-03-26T23:18:09.410
Just double checking - can we only use the
./program < f.png
option if the language has no way of reading files, or can we also use it even if the language can read files? (Apparently CJam can read from files, which I didn't know) – Sp3000 – 2016-03-27T17:22:46.467These 196 flag images are the only inputs your program has to handle then you say Your program will take no input. Does that mean that the one file f.png will be one of the those 196. So the program cannot reference those zipped files? Just f.png – Matt – 2016-03-27T17:25:19.357
@Matt No, it means that one of the files will be copied over to "f.png" before your program is callled, then this will be repeated for each of the 196 flag images. – James – 2016-03-27T19:06:55.743