STOP!

STOP!

You have 600 seconds to write function in your favorite programming language to check if two strings are anagrams.
>anagram("fuck", "fcku")
gives true or 1

It's not case sensitive.

Other urls found in this thread:

github.com/Property404/fetlang
php.net/manual/de/normalizer.normalize.php
twitter.com/SFWRedditImages

lambda a, b: a == b[::-1]

def isAnagram(s1, s2):
s1 = list(s1.upper())
s2 = list(s2.upper())
s2.sort()
s1.sort()
return s1 == s2

int anagram(char s1[], char s2[])
{
int i, len;
int is_anagram;

// to lower
len = 0;
for(i = 0;; ++i)
{
if(s1[i] == '\0' || s1[i] == '\n' || s2[i] == '\0' || s2[i] == '\n')
break;
if(s1[i] >= 65 && s1[i] = 65 && s2[i]

#include
using std::vector;
#include
using std::sort;

void strToCharVect(const char *a, vector &b)
{
int i = 0;
while (a[i] != 0)
{
b.push_back(a[i]);
i++;
}

}

bool anagram(const char *a, const char *b)
{
vector strA;
vector strB;

strToCharVect(a, strA);
strToCharVect(b, strB);

sort(strA.begin(), strA.end());
sort(strB.begin(), strB.end());

if (strA == strB)
{
return true;
}
else
{
return false;
}
}

int _tmain(int argc, _TCHAR* argv[])
{
if (anagram("test", "teet"))
{
printf("True\n");
}
else
{
printf("False\n");
}

return 0;
}

ez pz

this actually works right?

It does.

anagram is not necessarily a palindrom moron

hey that's clever

not a shitpost

>int _tmain
what the? is that C++20? never seen that

No. It would say a word is an anagram of itself

STOP!

You have all the time you need to do your homework.

indeed

```
anagram :: (Ord a) => [a] -> [a] -> Bool
anagram s1 s2
| sort s1 == sort s2 = True
| otherwise = False
```

...

Argh. It's a microsoft/Visual-studio ism.

They have a series of macros that expand to either a character or wide character function depending on whether the UNICODE preprocessor symbol is defined..

So _tmain becomes main or mainw (which takes wchar strings)

That bird isn't holding any weapons so I won't do it

function isAnagram($w1, $w2) {
$PROBABLY_ENOUGH = 9999999;
for ($i = 0; $i < $PROBABLY_ENOUGH; $i++) {
if ($w1 == str_shuffle($w2)) {
return true;
}
}
return false;
}

var_dump(isAnagram('ThisIs', 'b8')); // bool(false)
var_dump(isAnagram('bamboozle', 'zleboobam')); // bool(true) (most of the time

translate both string as an array of integers and add them up if the result is the same they are anagrams that is fking trivial and i'm a pajeet.

But that's wrong - your way would return true for anagram("ad", "bc");

>[1][1] == [2][0]

Well, it works, most of the time.
You could probably be a senior php developer with those skills.

AC = 65+67 = 132
BB = 66+66 = 132

Who /erlang/ here?
-module(anagram).
-export([isanagram/2]).

isanagram(Str1, Str2) ->
lists:sort(Str1) == lists:sort(Str2).

took me longer than it should
def anagram(s0,s1): len(s0) and len(s1) == True ; return True

> "i < i+1"
M8

What the fuck is this.

it's C, the programming language

I haven't used C++ much.

Do vectors have a predefined equals() function to compare their elements? In other languages I know that comparing usually just compares addresses.

>len
>anagram("abc", "def")
>true

c++ lets you overload the equality operator, and the standard library containers do this.

If we were talking about a plain C char-array type string, then you'd be right, but that's why I translated it into a vector (that and the pre-cooked sort function).

forgot to import
import Data.List
anagram :: (Ord a) => [a] -> [a] -> Bool
anagram s1 s2
| sort s1 == sort s2 = True
| otherwise = False

Then just put everything in an if-else statement

is_anagram = lambda s1, s2: sorted(s1.lower()) == sorted(s2.lower())

man, Haskell is truly the creation of God

Haskell is an art form

wrong but you gave me an idea:
primes = ( 2, 3, 5, ...)

def is_anagram(a, b):
return reduce(lambda s,x: s*primes[ord(x)-97], a.lower(), 1) == reduce(lambda s,x: s*primes[ord(x)-97], b.lower(), 1)

more shitty coders there are that can't even do trivial stuff to save themselves the better my position is on the jobs market

>no unicode support
it's shit

can somebody solve it in fetlang?
github.com/Property404/fetlang

would be interesting to see what that would look like

Why don't you just compare the sorted lists?

words contain letters not emoji, I don't need unicode to compare words

You could probably 1-liner that check using a lambda now - assuming it doesn't have it predefined already, in which case that version would probably be faster.

I read the book thinkpython2 and I'm now a anagram/palindrome/anaphone/reversed word professional. Nearly every exercises in this book are about searching words in a dictionary with special properties.

let's see your code then

woah its not like pythons made to manipulate strings

inefficient

Other languages, amerifat.

function is_anagram() {
$args = func_get_args();
$c = count($args);
for($i = 0; $i < $c; $i++) {
$arr[$i] = join(sort(str_split(str_to_lower($args[$k]))));
}
for($i = 0; $i < ( $c - 1 ); $i++) {
if($arr[$i] === $arr[$i + 1]] continue;
else return false;
}
}


Works for more arguments than one.

$code = str_replace('$k', '$i', $code);

>2017
>still using lambdas
Pleb imperative languages

> Unicode is just for emojis
b8 or burger

And also return true on the end.

Bash because of how easy it is for such simple tasks.

#!/bin/bash
[[ "$(echo $1 | grep -o . | sort | xargs)" == "$(echo $2 | grep -o . | sort | xargs)" ]] && echo "true"

(((Lisp when?)))

it's not. perl is.

))))))))))))))))))))))))))))))))))))))))))))))))))))))))

I like that pipe concept in bash

This is why I can't think of any uses for other languages, because anything complex enough to require a more complex language already exists. And if it doesn't it probably isn't worth the hassle.

return true;

import org.poo.pajeet.AnagramLibrary;

public boolean checkIfAnagram(String s1, String s2) {
return AnagramLibrary.checkIfAnagram(s1, s2);
}

D
bool isAnagram(string s1, string s2)
{
import std.uni;
import std.algorithm;
return isPermutation(s1.toLower.byGrapheme, s2.toLower.byGrapheme);
}

No, that's silly. An early exit solution would look cleaner, be more readable and do the same thing.

>early exit
Kill urself my man

A function should return once and at the bottom

My solution would be similar to
but with less words:
def is_anagram(word1, word2):
return sorted(word1.upper()) == sorted(word2.upper())

>A function should return once and at the bottom
please throw your computer in the trash

const cmp = ([...a],[...b]) => {
a.sort();
b.sort();
return a.length === b.length && a.every((val, i) => b[i] === val);
};

console.log(cmp('fkcu', 'fukc')); // true
console.log(cmp('fkcu', 'ffukc')); // false
console.log(cmp('fkcu', '1249')); // false

{(asc x)~asc y}

1 million shekels to anyone who can guess the language

function fn ( stringA, stringB ) {
stringA = stringA.toLowerCase().split("");
stringB = stringB.toLowerCase().split("");
var i;
stringA.forEach(function (c) {
i = stringB.indexOf(c);
if (i >= 0) {
stringB.splice(i, 1);
}
});
return (stringB.length === 0);
}
var s1 = "fuck";
var s2 = "cKuf";
var s3 = "ckaf";
fn(s1, s2);
=> true
fn(s1, s3);
=> false

>A function should return once and at the bottom
Found the C-fag.

ya blew it

function anagram(str1, str2) {

const str1Arr = Array.from(str1.toLowerCase()).sort();
const str2Arr = Array.from(str2.toLowerCase()).sort();

return str1Arr.length === str2Arr.length && str2Arr.every((l, i) => l === str1Arr[i]);
}


This solution sucks but it works I guess.

Javascript from 2003?

For just two arguments, it can be one liner...

if (condition1) {
if (condition2) {
if (condition3) {
if (condition4) {
if (condition5) {


Yes fãm this is truly the patrician's choice

Isabelle?

boolean isAnagram (String s1, String s2) {
if (s1.length() == s2.length() && !s1.equals(s2)) {
for (int i = 0; i < s2.length(); i++) {
s1 = s1.replaceFirst("" + s2.charAt(i), "");
}
return s1.isEmpty();
}
return false;
}

nope

ok ill multiply them and compare the result because if we suppose the anagram can only containt the 26 letters of the alphabet then the
product will be in the range of 26 consecutive numbers of which we know none is unity thus their product is unique to each letter.

there seems to be a lot of morons in this thread

nice try retard

I don't get your explanation

function anagram(str,str2) {
var reverseString = str.toLowerCase().split("").reverse().join("");
if (reverseString===str2.toLowerCase) {
return true;
}
return false;
}
anagram("fuck", "fcku")

wtf. why you reversing it? this doesn't work...

A would be an anagram of AA then.

The way to do it is: .
Assign every letter to its own prime number.
Since every number has a unique prime factorization as the fundamental theorem of arithmetic states, the product of every word must be different if it contains different letters.

i thought its about reversing string, so anagram of fuck is kcuf. Then it works, however i forget ()
function anagram(str,str2) {
var reverseString = str.toLowerCase().split("").reverse().join("");
if (reverseString===str2.toLowerCase()) {
return true;
}
return false;
}
anagram("fuck", "fcku")

i suppose you have a list of all primes then...

You only need 26 primes.

ok my bad

Who cares about other languages, fag? Speak English.

Is a word not an anagram of itself?

the majority

function is_anagram(a, b) {
return a.toLowerCase().split('').sort().join() == b.toLowerCase().split('').sort().join()
}


So fucking hard.

(You)

looooooooooool

No. Similarly, bo2o1k is not an anagram of bo1o2k.

package main

import (
"fmt"
"sort"
)

type sortRunes []rune

func (s sortRunes) Less(i, j int) bool {
return s[i] < s[j]
}

func (s sortRunes) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s sortRunes) Len() int {
return len(s)
}

func SortString(s string) string {
r := []rune(s)
sort.Sort(sortRunes(r))
return string(r)
}

func isAnagram(s1 string, s2 string) {
fmt.Println(s1)
fmt.Println(s2)
result := SortString(s1) == SortString(s2)
fmt.Println(fmt.Sprintf("Are they anagrams? %t\n", result))
}

func main() {
s1 := "railsafety"
s2 := "fairytales"
s3 := "notananagram"
isAnagram(s1, s2)
isAnagram(s1, s3)
}

too bad you don't know what anagram means.
regardless, how does your code handle normalization forms?

I realized that. That's why I deleted the post.

Also, PHP does bring a normalizer if you need: php.net/manual/de/normalizer.normalize.php