#Perform mathematic operations without using any numeric types(not explicit or implicit)

1 messages · Page 1 of 1 (latest)

wicked torrent
#

As the title already reveals i am trying to calculate using no numbers also indices arent allowed, does anyone knows a good way to perform such operations?
I thought about using chars to calculate but then i dont know how to without using the ascii value of the character.

This here is my own number class i created, the goal would be to perform operations with object from the number class

class Number {
    private LinkedList<Character> digits; 
    private boolean isNegative;

    public Number(String number) {
        digits = new LinkedList<>();
        isNegative = number.startsWith("-");
        for (char c : number.toCharArray()) {
            if (Character.isDigit(c)) {
                digits.add(c); 
            }
        }
    }

    public Number() {
        digits = new LinkedList<>();
        isNegative = false;
    }

    public void addDigit(char digit) {
        digits.add(digit); 
    }

    public LinkedList<Character> getDigits() {
        return digits; 
    }

    public boolean isNegative() {
        return isNegative;
    }

    public void setNegative(boolean isNegative) {
        this.isNegative = isNegative;
    }

    
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(isNegative ? "-" : "");
        for (Character digit : digits) {
            sb.append(digit); 
        }
        return sb.toString();
    }

    public static Number fromString(String str) {
        return new Number(str);
    }
    }


glacial voidBOT
#

<@&987246399047479336> please have a look, thanks.

wicked torrent
#

youre right, do you know a different way to do it?

spark haven
#

What kind of restriction is that

wicked torrent
#

a weird one,

so the task is to create an calculator using reversed polish notation, without using numbertypes and indeces or arrays

#

i am allowed to use chars but not the ascii value behind them

spark haven
#

you can subtract '0' from a char to get its numeric value

#

or use a method in Character

wicked torrent
#

ye but like then its a numeric value again and i think this is not allowed

#

i need to somehow operate only on the char string lvl or some diff level

quaint umbra
#

i mean, technically you could use boolean to represent bits. and based on the "bits", you can calculate

#

false represents 0, true represents 1

#

can link them together: [true -> false -> false]

#

that would be 100, which is the binary representation for the number 4

wicked torrent
#

this here is the task:

Development of a calculator that — and this is the challenge — may not use any number types in its implementation, either explicitly or implicitly. This eliminates, for example, the addressing of arrays via the index or the length comparison of two strings. It is advisable to implement a calculator that uses the reverse Polish notation.

#

i think the way you described is a possible one

#

i need to ask my teacher next week about it