Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » Programming challanges!
- 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.
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)
- gosoccerboy5
-
Scratcher
1000+ posts
Programming challanges!
My really inefficient and dumb rot13 program
The code is really messy, if you want to see a less messy version click the link above
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))
Last edited by gosoccerboy5 (March 3, 2021 23:44:09)
- mybearworld
-
Scratcher
1000+ posts
Programming challanges!
My really inefficient and dumb rot13 programxD I mean mine isn't betterThe code is really messy, if you want to see a less messy version click the link abovefunction 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))
- gosoccerboy5
-
Scratcher
1000+ posts
Programming challanges!
xD I mean mine isn't betterI feel like yours was a bit more concise than mine, idk
- mybearworld
-
Scratcher
1000+ posts
Programming challanges!
How can it be more concise, there's only work or no workxD I mean mine isn't betterI feel like yours was a bit more concise than mine, idk

- mybearworld
-
Scratcher
1000+ posts
Programming challanges!
Last edited by mybearworld (March 29, 2021 12:47:25)
- gosoccerboy5
-
Scratcher
1000+ posts
Programming challanges!
Opinions onHow can I have an opinion on it if I don't know what it isHow will you inspire?anyone?
- mybearworld
-
Scratcher
1000+ posts
Programming challanges!
Um.. any challenges?How about… idk, a text reserver? With as few characters possible?
r=lambda x:x[::-1]

- ScratchCatHELLO
-
Scratcher
1000+ posts
Programming challanges!
Um.. any challenges?How about… idk, a text reserver? With as few characters possible?That's 19 (and python.) Can anyone beat thatr=lambda x:x[::-1]
not sure if it's possible to beat this legitimately
I made a function on my “”“programming language”“” for reversing strings
:REV(x)
this is the backend of the function
@_('REVERSE "(" expr ")"') def expr(self, p): return str(p.expr)[::-1]
human-readable:
- scan for REVERSE token (which is the “:REV” text) followed by an expression in parenthesis
- not sure what this is doing, but I think it's just defining what the expression does
- returns the (string form, so that entering a number doesn't crash python) expression reversed.
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.
- 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!
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)
- gosoccerboy5
-
Scratcher
1000+ posts
Programming challanges!
https://www.khanacademy.org/computer-programming/fibonacci/6651822062649344Can 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?
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!
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
- gosoccerboy5
-
Scratcher
1000+ posts
Programming challanges!
Incomplete code:It'll only get harder from here.. 
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"));

Last edited by gosoccerboy5 (April 21, 2021 17:07:26)
- Discussion Forums
- » Things I'm Making and Creating
-
» Programming challanges!



