#!/bin/sh #languages="C++ #Python #TypeScript #C #Go #Ruby #PHP #Racket" # #echo "$languages" | shuf | head -n5 prob="$1" test -n "$prob" || { echo "Pass the problem number"; exit 1;} lang_frek="$(find . -maxdepth 1 -mindepth 1 -not -path './.*' -type d \ | parallel -j1 'find {} -maxdepth 1 -mindepth 1 -type f | wc -l | xargs echo {}' \ | sort -k2)" lest_amount="$(echo "$lang_frek" | head -n1 | cut -d' ' -f2)" possibles="$(echo "$lang_frek" | grep "$lest_amount" | sed "s/ ${lest_amount}//g")" chosen="$(echo "$possibles" | shuf | head -n1)" newest_file="$(find "${chosen}" -type f -printf "%T@ %p\n" \ | sort -n \ | cut -d' ' -f 2- \ | tail -n 1)" bn="$(basename "$newest_file")" ext="$(echo "$bn" | cut -d'.' -f2)" cp "$newest_file" "${chosen}/${prob}.${ext}" echo "Language ${chosen}" echo "File: '${chosen}/${prob}.${ext}'"