Fun programming is fun!

Write a function (in any language you want) that takes in a string like e.g. "(({{[[]]}}))" and checks if the string is a complete mirror on both sides.

e.g.
[[{{}}]] will return true
{{{{]]]] will return false

Attached: brainlet.png (413x549, 71K)

Dude didn't we had this thread before?

then must be easy by now for you, right?

It's called a palindrome you fucking zoomer

A palindrome is a word that reads the same as it goes backwards, if you read [[{{}}]] backwards then you get ]]}}{{[[ so it is not a palindrome, but is a mirror on both sides.

Do your own homework

i just put it into sbcl and see if any unmatched parens found

why yes, I have 168 IQ

Wrote this in notepad so not sure if it runs

public boolean isMirrored(String target) {
char[] characters = target.toCharArray();
if(characters.length % 2 != 0) {
return false;
}

int right = chracters.length-1;
int left = 0;
for(; right > left; i++) {
if(characters[right] != characters[left]) {
return false;
}
}
return true;
}

nevermind, missread the question, total brainlett

Since there is no obvious way of matching mirrored characters, the only solution i can think of is to keep a mapping from left->right and use the same strategy as for palindroms.

Attached: Untitled.png (549x390, 11K)

This has to be the most retarded solution that still works

I'm sorry for being a brainlet.

this is fucking retarded, why are parentheses are next to each other in ascii, but brackets are not?

(def o->c {"}" "{"
"]" "["
")" "("}

(def input "(({{[[]]}}))")

(def input-median (/ (count input) 2))

(def first-half-input (clojure.string/subs input 0 input-median))

(def second-half-input (clojure.string/subs input 0 input-median))

(def is-mirrored? (= first-half-input (map o-c second-half-input)))


easy bro

self-correct: 0 should be removed from second-half-input

>Read first character
>Read last character
>Loop in to all the characters
Are you retarded?

what langfu is it?
please explain your algo

haha loop on your dick brainlet, reread the problem

this is in clojure. I split input in two halves, then switch all chars in the second half to their opening counterparts, then test equality

def palindrome(string):
length = len(string)
if length%2 != 0:
return False
for i in range(length//2):
if string[i] in "()":
if abs(ord(string[length-1-i]) - ord(string[i])) != 1:
return False
else:
pass
elif string[i] in "[{}]":
if abs(ord(string[length-1-i]) - ord(string[i])) != 2:
return False
else:
pass
else:
pass

return True

>Iterate with all the characters going inward
Nice try brainlet

Programming in UE blueprint is actually fun.
Working with horrific syntax and seeking for typos in notepad (teachers didn't tell as about coding editors) in lines of esoteric code is the reason i chose engineering over IT, by the end of school i only knew i wanted to be as far from typos in notepad as possible.

The poragramming itself is fun though, it's coding that sucks. And i fail to see the reason why can't they make an advanced language like blueprint or scratch

Attached: zdevW.png (1051x485, 91K)

What the fuck?

[{{[ = palindrome
[{}] = mirror

Ooh I get it. Thanks user uwu

oh, this is also good, however too much repetion for my taste just for the unicode distance difference

For(i=1; i 0; b--) {
If (i==b)printf
else()
}
}


Basically what it is

My solution would be to push each [, {, and (onto the stack. Then when you start giving me the closed versions, pop the value and compare. If they are a match then continue comparing. If they are not a match, then you know that the string is not a mirror and you fail the entire thing.

i don't understand you. Is this pseudocode? you are just testing for plain equivalence in O^2, you are aware of that?

You have to at least supply a map of chars, no computer knows the reverse of { out of the box.

you don't need to check from start to end.
just half of the string is enough because you're comparing a pair (left & right).
you assume it's a palindrome.

>( { ( } ) )
>lol

This is brilliant! I wish I thought of doing it this way. Libraries is for the win.

and give us some code bro, I'd love to see that 200 lines of boilerplate C

I forgot to check the () though.
Just add IndexOf("()") and Replace("()", "").
It's not the best algo because of cost of calling functions and memory allocation of each string produced by Replace().

try {{}[]} for me

How about web assembly instead?

Damn, you spot a bug!

>You are testing for plain equivilance of 0^2
Explain

this fails with racecar which has an odd number of characters. back to school!

```
if IsMirror():
return true
else:
return false
```
Checkmate retards

Agreed. I have to provide the map.

Just make sure the indexOf is the middle, and not just gt -1

Unless there are only 2 characters

I know how to derive a closed form for the one with only one symbol.

*yawn*

def palindrome(s):
if s == '' or len(s) == 1: # if empty or of length 1
return True
return s[0] == s[-1] and palindrome(s[1:-1])

BTW, how to correctly embed code on this frogposting chink imageboard?

Python 3.6.8 (default, Mar 5 2019, 18:20:50)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def palindrome(s):
... if s == '' or len(s) == 1: # if empty or of length 1
... return True
... return s[0] == s[-1] and palindrome(s[1:-1])
...
>>> palindrome("[[{{}}]]")
False

...

Congratulations on being an idiot.

I'm not good with python, but how the fuck does recursive call here work? s[1:-1] is cutting the string at the first call to 2 chars and that's it, it seems so

nested loops have the worst case complexity of O^2, the worst ever algorithm complexity known to man

>the worst ever algorithm complexity known to man
what about O^3

what about ))][((? is that a valid mirror?

and what about characters < and >?

The first one is a valid number

>new []

Attached: JPEG_20190423_223918.png (83x84, 13K)

>How to embed code

ackhually never seen an example of such an algo discussed in any literature, I think exponential growth is practically cutoff for algorithm efficiency

how do you paste this code into python interpreter? help bros, I want to use it but I don't want to paste line by line while manually indenting this shit

>hello

#include
#include
char map(char ch){switch(ch){case']':return'[';case'[':return']';case'{':return'}';case'}':return'{';default:return'\0';}}int chk_mirror(char*s){size_t len=strlen(s);if(len%2!=0)return 0;size_t i=0;size_t l=len-1;size_t mid = len/2;while (imid){if(s[i++]!=map(s[l--]))return 0;}return 1;}int main(int argc,char**argv){if(argc

need new [] because it's using var.

Where's i you're incrementing?

yes, yes, I've fucked it. the strategy is the same, just need a predicate instead of == in the last line

not that simple.
i need to remove only the middle part in each iteration otherwise {[]{}{}} will return true. using replace function remove all occurrence, remove {}{}, instead of removing just the first {}.

int
balanced(unsigned char *string)
{
int nRoundO = 0, nRoundC = 0;
int nCurlO = 0, nCurlC = 0;
int nSquareO = 0, nSquareC = 0;
int i = 0, len = 0;
while(string[i] != 0x0){
switch(string[i++]){
case '(': nRoundO++; break;
case ')': nRoundC++; break;
case '{': nCurlO++; break;
case '}': nCurlC++; break;
case '[': nSquareO++; break;
case ']': nSquareC++; break;
default: return 1;
}
len++;
}
if(len & 0x1) return 1;
if(nRoundO != nRoundC) return 1;
if(nCurlO != nCurlC) return 1;
if(nSquareO != nSquareC) return 1;
int halfLen = (len >> 1);
for(i = 0; i < halfLen; i++){
if(!(string[i] == string[len - 1 - i] - 1 ||
string[i] == string[len - 1 - i] - 2)) return 1;
}
return 0;
}

#include
#include
#include

int char_equals(char a, char b)
{
return (a == '(' && b == ')')
|| (a == '[' && b == ']')
|| (a == '{' && b == '}');
}

int str_equals(char* str)
{
int len = strlen(str);

for(int n = 0; n < len / 2; n++)
{
if(!char_equals(str[n], str[len - n - 1]))
{
return 0;
}
}

return 1;
}

int main(int argc, char **argv)
{
for(int i = 1; i < argc; i++)
{
if(str_equals(argv[i]))
{
printf("true\n");
}
else
{
printf("false\n");
}
}

return EXIT_SUCCESS;
}

(defn is-mirrored? [input]
(def o->c {\} \{ \] \[ \) \(})
(def input-median (/ (count input) 2))
(def first-half-input (vec (subs input 0 input-median)))
(def second-half-input (vec (subs input input-median)))
(def is-mirrored? (= first-half-input (reverse (mapv o->c second-half-input))))
is-mirrored?)


edited a bit, because my autism doesn't let me go

Read the question again user

what a monster, O^2 too

>0x1
why do people do this?

Why, yes, I am an idiot. How else could I be here among retards.

If you check for the middle, your example will fail, since after removing {} youll get a ]{ in the middle, and it will not proceed.

nvm didn't read the last bit you posted about replace.

that is not mirrored brainlet

sorry, final version looks like this, it should be clean and the most superior in terms of algo performance

(defn is-mirrored? [input]
(def o->c {\} \{ \] \[ \) \(})
(def input-median (/ (count input) 2))
(def first-half-input (vec (subs input 0 input-median)))
(def second-half-input (vec (subs input input-median)))
(= first-half-input (reverse (mapv o->c second-half-input))))

if it's not mirrored, it returns false
it's that simple

Is this thread a joke where everyone tries to create the longest most contrived solution possible?

Why not just return str[:half] == str[half:]

? That would correctly return false

Forgot reverse method on one of them

Are you joking?

I could fix it by taking the left part and right part and omit the middle mirrored part in each iteration.
But I lost my mood.
I thought I wrote some cool short code.
Thanks for spotting the bug.
I still need to learn.

his positional approach is actually correct, but for odd strings it will crash with no survivors on the last chars of the string it seems

Just use java
public class Mirrored {
public static boolean areMirrored(char c1, char c2) {
switch(c1) {
case '[': return c2==']';
case '{': return c2=='}';
case '(': return c2==')';
case ']': return c2=='[';
case '}': return c2=='{';
case ')': return c2=='(';
default: return false;
}
}
public static void main(String[] args) {
String str = args[0];
int length = str.length();
if(length%2!=0) {
System.out.println("Not mirrored");
return;
}
for(int i=0; i

Codelet questions beget codelet answers

Because literally everyone but you has a functional brain
If akeem haseem from karachi pakistan can wrap his head around C I don't see why you can't

'and' is a macro, not a function.
* (defparameter *opposite-of* (loop :for l :across "[{(" :for r :across "]})" :collect `(,l . ,r)))

*OPPOSITE-OF*
* (defun mirrorp (s)
(every #'(lambda (x) (eq t x))
(loop :for l :across s
:for r :across (reverse s)
:collect (equalp (assoc l *opposite-of*) (rassoc r *opposite-of*)))))

MIRRORP
* (mirrorp "[[{{}}]]")

T
* (mirrorp "{{{{]]]]")

NIL

I think it works.
Someone tell me how I'm retarded, please.
dic={'(':')',
'{':'}',
'[':']'}
dic.update({y:x for x,y in dic.items()})
def mirror(s):
return s[-len(s)//2:]==''.join([dic[x] for x in s[:len(s)//2][::-1]])
print(mirror('[[{{}}]]'))#t
print(mirror('{{{{]]]]'))#f

Why the fuck would you put "Mirrored" in the end? I didn't even read your code, discarded right there

I mean programming by return, and ok is an exception, what the fuck

Brainlet version of: Write a parser that returns true upon verifying a complete set of matching pairs and false in all other cases. Use only basic control structures and string manipulation in the language of your choosing.

just make the function return boolean if you are offended that much

>s[-len(s)//2:]==''.join([dic[x] for x in s[:len(s)//2][::-1]])
What in the name of fuck?

]]]]))}}{{(([[[[
Freak

Couldn't figure out how to make code blocks.
Is this good?

Attached: Screenshot_2019-06-16_15-32-14.png (534x430, 38K)

#include

#define CHAR_EQ(a, b) (((a) == '(' && (b) == ')') || ((a) == ')' && (b) == '(') || ((a) == '{' && (b) == '}') || ((a) == '}' && (b) == '{') || ((a) == '[' && (b) == ']') || ((a) == ']' && (b) == '['))

static unsigned char is_mirror(const char * const str) {
size_t i;
const size_t len = strlen(str);

if(len % 2) {
return 0;
}

for(i = 0; i < len/2; ++i) {
if(!(CHAR_EQ(str[i], str[len - i - 1]))) {
return 0;
}
}

return 1;
}

Autohotkey
inputbox, input
StringLeft, left, input, StrLen(input)/2
rightMatch := RegExReplace(left, "\(", ")")
rightMatch := RegExReplace(rightMatch, "\[", "]")
rightMatch := RegExReplace(rightMatch, "\{", "}")
Loop, Parse, rightMatch
reversed := A_LoopField . reversed
StringRight, right, input, StrLen(input)/2
msgbox % reversed = right

Attached: output.webm (564x382, 799K)

Is the Common Lisp or the LOOP?

I fixed it after some debugging in IDE.
Not according to keikaku.

Attached: Untitled.png (805x661, 24K)

>false for case 4

Attached: brogramming.jpg (1300x957, 108K)

of course it is false.

Case 4 is not a mirror you absolute troglodyte.