Skip to content

Instantly share code, notes, and snippets.

@semahawk
Last active August 29, 2015 14:06
Show Gist options
  • Save semahawk/0d45b3883d90c4b86727 to your computer and use it in GitHub Desktop.
Save semahawk/0d45b3883d90c4b86727 to your computer and use it in GitHub Desktop.
*.cmi
*.cmx
*.o
gaidhlig
(*
* gàidhlig.ml
*
* Copyright (c) 2014 Szymon Urbaś <szymon.urbas@aol.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*)
open Printf
open Str
let (total, correct) = (ref 0, ref 0);;
let words: (string list * string list) list ref = ref [];;
let random l =
List.nth l (Random.int (List.length l))
;;
let chan = open_in "words" in
try
while true do
let line = input_line chan in
let pair = List.nth (split (regexp ":") line) in
let gd = pair 0 :: [] in
let en = split (regexp ",") (pair 1) in
words := (gd, en) :: !words
done
with End_of_file -> close_in chan;;
let ask_a_word (ask_gd: bool) =
let (gd, en) = random !words in
let (color, words, answers) = if ask_gd then (34, gd, en) else (31, en, gd) in
let word = random words in
let hintstaken = ref 1 in
let rec keep_asking (n: int) =
printf "(%2d/%2d) \027[1;%dm%s\027[0;0m: %!" !correct !total color word;
let guess = input_line stdin in
let guessed = List.exists (fun s -> s = guess) answers in
(* basic CLI impersonization *)
if guess = ".hint" || guess = ".h" then
begin
List.iter
(fun s ->
let n = min !hintstaken (String.length (s) - 1) in
printf " %s%s\n"
(Str.first_chars s n)
(String.make ((String.length s) - n) '.'))
answers;
hintstaken := !hintstaken + 1
end;
total := !total + 1;
if not guessed then
keep_asking (n + 1)
else
correct := 1 + !correct
in
keep_asking 1
;;
Random.self_init ();;
try
while true do
ask_a_word (Random.bool ())
done;
None
with End_of_file -> None;
(* vi: ft=ocaml:ts=2:sw=2:expandtab
*)
gaidhlig: gaidhlig.ml
ocamlopt str.cmxa gaidhlig.ml -o gaidhlig
clean:
rm -f *.cmx *.cmi *.o
distclean: clean
rm -f gaidhlig
falamh:empty
glan:clean
salach:dirty
geur:sharp
ìosal:low
teth:hot
bàta:boat
duine:person,husband
gille:lad
leabhar:book
nead:nest
peann:pen
seòmar:room
taigh:house
balach:boy
doras:door
each:horse
làr:floor
loch:lake
òran:long
rathad:road
sgàthan:mirror
teine:fire
abhainn:river
eaglais:church
làmh:hand
litir:letter
oidhche:night
sgoil:school
snàthad:needle
caileag:girl
fearg:anger
leabaidh:bed
nighean:daughter,girl
sgian:knife
sìth:peace
àrd:tall
glè:very
agus:and
cho:so
uabhasach:terribly,awfully,very
ro:too
ach:but
beag:small
fliuch:wet
leisg:lazy
sgìth:tired
trang:busy
toilichte:happy,pleased
fear:man
blàth:warm
fuar:cold
mòr:big,large,great
tioram:dry
snog:nice
dubh:black
trom:heavy
caora:sheep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment