Skip to content

Instantly share code, notes, and snippets.

@Cvetomird91
Last active May 27, 2017 15:44
Show Gist options
  • Save Cvetomird91/71da2310d7ecd052e7cce29039b2c39e to your computer and use it in GitHub Desktop.
Save Cvetomird91/71da2310d7ecd052e7cce29039b2c39e to your computer and use it in GitHub Desktop.
#!/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