Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » Programming challanges!
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
Would something like “IV” work like that? 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"));
Signatures are the only place where assets links still work.
- gosoccerboy5
- Scratcher
1000+ posts
Programming challanges!
No, hence the “incomplete”. I am working on it Would something like “IV” work like that?
- ScratchCatHELLO
- Scratcher
1000+ posts
Programming challanges!
Maybe generating Fibonacci numbers?
def fibonacci(num): list = [1, 1] i = 2 while i < num: list.append(list[i-1] + list[i-2]) i += 1 return list print(fibonacci(int(input("How Many? | "))))
how about detecting if a number is divisible by another?
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!
how about detecting if a number is divisible by another?
actually that's probably not that hard
def divisible(number, divider): return int(number)%int(divider)==0 while True: print(divisible(input('number to divide | '), input('divisor | '))) print('----------------------------------')
how about checking if a number is prime?
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!
I mean technically you could use brute force, but.. how about checking if a number is prime?
That's extremely difficult, if only there were a built in language construct for that? how about detecting if a number is divisible by another?
Last edited by gosoccerboy5 (April 21, 2021 20:04:00)
- ScratchCatHELLO
- Scratcher
1000+ posts
Programming challanges!
I mean technically you could use brute force, but.. how about checking if a number is prime?That's extremely difficult, if only there were a built in language construct for that? how about detecting if a number is divisible by another?
sorry
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
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
Sigh, if you could only doThat's extremely difficult, if only there were a built in language construct for that? how about detecting if a number is divisible by another?
x%y == 0
Alright, that's not going to be too hard. how about checking if a number is prime?
def is_prime(x, divider=False): for i in range(int(x)-1, 1, -1): if x%i == 0: return (False, i) if divider else False return (True, 1) if divider else True while True: y = input("Please enter a number:") if y=="stop": break try: y = int(y) except: print("Please enter a whole number.\n") continue print(f"{y} is{'' if is_prime(y) else '''n't'''} prime\n")
is_prime(3, divider=True) will give you (True, 1) as it is prime, so only divisible by one or itself.
Last edited by mybearworld (April 22, 2021 11:34:58)
Signatures are the only place where assets links still work.
- ScratchCatHELLO
- Scratcher
1000+ posts
Programming challanges!
I'm still trying to figure out how to do roman numerals, but meanwhile I was trying to do other practice things and at some point I realized one of the challanges was to write the function that validates your function that validates your function that validates your function that validates your function
(read bottom left)
(read bottom left)
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
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
on that validates your function that validates your function that validates your function“The code must contain () for the parameter list I'm still trying to figure out how to do roman numerals, but meanwhile I was trying to do other practice things and at some point I realized one of the challanges was to write the function that validates your functi
(read bottom left)
The code must not return ()”
Eh…
Signatures are the only place where assets links still work.
- ScratchCatHELLO
- Scratcher
1000+ posts
Programming challanges!
on that validates your function that validates your function that validates your function“The code must contain () for the parameter list I'm still trying to figure out how to do roman numerals, but meanwhile I was trying to do other practice things and at some point I realized one of the challanges was to write the function that validates your functi
(read bottom left)
The code must not return ()”
Eh…
you can do ‘(’ + ‘)’ to avoid that, but yeah.
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
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
Oooh, I understand what it wants from me. Alright, that's simple…
chr(40)+chr(41), because I'm not allowed to put () in my code
def validate(code): if not "def" in code: return "missing def" if not ":" in code: return "missing :" if chr(40)+chr(41) in code: return "missing param" if not (")" in code and "(" in code): return "missing paren" if not ("\t" in code or " "*4 in code): return "missing intend" if not "return" in code: return "missing return" if not "validate" in code: return "wrong name" return True
Signatures are the only place where assets links still work.
- ScratchCatHELLO
- Scratcher
1000+ posts
Programming challanges!
Oooh, I understand what it wants from me. Alright, that's simple…chr(40)+chr(41), because I'm not allowed to put () in my codedef validate(code): if not "def" in code: return "missing def" if not ":" in code: return "missing :" if chr(40)+chr(41) in code: return "missing param" if not (")" in code and "(" in code): return "missing paren" if not ("\t" in code or " "*4 in code): return "missing intend" if not "return" in code: return "missing return" if not "validate" in code: return "wrong name" return True
yeah, that was basically what their solution was
I did it using loops instead, which isn't very good for this but might work better if there were more criteria
required = { 'def': 'missing def', ':': 'missing :', '(': 'missing paren', ')': 'missing paren', ' ': 'missing indent', '(' + ')': 'missing param', 'validate': 'wrong name', 'return': 'missing return' } def validate(code): for item in required: if item == '(' + ')': if item in code: return "missing param" else: if not item in code: return required[item] return True
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
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
class Roman: romanConvert = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000} romanLetters = romanConvert.keys() def __init__(self, x): self.number = str(x).upper() def __int__(self): x = -1 result = 0 while True: x += 1 if x != len(self.number)-1 and self.romanConvert[self.number[x+1]] > self.romanConvert[self.number[x]]: result += self.romanConvert[self.number[x+1]]-self.romanConvert[self.number[x]] x += 1 else: result += self.romanConvert[self.number[x-1]] if x == len(self.number)-1: return result # I finally did it! print(int(Roman("XXIV")))
Last edited by mybearworld (June 3, 2021 20:51:20)
Signatures are the only place where assets links still work.
- gosoccerboy5
- Scratcher
1000+ posts
Programming challanges!
I hate to burst your bubble, but I think XXIV means 24.. your program says 19.. Yay! Roman Numerals!
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
[View post]Oooops.I hate to burst your bubble, but I think XXIV means 24.. your program says 19.. Yay! Roman Numerals!
Last edited by mybearworld (Sept. 24, 2022 14:16:18)
Signatures are the only place where assets links still work.
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
Bump after >6 months.
Get an input from 0-4. Undefined behavior for anything different. For each number, raise a different error.
Rules:
Example (87 bytes, Python 3):
Have fun!
Get an input from 0-4. Undefined behavior for anything different. For each number, raise a different error.
Rules:
- Do not use functions made to error, like Python's raise
- If your programming language gives more information then just the error, than just the error counts. For example, in Python again, errors in line 1 and 4 won't be counted different, and “unsupported operand type(s) for +: ‘int’ and ‘tuple’” and “can only concatenate list (not ”dict“) to list” aren't different errors, because they're both “TypeError”s
- Please say which errors are caused, and (optionally, but would be great), why.
Example (87 bytes, Python 3):
x=int(input())
if x==0:1/0
if x==1:x()
if x==2:f"{a}"
if x==3:eval("def")
x.x
- 0 returns a ZeroDivisionError, no explanation needed
- 1 returns a TypeError, because you can't run an integer. x is set as an integer, as it is what the user's answer is stored in. 1() would work just as well, but it also gives a SyntaxWarning.
- 2 returns a NameError. I couldn't just use a simple “a”, because Python would complain. By putting it in an f-string, it only evaluates it when it needs to.
- 3 returns a SyntaxError. This couldn't be put into an f-string, because you can't use defs in f-strings. Eval will still allow this.
- 4 (and any other number, but that's undefined behavior) returns an ArgumentError, because an integer does not have the argument x.
Have fun!
Last edited by mybearworld (Feb. 19, 2022 11:26:10)
Signatures are the only place where assets links still work.
- ScratchCatHELLO
- Scratcher
1000+ posts
Programming challanges!
What if you don’t define anything for 4?
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
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
You need to error for 4 too What if you don’t define anything for 4?
Signatures are the only place where assets links still work.
- applejuiceproduc
- Scratcher
1000+ posts
Programming challanges!
Mine is even shorter:How about… idk, a text reserver? With as few characters possible? Um.. any challenges?That's 19 (and python.) Can anyone beat thatr=lambda x:x[::-1]
./.py
#usr/bin/python3
Last edited by applejuiceproduc (Feb. 21, 2022 08:27:58)
A signature
- mybearworld
- Scratcher
1000+ posts
Programming challanges!
That doesn't count
Signatures are the only place where assets links still work.
- Discussion Forums
- » Things I'm Making and Creating
- » Programming challanges!