right, if you want challenging test go to expert mode
Any bash rider here? hell more difficult to finish this puzzle within those condition
If you dunno what iâm talking about, check the achievements
Doesnât seem that hard and Iâm far from being a bash pro. However, I wasnât able to have a solution which passes both âHorses in disorderâ and âNumerous Horsesâ and ended up using a faster but not completly reliable method when N is large. Basically if there were a test with a large N and tied horses, Iâd fail. So if anyone could explain me the right way, Iâll be glad to learn some bash tricks.
Edit: finally managed to get a legit 100%. The way you read input and the moment you sort can make a huge difference.
Hi,
Iâve finally found a solution, in Bash, fast enough.
The principle was described in the Niskazâs post:
Itâs quite easy to implement. But you have to take care about how you perform arthitmetic expressions: it is better to use $(( Pi - Pj ))
than expr Pi - Pj
.
This little detail allowed me to pass the test with a huge number of horses.
I hope this will help !
Or try a Mars Lander II from medium, be it better left unmentionedâŠ
Ton idĂ©e a marchĂ© dans mon cas pourtant. Peut ĂȘtre que le tri nâĂ©tait pas si rapide que ça
Salut,
en Bash, pour lire lâinput, NE FAITES PAS read line (effacez le du code gĂ©nĂ©rĂ©) et faites cat /dev/stdin Ă la place. Câest bourrin mais ça vous fera gagner le trophĂ©e Bash.
Bonne chance.
je dois dire que jâai reussi avec le code par dĂ©faut, donc pas la peine de trickser
I did it with the default code, no need to trick
My current method is failing at case 3.
My method is to append all the input to a list, sort the list, and compare all pairs. The first 2 cases work fine. But at the third, my output is 1, but 4 is supposedly correct. Any ideas? I am using python2
Bonjour Ă tous,
Quelquâun saurait comment trier un tableau en bash⊠je galĂšre un peu mais je sens que je suis proche du butâŠ
franchement, je savais pas non plus mais une petite recherche sur google et tu sauras, stackoverflow par exemple a de bons morceau de code pour tâapprendre Ă trier un tableau.
Merci de la réponse,
Je vais regarder plus attentivement⊠jâavais dĂ©jĂ pas mal recherchĂ© avant mais je nâarrive pas Ă utiliser comme tableau les donnĂ©es triĂ©esâŠ
Hello
When i run the tests it all goes fine, but when i submit i got 2 errors (on Simple Case and NumerousâŠ). Anyone encountered this?
Salut, pour le Bash jâai utilisĂ© un tableau mais cela nâa pas fonctionnĂ© sur le test des grandes donnĂ©es car cela prend trop de temps. Aussi jâai abordĂ© le problĂšme en utilisant la commande âawkâ qui mâa permis de passer tous les tests.
Si ton code fonctionne avec un tableau je suis curieux de voir comment tu as codé.
Merci
Hi guys,
Please tell me how to pass âHorses in desorderâ. I am stuck
Thanks,
Iâm having the same problem. There might be a submission error.
I donât know what language youâre using, but I used a JavaScript array.sort() function before comparing strengths. When comparing, have a couple variables like âsmallestDiffâ and âcurrentDiffâ in the loop. If the current difference is smaller than smallest, set smallest equal to current.
That might be a little confusing, but I hope it helps.
I am using C++. Thanks for your help!
You sir deserve a cookie.
It took me hours to try to optimise different parts of that code, but I didnât realise using expr
makes such a difference. Thanks for the tip.
I tried the bash rider achievement without luck for a time. Checking elements two by two in the sorted array was too slow for me (strangely, it gets slower and slower as I go into higher indexes).
I finally just did a one-liner with sed / sort / awk.
It could be considered cheating as there is not a line of actual bash, on the other hand, for me this is the mentality of bash / command-line: use whatever tool you have at your disposal to get the job done.
See for instance: http://franklinchen.com/blog/2011/12/08/revisiting-knuth-and-mcilroys-word-count-programs/