Language Study - new problem for testing

Back to General discussions forum

qwerty     2021-06-25 22:42:45

Hey everyone!

I was looking in internet for puzzle which is interesting but at the same time is simple enough (you know, I am not good at thinking :) ). ... and it seems I found one:

Original:

Даны слова на некотором искусственном языке и их перевод на русский язык:

  1. bbalgan sangwa — красное яблоко.
  2. ppaleun jae — быстрая машина.
  3. bbalgan yeonpiel — красный камень.
  4. keun jae — машина времени.

Напишите на этом языке словосочетание «красная машина». Все буквы в ответе должны быть строчными, пробел между словами один.

Translation (sorry if my english is not very good):

Here are words written on some fictional language, and their meanings:

  1. bbalgan sangwa - red apple.
  2. ppaleun jae - fast machine.
  3. bbalgan yeonpiel - red stone.
  4. keun jae - time machine.

Write "red machine" on that fictional language. Use only lowercase letters and separate words with exactly one space character."

That's it. I hope that it is not too hard to implement the checker - for creating new words checker of "Funny Words Generator" problem probably will do. And I can imagine there are ways to make problem more complex, if you want. For example, not only adjectives and nouns can be used, but verbs too.

What do you think about new problem, fellow brothers and sistren?

Rodion (admin)     2021-06-26 08:22:53
User avatar

Hi Friend!

by the way I received your notification, thanks - nice to see it still works, ha-ha

Thanks for your input! Initially I thought "this is bit too simple" - perhaps, writing generator/checker is harder than coding solution. However most probably it is not necessarily that simple :)

We seemingly suppose that single word refers to single adjective or noun. Even with such simplification we still may have more logic rather than just matching same words in different combinations. For example:

  • bbalgan sangwa - red apple.
  • ppaleun jae - fast machine.
  • yeonpiel bbalgan - red stone.
  • cirdonawa ppaleun - fast thought.
  • ??? ??? - red machine.

In this case machine is not found by matching combinations containing it, but rather by exclusion (supposing that order of nouns and adjectives is not imperative).

I suspect I need to think more about it and how to solve it - to understand how to write good data generator :) Especially if we want problem not to be easier to solve manually :)

qwerty     2021-06-26 10:26:51

Hi, Rodion!

Glad to hear that you like my idea!

I started to write generator for this task, this is what I got so far:

from random import randint, randrange, sample, choice, shuffle
from itertools import chain, product
from wgen import FunnyWordsGenerator, vowels

adjectives = ['red', 'fast', 'time', 'big', 'good', 'last', 'unknown', 'attractive', 'unusual']
nouns = ['apple', 'machine', 'thought', 'house', 'animal', 'flower', 'team', 'king', 'symbol', 'world']
adjective_first = 0
noun_first = 1
joining_rules = [adjective_first, noun_first]

def join_by_rule(fict_adj, fict_noun, rule):
    if rule == adjective_first:
        return fict_adj + ' ' + fict_noun
    elif rule == noun_first:
        return fict_noun + ' ' + fict_adj
    else:
        raise ValueError

def generate_task():
    selected_adjectives = sample(adjectives, randint(3, 5))
    selected_nouns = sample(nouns, randint(3, 5))
    chosen_rules = dict((noun, choice(joining_rules)) for noun in selected_nouns)
    ask_for_adjective = choice(selected_adjectives)
    ask_for_noun = choice(selected_nouns)

    funny_words = FunnyWordsGenerator(randrange(FunnyWordsGenerator(0).m))
    fictional_lang = dict(zip(chain(selected_adjectives, selected_nouns), chain(map(lambda word: word + ('un' if word[-1] in vowels else 'an'), map(funny_words.generate, (randint(2, 5) for _ in range(len(selected_adjectives))))), map(funny_words.generate, (randint(4, 8) for _ in range(len(selected_nouns)))))))

    phrases = list(product(selected_adjectives, selected_nouns))
    task_phrases = list(chain(sample([(adjective, noun) for adjective, noun in phrases if adjective == ask_for_adjective and noun != ask_for_noun], 2), sample([(adjective, noun) for adjective, noun in phrases if adjective != ask_for_adjective and noun == ask_for_noun], 2)))
    other_phrases = [(adjective, noun) for adjective, noun in phrases if adjective != ask_for_adjective and noun != ask_for_noun]
    with_informational_noise = list(chain(task_phrases, sample(other_phrases, randint(min(3, len(other_phrases) // 2), max(3, len(other_phrases) // 2)))))
    shuffle(with_informational_noise)

    data = '\n'.join(f'{join_by_rule(*map(fictional_lang.get, (adjective, noun)), chosen_rules[noun])} - {adjective} {noun}' for (adjective, noun) in with_informational_noise)

    query = f'{ask_for_adjective} {ask_for_noun}'

    answer = f'{join_by_rule(*map(fictional_lang.get, (ask_for_adjective, ask_for_noun)), chosen_rules[ask_for_noun])}'

#    debug_output = f'...here are words written on some fictional language, and their meanings:\n\n{data}\n\nWrite "{query}" on that fictional language.\n\n(The answer is "{answer}")\n\n'
#    
#    with open('output.txt', 'a') as file:
#        file.write(debug_output)

    return (data + '\n??? ??? - ' + query, answer)

Some examples generated by this code:

First example:

Here are words written on some fictional language, and their meanings:

  • kumul lovoun - unusual world
  • vozewuri pojugan - big machine
  • kumul mefadan - fast world
  • mefadan dadaxaci - fast apple
  • vozewuri lovoun - unusual machine
  • woun dadaxaci - unknown apple
  • hupowa pojugan - big symbol
  • texaj pojugan - big animal
  • lovoun dadaxaci - unusual apple

Write "fast machine" on that fictional language.

(The answer is "vozewuri mefadan")

Second example:

...here are words written on some fictional language, and their meanings:

  • joun sabo - good machine
  • widuveg kigupan - big thought
  • widuveg vipoun - attractive thought
  • vipoun migoziwe - attractive symbol
  • kigupan migoziwe - big symbol
  • xilovan sabo - unknown machine
  • xilovan migoziwe - unknown symbol

Write "attractive machine" on that fictional language.

(The answer is "vipoun sabo")

Third example:

...here are words written on some fictional language, and their meanings:

  • zepovo vuneun - attractive animal
  • kocu dagan - fast flower
  • bagan xusipe - good apple
  • kocu vuneun - attractive flower
  • vuneun xusipe - attractive apple
  • zepovo bagan - good animal
  • dagan xusipe - fast apple

Write "good flower" on that fictional language.

(The answer is "kocu bagan")

Hopefully this code can serve as good starting point!

Rodion (admin)     2021-06-26 12:54:18
User avatar

I started to write generator for this task

Eh... thanks for the effort, but it probably would be better to discuss idea in words :) I'm not that much confident in myself to blatantly rewrite Python to PHP

See, this part is rather simple - basically, generate random pairs so that every word is used at least twice and so could be found by comparison. I'm afraid that in such form people won't bother with writing solution code at all! Too easy to solve by hand...

What I'm thinking of - is to add pairs which work by exclusion. Then user's solution may need to employ some dynamic logic, e.g.:

- aaa bbb - small cat
- vvv aaa - pretty cat
- xxx mmm - young girl
- ttt xxx - young city

- ??? ??? - pretty girl

You see, "pretty" and "girl" are only used once. This is not great complication however, so I'm curious what other logical tricks could be employed.

qwerty     2021-06-26 13:42:29

Hey, Rodion.

I am not good at logical tricks, so I tried to make thinks more complex by adding verbs as parts of phrase.

My idea is that most verbs are derived from nouns, for example, in Russian language it look like that:

  1. дума - думать;
  2. письмо - писать;
  3. чтение - читать;
  4. еда - есть;
  5. программа - программировать.

And so on...

The new version of program derive verbs of fictional language from nouns by adding some suffux, or prefix, or both. Suffixes and prefixes are not known in advance, but we give user some examples to figure it out, and then user can receive requested verb by applying proper transformation to noun.

Example of task which I generated with this idea:

Here are words written on some fictional language, and their meanings:

  • jejan pogov fivumejavix - paint unknown thought
  • leun taxikoxi - fast letter
  • dicoxov jejan - unknown flight
  • vabijan taxikoxi - time letter
  • ruracan vumeja - last painting
  • jejan taxikoxi - unknown letter
  • dicoxov leun fipogovvix - think fast flight
  • dicoxov leun fivumejavix - paint fast flight
  • ruracan taxikoxi fidicoxovvix - fly last letter
  • jejan vumeja - unknown painting
  • vabijan pogov fipogovvix - think time thought

Write "write time painting" on that fictional language.

(The answer is "vabijan vumeja fitaxikoxivix")

qwerty     2021-06-26 13:43:07

Code of program (sorry that the code is again on Python, and not on PHP, but I can rewrite it to PHP if you find this idea promising):

from random import randint, randrange, sample, choice, shuffle
from itertools import chain, product
from wgen import FunnyWordsGenerator, vowels

adjectives = ['fast', 'time', 'big', 'good', 'last', 'unknown', 'attractive', 'unusual']
nouns_verbs = {'thought':'think', 'letter':'write', 'food':'eat', 'flower':'fluorish',  'symbol':'symbolize', 'life':'live', 'game':'play', 'movement':'move', 'painting':'paint', 'flight':'fly'}
adjective_first = 0
noun_first = 1
joining_rules = [adjective_first, noun_first]

def join_by_rule(rule, lang, verbs, adj, noun, verb=None):
    s = ''
    fict_adj = lang[adj]
    fict_noun = lang[noun]
    if rule == adjective_first:
        s = fict_adj + ' ' + fict_noun
    elif rule == noun_first:
        s = fict_noun + ' ' + fict_adj
    else:
        raise ValueError
    if verb is not None:
        s += ' ' + verbs[verb]
    return s

def join_english_phrase(adj, noun, verb=None):
    s = adj + ' ' + noun
    if verb is not None:
        s = nouns_verbs[verb] + ' ' + s
    return s

def generate_task():
    selected_adjectives = sample(adjectives, randint(3, 5))
    selected_nouns = sample(nouns_verbs.keys(), randint(3, 5))
    chosen_rules = dict((noun, choice(joining_rules)) for noun in selected_nouns)
    ask_for_adjective = choice(selected_adjectives)
    ask_for_noun = choice(selected_nouns)

    funny_words = FunnyWordsGenerator(randrange(FunnyWordsGenerator(0).m))
    fictional_lang = dict(zip(chain(selected_adjectives, selected_nouns), chain(map(lambda word: word + ('un' if word[-1] in vowels else 'an'), map(funny_words.generate, (randint(2, 5) for _ in range(len(selected_adjectives))))), map(funny_words.generate, (randint(4, 8) for _ in range(len(selected_nouns)))))))
    verb_decoration = randrange(3)
    verb_suffix = funny_words.generate(randint(2, 4)) if verb_decoration != 1 else ''
    verb_prefix = funny_words.generate(2) if verb_decoration != 0 else ''
    verbs = dict(zip(selected_nouns, (verb_prefix + fictional_lang[noun] + verb_suffix for noun in selected_nouns)))
    noun_to_verb = choice(selected_nouns)
    ask_for_verb = verbs[noun_to_verb]
    verbs.pop(noun_to_verb)
#    print()
#    print(*verbs.keys(), sep='\n')
#    print(*verbs.values(), sep='\n')
#    print()

    phrases = list(product(selected_adjectives, selected_nouns))
    task_phrases = list(chain(sample([(adjective, noun) for adjective, noun in phrases if adjective == ask_for_adjective and noun != ask_for_noun], 2), sample([(adjective, noun) for adjective, noun in phrases if adjective != ask_for_adjective and noun == ask_for_noun], 2)))
    i = randrange(4)
    adjective, noun = task_phrases[i]
    task_phrases[i] = adjective, noun, choice(list(verbs.keys()))

    other_phrases = [(adjective, noun) for adjective, noun in phrases if adjective != ask_for_adjective and noun != ask_for_noun]
#    print()
#    print(*other_phrases, sep='\n')
#    print()
    other_phrases_with_verbs = [(adjective, noun, verb) for phrase, verb in product(other_phrases, verbs.keys()) for (adjective, noun) in [phrase]]
#    print()
#    print(*other_phrases_with_verbs, sep='\n')
#    print()
    with_informational_noise = list(chain(task_phrases, sample(other_phrases, randint(min(3, len(other_phrases) // 2), max(3, len(other_phrases) // 2))), sample(other_phrases_with_verbs, randint(min(3, len(other_phrases_with_verbs) // 5), max(3, len(other_phrases_with_verbs) // 5)))))
#    print()
#    print(*with_informational_noise, sep='\n')
#    print()
    verbs[noun_to_verb] = ask_for_verb

    shuffle(with_informational_noise)

    data = '\n'.join(f'{join_by_rule(chosen_rules[noun], fictional_lang, verbs, *row)} - {join_english_phrase(*row)}' for row in with_informational_noise)

    query = f'{nouns_verbs[noun_to_verb]} {ask_for_adjective} {ask_for_noun}'

    answer = f'{join_by_rule(chosen_rules[ask_for_noun], fictional_lang, verbs, ask_for_adjective, ask_for_noun, noun_to_verb)}'

#    newline = '\n'
#    debug_output = f'Here are words written on some fictional language, and their meanings:\n\n{newline.join("- " + line for line in data.splitlines())}\n\nWrite "{query}" on that fictional language.\n\n(The answer is "{answer}")\n\n'
#    
#    with open('output.txt', 'a') as file:
#        file.write(debug_output)

    return (data + '\n??? ??? - ' + query, answer)
qwerty     2021-06-29 03:28:09

Rodion, I translated the above code to PHP. Can we please see this problem published?

qwerty     2021-06-29 03:34:47

Code - part I:

<?php
class string_list{
    public $_array;
    public function __construct(){
        $this->_array=array();
    }
    public function __destruct(){
        $this->_array=null;
    }
    public function append($value){
        array_push($this->_array,chop($value));
    }
    public function length(){
        return count($this->_array);
    }
    public function get_item($index){
        return $this->_array[$index];
    }
    public function collect(){
        return implode($this->_array);
    }
    public function sample($size){
        $array_copy=array_values($this->_array);
        shuffle($array_copy);
        $result_list=new string_list();
        $result_list->_array=array_slice($array_copy,0,$size);
        return $result_list;
    }
    public function random_choice(){
        return $this->_array[rand(0,count($this->_array)- 1)];
    }
}
class dictionary{
    public $_array;
    public function __construct(){
        $this->_array=array();
    }
    public function __destruct(){
        $this->_array=null;
    }
    public function append($key_value_pair){
        list($key,$value)=explode(':',$key_value_pair);
        $this->_array[chop($key)]=trim($value);
    }
    public function add($key,$value){
        $this->_array[$key]=$value;
    }
    public function length(){
        return count($this->_array);
    }
    public function get_item($index){
        return array_keys($this->_array)[$index];
    }
    public function get_value($key){
        return $this->_array[$key];
    }
    public function sample($size){
        $array_copy=array_keys($this->_array);
        shuffle($array_copy);
        $result_dict=new dictionary();
        $result_dict->_array=array_intersect_key($this->_array,array_flip(array_slice($array_copy,0,$size)));
        return $result_dict;
    }
    public function random_choice(){
        return array_keys($this->_array)[rand(0,count($this->_array)- 1)];
    }
}
class pair{
    public $x,$y;
    public function __construct($x,$y){
        $this->x=$x;
        $this->y=$y;
    }
}
class pairs_list{
    public $_array;
    public function __construct(){
        $this->_array=array();
    }
    public function __destruct(){
        $this->_array=null;
    }
    public function append($x,$y){
        array_push($this->_array,new pair($x,$y));
    }
    public function length(){
        return count($this->_array);
    }
    public function get_item($index){
        return $this->_array[$index];
    }
    public function filter($predicate){
        $result=new pairs_list();
        $n=count($this->_array);
        for($i=0;$i<$n;$i++){
            $xy=$this->_array[$i];
            $x=$xy->x;
            $y=$xy->y;
            if($predicate($x,$y))$result->append($x,$y);
        }
        return $result;
    }
    public function sample($size){
        $array_copy=array();
        $n=count($this->_array);
        for($i=0;$i<$n;$i++){
            $xy=$this->_array[$i];
            $x=$xy->x;
            $y=$xy->y;
            array_push($array_copy,new pair($x,$y));
        }
        shuffle($array_copy);
        $result_list=new pairs_list();
        $result_list->_array=array_slice($array_copy,0,$size);
        return $result_list;
    }
    public function extend(){
        $result=new triplets_list();
        $n=count($this->_array);
        for($i=0;$i<$n;$i++){
            $xy=$this->_array[$i];
            $x=$xy->x;
            $y=$xy->y;
            $result->append($x,$y,null);
        }
        return $result;
    }
}
class triplet{
    public $x,$y,$z;
    public function __construct($x,$y,$z){
        $this->x=$x;
        $this->y=$y;
        $this->z=$z;
    }
}
class triplets_list{
    public $_array;
    public function __construct(){
        $this->_array=array();
    }
    public function __destruct(){
        $this->_array=null;
    }
    public function append($x,$y,$z){
        array_push($this->_array,new triplet($x,$y,$z));
    }
    public function length(){
        return count($this->_array);
    }
    public function get_item($index){
        return $this->_array[$index];
    }
qwerty     2021-06-29 03:41:07

Code - part II:

    public function sample($size){
        $array_copy=array();
        $n=count($this->_array);
        for($i=0;$i<$n;$i++){
            $xy=$this->_array[$i];
            $x=$xy->x;
            $y=$xy->y;
            $z=$xy->z;
            array_push($array_copy,new triplet($x,$y,$z));
        }
        shuffle($array_copy);
        $result_list=new triplets_list();
        $result_list->_array=array_slice($array_copy,0,$size);
        return $result_list;
    }
}
class itertools{
    public static function product($a,$b){
        $n=$a->length();
        $m=$b->length();
        $p=new pairs_list();
        for($i=0;$i<$n;$i++){
            for($j=0;$j<$m;$j++){
                $p->append($a->get_item($i),$b->get_item($j));
            }
        }
        return $p;
    }
    public static function product2($ab,$c){
        $n=$ab->length();
        $m=$c->length();
        $p=new triplets_list();
        for($i=0;$i<$n;$i++){
            $x=$ab->get_item($i)->x;
            $y=$ab->get_item($i)->y;
            for($j=0;$j<$m;$j++){
                $p->append($x,$y,$c->get_item($j));
            }
        }
        return $p;
    }
    public static function chain($ab,$pq){
        $n=$ab->length();
        $m=$pq->length();
        $s=new pairs_list();
        for($i=0;$i<$n;$i++){
            $x=$ab->get_item($i)->x;
            $y=$ab->get_item($i)->y;
            $s->append($x,$y);
        }
            for($i=0;$i<$m;$i++){
            $x=$pq->get_item($i)->x;
            $y=$pq->get_item($i)->y;
            $s->append($x,$y);
        }
        return $s;
    }
    public static function chain2($abc,$pqr){
        $n=$abc->length();
        $m=$pqr->length();
        $s=new triplets_list();
        for($i=0;$i<$n;$i++){
            $x=$abc->get_item($i)->x;
            $y=$abc->get_item($i)->y;
            $z=$abc->get_item($i)->z;
            $s->append($x,$y,$z);
        }
        for($i=0;$i<$m;$i++){
            $x=$pqr->get_item($i)->x;
            $y=$pqr->get_item($i)->y;
            $z=$pqr->get_item($i)->z;
            $s->append($x,$y,$z);
        }
        return $s;
    }
}
$file=fopen("adjectives.txt","r")or die("adjectives are not available");
$adjectives=new string_list();
while(!feof($file)){
    $line=fgets($file);
    if(strlen($line)!=0)$adjectives->append($line);
}
fclose($file);
$file=fopen("nouns-verbs.txt","r")or die("nouns and verbs are not available");
$nouns_verbs=new dictionary();
while(!feof($file)){
    $line=fgets($file);
    if(strlen($line)!=0)$nouns_verbs->append($line);
}
fclose($file);
function checker(){
    global $adjectives,$nouns_verbs;
    global $consonants,$vowels,$consonant_count,$vowel_count;
    global $adjective_first,$noun_first,$fictional_lang,$fictional_verbs;
    global $ask_for_adjective,$ask_for_noun;
    $selected_adjectives=$adjectives->sample(rand(3,5));
    $selected_nouns=$nouns_verbs->sample(rand(3,5));
    $ask_for_adjective=$selected_adjectives->random_choice();
    $ask_for_noun=$selected_nouns->random_choice();
    $ask_for_vernoun=$selected_nouns->random_choice();
    $consonants=array('b','c','d','f','g','h','j','k','l','m',
    'n','p','r','s','t','v','w','x','z');
    $vowels=array('a','e','i','o','u');
    $consonant_count=count($consonants);
    $vowel_count=count($vowels);
    function generate_word($length){
        global $consonants,$vowels,$consonant_count,$vowel_count;
        $characters=new string_list();
        $type=rand(0,4)==4?1:0;
        for($i=0;$i<$length;$i++){
            if($type==0){
                $index=rand(0,$consonant_count-1);
                $character=$consonants[$index];
                $type=1;
            }
            else{
                $index=rand(0,$vowel_count-1);
                $character=$vowels[$index];
                $type=0;
            }
            $characters->append($character);
        }
        return $characters->collect();
    }
    $fictional_lang=new dictionary();
    for($i=0;$i<$selected_adjectives->length();$i++){
        $word=generate_word(rand(2,5));
        $word.=in_array($word[strlen($word)- 1],$vowels)?"un":"an";
        $fictional_lang->add($selected_adjectives->get_item($i),$word);
    }
qwerty     2021-06-29 03:45:21

Code - part III:

    for($i=0;$i<$selected_nouns->length();$i++){
        $word=generate_word(rand(4,8));
        $fictional_lang->add($selected_nouns->get_item($i),$word);
    }
    $verb_decoration=rand(0,2);
    $verb_suffix=$verb_decoration!=1?generate_word(rand(2,4)):"";
    $verb_prefix=$verb_decoration!=0?generate_word(rand(1,2)):"";
    $fictional_verbs=new dictionary();
    for($i=0;$i<$selected_nouns->length();$i++){
        $noun=$selected_nouns->get_item($i);
        if($noun!=$ask_for_vernoun){
            $word=$verb_prefix;
            $word=$word .($fictional_lang->get_value($noun));
            $word=$word.$verb_suffix;
            $fictional_verbs->add($noun,$word);
        }
    }
    $phrases=itertools::product($selected_adjectives,$selected_nouns);
    $task_phrases=itertools::chain(
    $phrases->filter(function($x,$y){
    global $ask_for_adjective,$ask_for_noun;
    return($x==$ask_for_adjective)&&($y!=$ask_for_noun);})->sample(2),
    $phrases->filter(function($x,$y){
    global $ask_for_adjective,$ask_for_noun;
    return($x!=$ask_for_adjective)&&($y==$ask_for_noun);})->sample(2));
    $task_phrases_with_verbs=$task_phrases->extend();
    $task_phrases_with_verbs->get_item(rand(0,3))->z=$fictional_verbs->random_choice();
    $other_phrases=$phrases->filter(function($x,$y){
    global $ask_for_adjective,$ask_for_noun;
    return($x!=$ask_for_adjective)&&($y!=$ask_for_noun);});
    $other_phrases_null_verbs=$other_phrases->extend();
    $other_phrases_with_verbs=itertools::product2($other_phrases,$fictional_verbs);
    $target_size=$other_phrases_null_verbs->length();
    $min_sample_size=3;
    if($min_sample_size>$target_size)$min_sample_size=$target_size;
    $max_sample_size=intdiv($target_size,2);
    if($max_sample_size<$min_sample_size)$max_sample_size=$min_sample_size;
    $chosen_other_phrases=$other_phrases_null_verbs->sample(rand($min_sample_size,$max_sample_size));
    $target_size=$other_phrases_with_verbs->length();
    $min_sample_size=3;
    if($min_sample_size>$target_size)$min_sample_size=$target_size;
    $max_sample_size=intdiv($target_size,5);
    if($max_sample_size<$min_sample_size)$max_sample_size=$min_sample_size;
    $chosen_other_with_verbs=$other_phrases_with_verbs->sample(rand($min_sample_size,$max_sample_size));
    $with_informational_noise=itertools::chain2($task_phrases_with_verbs,
    itertools::chain2($chosen_other_phrases,$chosen_other_with_verbs));
    shuffle($with_informational_noise->_array);
    function join_by_rule($xyz){
        global $adjective_first,$noun_first,$fictional_lang,$fictional_verbs;
        $adjective=$xyz->x;
        $noun=$xyz->y;
        $vernoun=$xyz->z;
        $rule=rand($adjective_first,$noun_first);
        $fict_adjective=$fictional_lang->get_value($adjective);
        $fict_noun=$fictional_lang->get_value($noun);
        if($rule==$adjective_first)
        $s=$fict_adjective." ".$fict_noun;
        else if($rule==$noun_first)
        $s=$fict_noun." ".$fict_adjective;
        else die("unknown rule");
        if($vernoun!=null)
        $s.=" ".$fictional_verbs->get_value($vernoun);
        return $s;
    }
    function join_english_phrase($xyz)
    {
        global $nouns_verbs;
        $adjective=$xyz->x;
        $noun=$xyz->y;
        $vernoun=$xyz->z;
        $s=$adjective." ".$noun;
        if($vernoun!=null)
        $s=$nouns_verbs->get_value($vernoun)." ".$s;
        return $s;
    }
    $target_size=$with_informational_noise->length();
    $lines=range(0,$target_size-1);
    $adjective_first=0;
    $noun_first=1;
    for($i=0;$i<$target_size;$i++){
        $lines[$i]=join_by_rule($with_informational_noise->get_item($i));
        $lines[$i].="-";
        $lines[$i].=join_english_phrase($with_informational_noise->get_item($i));
    }
    $data=implode("\n",$lines);
    $query=implode(" ",array("???","???","-",$nouns_verbs->get_value($ask_for_vernoun),$ask_for_adjective,$ask_for_noun));
    $data.="\n".$query;
    $word=$verb_prefix;
    $word=$word.($fictional_lang->get_value($ask_for_vernoun));
    $word=$word.$verb_suffix;
    $answer=implode(" ",array($fictional_lang->get_value($ask_for_adjective),$fictional_lang->get_value($ask_for_noun),$word));
    return array($data,$answer);
}
?>
Rodion (admin)     2021-06-30 06:42:04
User avatar

Hi Friend!

by the way I probably still don't know how to properly address you, though perhaps I forgot something?

Don't think please that I forgot or fell a victim to popular virus (not yet!) - I was wringing my brain about this problem and hopefully it will go live in a few days.

I'm sorry but I prefer to return to your original idea, without verbs - they made problem somewhat more confusing and complicated but probably not improve difficulty :) Additionally some English words are often both nouns and verbs thus with your proposal to make people study about prefixes and suffixes it is easy to convert programming problem into detective story with linguistic roots.

Also sorry for I can't easily reuse your code - it is bit too large to be easily understandable and I'm not the most clever person, probably. After kicking around it for some time I decided to return to it bit later.

I found that your original idea could be best extended by allowing phrases of up to 4 words (red fat clever cat), which allows for less straightforward solving of some combinations.

qwerty     2021-06-30 08:21:47

Good day, Rodion!

Don't think please that I forgot or fell a victim to popular virus

Glad to hear that you are all right!

by the way I probably still don't know how to properly address you

I don't like to tell much about myself, so if you meant my name and surname, then I never told these to anyone, yes.

I was wringing my brain about this problem and hopefully it will go live in a few days.

I'm sure that with proper approach this idea can make a good problem, though it seems like I myself can't find that approach... Can't wait to see what you are up to!

I'm sorry but I prefer to return to your original idea, without verbs - they made problem somewhat more confusing and complicated but probably not improve difficulty :)

No worries! The idea with verbs is not necessarily the best.

Additionally some English words are often both nouns and verbs.

Exactly! Had a big trouble filling my nouns-verbs.txt with non-ambigious pairs of nouns and verbs because of that.

Also sorry for I can't easily reuse your code - it is bit too large to be easily understandable and I'm not the most clever person, probably.

I think it is not like you are "not the most clever person" - it is my unability to organize the code well... I know that exploring someone else's code is hard, and that I probably should leave some comments in code to help understand it, but I was in hurry to make my idea work :). Well, for your current idea, I think, most of my code is useless, so I will comment only one function from my code which may be still useful:

#Chooses $size elements from that string_list object at random.
public function sample($size){
    $array_copy=array_values($this->_array); #make a copy so that original won'be shuffled.
    shuffle($array_copy); #make a random permutation of elements.
    $result_list=new string_list(); #make a new string_list object.
    $result_list->_array=array_slice($array_copy,0,$size); #initialize that object with first $size elements taken from random permutation.
    return $result_list; #result is ready!
}
Rodion (admin)     2021-07-02 09:38:59
User avatar

Hi Friend!

First of all - here is the problem and I would be glad and thankful if you can help testing it!

As about the name - no problem, sure :) I vaguely remember you prefer to go anonymous - just asked in case I have confused something.

Thanks for the code snippet, I guess it is almost what array_rand() does - though it should be understand I do not know much of PHP besides experience of creating this site :(

If you would like, after your testing I can share main part of the current checker code (somehow privately though) so that you may review/verify and suggest some additions in logic etc.

Quandray     2021-07-02 13:11:36
User avatar

It all looks fine to me.

Rodion (admin)     2021-07-02 13:46:14
User avatar

Grae! Glad to see you and thanks for your quick reaction!

Double thanks as I myself haven't come up with programming solution yet.

Also I wonder should we limit submission time to prevent manual solution :)

Quandray     2021-07-02 17:53:39
User avatar

Yes, limiting the submission time may be a good idea, although I don't think I'd like to do it manually.

qwerty     2021-07-03 19:48:12

First of all - here is the problem and I would be glad and thankful if you can help testing it!

Great! I will take a look and tell you what I think.

Thanks for the code snippet, I guess it is almost what array_rand() does - though it should be understand I do not know much of PHP besides experience of creating this site :(

My overall experience with PHP is even smaller - only two days, when I was trying to rewrite my checker code to PHP... No wonder I missed that array_rand() function. Thank you for tip!

If you would like, after your testing I can share main part of the current checker code (somehow privately though) so that you may review/verify.

Will gladly help to improve the checker if needed! But of course, first I need to take a look at problem.

Also I wonder should we limit submission time to prevent manual solution :)

No, please! Time limit is so stressful, like in that problem, and this time you cannot even excuse its existence with need of effective algorithm like binary search.

qwerty     2021-07-03 21:53:53

although I don't think I'd like to do it manually

Yeah, solving this manually should require a bit too much of patience, attention and time.

qwerty     2021-07-03 23:00:48

Rodion, I made several submissions, checking the results both programmaticaly and manually (manually, of course, only a few, chosen at random, words), and haven't seen any big problems with checker so far.

I will go sleep now, but maybe I will add something tomorrow.

Rodion (admin)     2021-07-04 05:42:43
User avatar

Aha, thanks Friends for verification - then let it become visible in the list!

Time limit is so stressful, like in that problem

in this case it needs not be that tight I think... There are 13+ test cases, each may take, say, 20 seconds when solving manually... Thus 200 seconds (3.3 minutes) should be comfortable, perhaps?

qwerty     2021-07-04 06:10:21

There are 13+ test cases, each may take, say, 20 seconds when solving manually... Thus 200 seconds

You found O(n) algorithm, with n = number of "equations" ?? This is awesome! My algorithm is O(m ** 2), with m = number of "words", so for 20 secs and 13 "equations" with 3 "words" each it could take 20 * 39 * 39 = 8.45 hours to solve manually, without eating, toilet and other needful things...

qwerty     2021-07-04 06:11:41

Can you please share this linear algorithm? This is very interesting!

qwerty     2021-07-04 06:19:15

Three minutes should be enough time to send solution, so it is ok for me.

qwerty     2021-07-04 08:15:09

Hey Rodion!

There are two more additions.

First: I wrote a story to introduce the problem. Please read and tell what you think.

Our Brother Shampolion is an famous archeologist. Recently he and his team started digging the mysterious ruins of Su-Chan, which age is estimated around 3400 BD.

You can imagine how amazing discovery it was - to find out there is an civilization which existed more than thirty - three centures before our era.

Infortunately, there was nothing known about their language so far...

...until today.

Oh, today is an wonderful day! Shampolion and his assistants digged from earth several stone tablets containing not only words of unknown language, but illustations too!

On one of these illustations a juicy red apple was drawn, and the title was "bbalgan sangwa", so this is how "red apple" is written on that language.

On the other illustration, a mysterous device was drawn, titled "keun jae", and near a portrait of Albert Einstein was drawn. Incredible! Did that civilization invent a "time machine" to talk with famous scientist?

After studying these tablets, a list of phrases in unknown language and their corresponding translations was filled. Now Shampolion is curious if it is possible to build new phrases using the known ones... He asks you for help.

(problem statement follows...)

Second: I don't really want my nickname to be mentioned - like in fragment:

Idea of this problem was suggested by our colleague qwerty_one - thanks a lot!

I think you can replace this fragment with story I described above or reformulate like:

Idea of this problem was suggested by our community - thanks a lot to you all!

Please login and solve 5 problems to be able to post at forum