Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Duo Lingo clone
#!/usr/bin/env ruby
require 'readline'
# copied from https://www.vistawide.com/spanish/top_100_spanish_words.htm
list = <<~WORDS
el / la (def. art.) the
de (prep.) of, from
que (conj.) that, which
y (conj.) and
a (prep.) to, at
en (prep.) in, on
un (indef. art.) a, an
ser (verb) to be
se (pron.) -self, oneself [reflexive marker]
no (adv.) no
haber (verb) to have
por (prep.) by, for, through
con (prep.) with
su (adj.) his, her, their, your
para (prep.) for, to, in order to
como (conj.) like, as
estar (verb) to be
tener (verb) to have
lo (art.) the
lo (pron.) [3rd pers. masc. direct object pronoun]
le (pron.) [3rd pers. indirect object pronoun]
la (pron.) [3rd pers. fem. direct object pronoun]
todo (adj.) all, every
pero (conj.) but, yet, except
más (adj.) more
hacer (verb.) to do, make
o (conj.) or
poder (verb) to be able to, can
decir (verb) to tell, say
este (adj.) this (m)
esta (adj.) this (f)
ir (verb) to go
otro (adj.) other, another
ese (adj.) that (m)
esa (adj.) that (f)
si (conj.) if, whether
me (pron.) me
ya (adv.) already, still
ver (verb) to see
porque (conj.) because
dar (verb) to give
cuando (conj.) when
él (pron.) he
muy (adv.) very, really
sin (prep.) without
vez (noun, f.) time, occurrence
mucho (adj.) much, many, a lot
saber (verb) to know
qué (pron.) what?, which?, how (+ adj.)
sobre (prep.) on top of, over, about
mi (adj.) my
alguno (adj.) some
alguno (pron.) someone
mismo (adj.) same
yo (pron.) I
también (adv.) also
hasta (prep.) until, up to
hasta (adv.) even
año (noun, m.) year
dos (num.) two
querer (verb) to want, love
entre (prep.) between
así (adv.) like that
primero (adj.) first
desde (prep.) from, since
grande (adj.) large, great, big
eso (pron., n.) that
ni (conj.) not even, neither, nor
nos (pron.) us
llegar (verb) to arrive
pasar (verb) to pass, spend (time)
tiempo (noun, m.) time, weather
ella (pron.) she; ellas them
sí (adv.) yes
día (noun, m.) day
uno (num.) one
bien (adv.) well
poco (adj.) little few
poco (adv.) a little bit
deber (verb) should, ought to; to owe
entonces (adv.) so, then
poner (verb) to put (on); get (+ adj.)
cosa (noun, f.) thing
tanto (adj.) much
hombre (noun, m.) man, mankind, husband
parecer (verb) to seem, look like
nuestro (adj.) our
tan (adv.) such, a, too, so
donde (conj.) where
ahora (adv.) now
parte (noun, f.) part, portion
después (adv.) after
vida (noun, f.) life
quedar (verb) to remain, stay
siempre (adv.) always
creer (verb) to believe
hablar (verb) to speak, talk
llevar (verb) to take, carry
dejar (verb) to let, leave
nada (pron.) nothing
cada (adj.) each, every
seguir (verb) to follow
menos (adj.) less, fewer
nuevo (adj.) new
encontrar (verb) to find
WORDS
list = list.strip.lines.shuffle.map do |line|
line.split(/(?=[(]|(?<=[)]))/, 3).map(&:strip)
end
missed = []
correct = incorrect = 0
def test(spanish, type, english, &process)
puts "\e[H\e[2J#{spanish} #{type}"
system 'say', '-v', 'Monica', spanish
guess = Readline.readline "\r> "
is_correct = guess == english
correct, incorrect = process.call(is_correct)
if is_correct
print "\e[32mCorrecto! 😊"
puts " (#{correct}/#{incorrect})\e[0m"
else
print "\e[31mIncorrecto 😞"
puts " (#{correct}/#{incorrect})\e[0m"
puts "Expected: #{english}"
end
gets
end
list.each do |challenge|
missed.each do |challenge|
test(*challenge) { [correct, incorrect] }
end
test *challenge do |is_correct|
if is_correct
correct += 1
else
incorrect += 1
missed.unshift challenge
end
[correct, incorrect]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.