Lorem Ipsum

Discussion of challenges you have already solved
adark
Posts: 9
Joined: Fri Nov 20, 2015 2:04 pm
Contact:

Post by adark »

Lua:

Code: Select all

local file = io.open("lorem.txt")
local t = string.lower(file:read("*all"))
file:close()

for word in t:gmatch("%a+") do
	local count = 0
	for _ in t:gmatch(word) do
		count = count + 1
		if count == 2 then
			break
		end
	end
	if count == 1 then
		print(word)
		break
	end
end
mlynekt
Posts: 1
Joined: Tue Jul 05, 2016 11:09 pm

Post by mlynekt »

Code: Select all

tr -c "a-zA-Z" "\n" < lorem.txt | sort | uniq -u
User avatar
xiexun162534
Posts: 4
Joined: Fri Jul 26, 2013 1:26 pm
Contact:

Post by xiexun162534 »

The code I wrote in Challenge 3280 worked.
I'm boring.
Warscyther
Posts: 1
Joined: Mon Aug 29, 2016 1:48 pm

Javascript Solution

Post by Warscyther »

Thought I'ld post my quick Javascript solution which you can run directly in browser..

Code: Select all

var preInner = pre.innerHTML.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,""); // Remove punctuation.
preInner = preInner.replace(/\r?\n|\r/g, " "); // Remove all newline carriages
var myArray = preInner.split(" "); // Split into array

var sorted = myArray.slice().sort(); // Sort it alphabetically

var newArray = []; // Results array
var count = 0;


// If the current one is same as the next one - increase count.
for (var i =0; i < sorted.length -1; i++){
  if(sorted[i] == sorted[i+1]){ 
    count++;
  } else { // If the next one is a new one, check the count
    if(count > 0){ // There more than one previous one, reset the count and reloop
      count = 0;
    } else { // Only one counted current and reached now one? - Add to results array
      newArray.push(sorted[i]);
      count = 0;
    }
  }
}
newArray
[/code]
as33r
Posts: 1
Joined: Sun Oct 21, 2018 2:14 pm

my Linux solution

Post by as33r »

well i use Linux commands to solve this, and seems that my solution is pretty easy rather then others.

Code: Select all

# for i in $(cat lorem.txt); do echo $i ; done > split_lorem.txt
# cat split_lorem.txt | sort | uniq -c | grep ' 1 '
      1 auctor.
      1 blandit.
      1 fermentum.
      1 odio,
      1 scatterbrained
      1 suscipit.
      1 ultrices,
      1 vehicula.
here only one line is without suffix. so that's the flag :)
Post Reply