Last active
May 27, 2017 15:44
-
-
Save Cvetomird91/71da2310d7ecd052e7cce29039b2c39e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#this is the Lonely Integer challenge from HackerRank | |
declare -a numbers; | |
control_string="%d\\n"; | |
read count || [ -n "$count" ]; | |
while read number || [ -n "$number" ]; do | |
numbers=( "${numbers[@]}" "$number" ); | |
done | |
let "count--"; | |
while [ "$count" -gt 0 ]; do | |
let "count--"; | |
control_string="${control_string}%d\\n"; | |
done | |
var=$( echo "${numbers[@]}" ) | |
printf $control_string $var | uniq -c | sed 's/^ *//;s/ *$//' | grep -P ^1 | awk '{print $2}' | sort | uniq -c | sed 's/^ *//;s/ *$//' | awk '{if($1==1) print $2}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment