Quick actions

cmd+k|ctrl+k

Navigation

Languages

Singleton-Filter-But-Preserving-Order

Snippet info

Language

Raku

Visibility

public

Author

221a86612c7785cb6094f25b034cba9994736288

Created

2025-09-15T19:21:52.559567Z

Updated

2025-09-15T19:21:52.559567Z

#!/usr/bin/env raku
#| The program outputs the numbers that appear only once in the input - keeping the original order

# example input
#2
#1
#4
#3
#2
#1

# expected output for the example input
#4
#3

# read all lines from standard input - we need it twice, hence we store it in an array
my @numbers = $*IN.lines;

# find numbers that appear only once
my @singletons = @numbers.Bag.grep(*.value == 1).map(*.key);

# print the single-occurrence numbers in their original order
@numbers.grep( * ∈ @singletons ).join("\n").put
INFO