Discuss Scratch

mybearworld
Scratcher
1000+ posts

Programming challanges!

Code challenges! Write interesting ideas to do in code. You can write in any programming language. Try to find the shortest in every language (measured in bytes).
I'll start:
Write a rot13 program - and try to support case sensing as well.

Last edited by mybearworld (Feb. 16, 2022 18:00:59)


Signatures are the only place where assets links still work.
mybearworld
Scratcher
1000+ posts

Programming challanges!

Bonk!

Signatures are the only place where assets links still work.
mybearworld
Scratcher
1000+ posts

Programming challanges!

mybearworld wrote:

Bonk!

Signatures are the only place where assets links still work.
gosoccerboy5
Scratcher
1000+ posts

Programming challanges!

My really inefficient and dumb rot13 program
function rot13(input,amount=13){const letters="abcdefghijklmnopqrstuvwxyz";let temp="";const isUpperCase=function(text){return text.toUpperCase()===text};for(let i=0;i<input.length;i++){if(!letters.includes(input[i].toLowerCase())){temp+=input[i]}else{let changeLetter=letters[(letters.indexOf(input[i].toLowerCase())+amount)%26];temp+=isUpperCase(input[i])?changeLetter.toUpperCase():changeLetter}}
return temp}console.log(rot13("Hello World!!",14))
The code is really messy, if you want to see a less messy version click the link above

Last edited by gosoccerboy5 (March 3, 2021 23:44:09)


mybearworld
Scratcher
1000+ posts

Programming challanges!

gosoccerboy5 wrote:

My really inefficient and dumb rot13 program
function rot13(input,amount=13){const letters="abcdefghijklmnopqrstuvwxyz";let temp="";const isUpperCase=function(text){return text.toUpperCase()===text};for(let i=0;i<input.length;i++){if(!letters.includes(input[i].toLowerCase())){temp+=input[i]}else{let changeLetter=letters[(letters.indexOf(input[i].toLowerCase())+amount)%26];temp+=isUpperCase(input[i])?changeLetter.toUpperCase():changeLetter}}
return temp}console.log(rot13("Hello World!!",14))
The code is really messy, if you want to see a less messy version click the link above
xD I mean mine isn't better

Signatures are the only place where assets links still work.
gosoccerboy5
Scratcher
1000+ posts

Programming challanges!

mybearworld wrote:

xD I mean mine isn't better
I feel like yours was a bit more concise than mine, idk

mybearworld
Scratcher
1000+ posts

Programming challanges!

gosoccerboy5 wrote:

mybearworld wrote:

xD I mean mine isn't better
I feel like yours was a bit more concise than mine, idk
How can it be more concise, there's only work or no work

Signatures are the only place where assets links still work.
mybearworld
Scratcher
1000+ posts

Programming challanges!

Last edited by mybearworld (March 29, 2021 12:47:25)


Signatures are the only place where assets links still work.
gosoccerboy5
Scratcher
1000+ posts

Programming challanges!

mybearworld wrote:

Opinions on
How will you inspire?
anyone?
How can I have an opinion on it if I don't know what it is

mybearworld
Scratcher
1000+ posts

Programming challanges!


Signatures are the only place where assets links still work.
gosoccerboy5
Scratcher
1000+ posts

Programming challanges!

Um.. any challenges?

mybearworld
Scratcher
1000+ posts

Programming challanges!

gosoccerboy5 wrote:

Um.. any challenges?
How about… idk, a text reserver? With as few characters possible?
r=lambda x:x[::-1]
That's 19 (and python.) Can anyone beat that

Signatures are the only place where assets links still work.
ScratchCatHELLO
Scratcher
1000+ posts

Programming challanges!

mybearworld wrote:

gosoccerboy5 wrote:

Um.. any challenges?
How about… idk, a text reserver? With as few characters possible?
r=lambda x:x[::-1]
That's 19 (and python.) Can anyone beat that

not sure if it's possible to beat this legitimately

I made a function on my “”“programming language”“” for reversing strings
:REV(x)
if this counts, it's technically 7 characters

this is the backend of the function
@_('REVERSE "(" expr ")"')
def expr(self, p):
    return str(p.expr)[::-1]

human-readable:
  1. scan for REVERSE token (which is the “:REV” text) followed by an expression in parenthesis
  2. not sure what this is doing, but I think it's just defining what the expression does
  3. returns the (string form, so that entering a number doesn't crash python) expression reversed.

mybearworld wrote:

Write a rot13 program - and try to support case sensing as well.

letters = 'abcdefghijklmnopqrstuvwxyz'
def rot13(input):
    txt = ''
    for char in input:
        if not letters.find(char.lower()) == -1:
            tmp = letters[(letters.find(char.lower())+13)%26]
            if char.isupper():
                txt += tmp.upper()
            elif char.islower():
                txt += tmp
        else:
            txt += char
    print(txt)
while True:
    rot13(input("input> "))

this code isn't very good or fast and could probably be simplified, but it still took me a while to fix the variety of errors I got when I first typed it (like putting the modulo in the wrong part of the big weird index thing). actually, a significant section of the code is case-sensitivity and error handling. the rot13 part itself is one line.





ScratchCatHELLO
I have 5600+ posts, I've been on scratch for 5 1/2 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust



Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y
ScratchCatHELLO
Scratcher
1000+ posts

Programming challanges!

bump





ScratchCatHELLO
I have 5600+ posts, I've been on scratch for 5 1/2 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust



Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y
gosoccerboy5
Scratcher
1000+ posts

Programming challanges!

Can we have another challenge? I know, you beat us. Python is infinitely superior. Now, can we get a good challenge?

mybearworld
Scratcher
1000+ posts

Programming challanges!

gosoccerboy5 wrote:

Can we have another challenge? I know, you beat us. Python is infinitely superior. Now, can we get a good challenge?
xD
Maybe generating Fibonacci numbers?
Okay, put this in your url bar if you want to see how I did it (if you want to do it first by yourself

Python
data:text/plain;base64,ZiA9IFswLDFdCnByaW50KCIwIHwgMSAiLGVuZD0iIikKd2hpbGUgVHJ1ZToKICAgIGYuYXBwZW5kKGZbLTFdK2ZbLTJdKQogICAgcHJpbnQoZiJ7ZlstMV19IHwgIixlbmQ9IiIpCg==

Two browser crashs later

Javascript
data:text/plain;base64,dmFyIGYgPSBbMCwxXTsKY29uc29sZS5sb2coMCk7CmNvbnNvbGUubG9nKDEpOwpmdW5jdGlvbiBmaWIobnVtKSB7CiBmLnB1c2goZltmLmxlbmd0aC0xXStmW2YubGVuZ3RoLTJdKTsKIGNvbnNvbGUubG9nKGZbZi5sZW5ndGgtMV0pOwogaWYgKG51bSAhPSAwKSB7IGZpYihudW0tMSk7IH0KfQpmaWIoMjApOyAvLyBZb3UgY2FuIG1vZGlmeSB0aGlzIG51bWJlciB0byBnZXQgbW9yZSBudW1iZXJzIChjYW4ndCBydW4gaXQgaW5maW5ldGVseSBoZXJlIGJlY2F1c2UgaXQgY3Jhc2hlcykK

Last edited by mybearworld (April 21, 2021 16:53:28)


Signatures are the only place where assets links still work.
gosoccerboy5
Scratcher
1000+ posts

Programming challanges!

mybearworld wrote:

gosoccerboy5 wrote:

Can we have another challenge? I know, you beat us. Python is infinitely superior. Now, can we get a good challenge?
xD
Maybe generating Fibonacci numbers?
https://www.khanacademy.org/computer-programming/fibonacci/6651822062649344
It uses recursion to recalculate the value every time, which is inefficient tho (also don't go above 30 or it will crash)

also, I applied the same technique to factorials

dart:
List FIB_LIST = <int>[0, 1, 1, 2];
void main() {
  for (int i = FIB_LIST.length; i < 50; i++) {
    FIB_LIST.add(FIB_LIST[i - 1] + FIB_LIST[i - 2]);
  }
  print(FIB_LIST.length);
}

Last edited by gosoccerboy5 (April 21, 2021 16:50:40)


gosoccerboy5
Scratcher
1000+ posts

Programming challanges!

OK, what about.. parsing and converting roman numerals to normal numbers?

mybearworld
Scratcher
1000+ posts

Programming challanges!

gosoccerboy5 wrote:

OK, what about.. parsing and converting roman numerals to normal numbers?
Nice! I hope this is nothing that will cause javascript to crash… again.
I'm going to start in python though xD

Signatures are the only place where assets links still work.
gosoccerboy5
Scratcher
1000+ posts

Programming challanges!

Incomplete code:
function parseRN(numeral) {
  numeral = numeral.toUpperCase();
  let result = 0;
  let keys = {
    "I": 1, "V": 5, "X": 10,
    "L": 50, "C": 100, 
    "D": 500, "M": 1000,
  };
  for (i in numeral) {
    if (keys[numeral[i]] === undefined) {
      throw "Invalid Roman numeral";
    }
    result += keys[numeral[i]];
  }
  return result;
}
console.log(parseRN("MDCCCLXVII"));
It'll only get harder from here..

Last edited by gosoccerboy5 (April 21, 2021 17:07:26)


Powered by DjangoBB