#ot1-perplexing-regexing
1 messages · Page 483 of 1
so if i use debian baed i cant join?
the gurkult emphasizes freedom, we dont force you :3
the channel died. but it is okay. gotta finish some assignments
bye

nice
i guess return doesnt want me to return :((
^^lol nice nickname
you know how like if something in C returns 1 or more its an error
idk i never used C
good wisdom man
so did length figure out what ara ara meant
we thought length was a sheltered person and didnt want to search it
he was asking what it meant
its not
but didnt want to search it
whats wrong with a quick google search
that gy told me to not search
so i didnt
dudes
dudes
yeha
dont fight now k?
but we arent
both won
well u sound you were so..
huh?
lmao
ok
just kidding
lol
everything
Its js that's what is wrong with it
yeah i might learn Rescript or Elm in the future. fudge
uhh rip ping
Jesus I only got through the first box of examples and I already hate it
who decided it should work like that
I've seen a lot of instances about this
what examples?
And lemme just stress the response
the Type Coercion picture
what examples?
#ot1-perplexing-regexing message
"Wow, JS does weird things when you do things you normally won't do except to prove a weird point"
Js is annoying
Yeah
I don't encounter most of these examples
Except for the array comparison, oh my God
yeah. don't rly need to know that in web devs
I did a Kata last night. Worked, and it needed to not time out on very large input lists, but it was like 30 lines and sorta kludgy. But I got to look at the solutions after...
the right way to do it is 5 short beautiful lines
'right way'
What I've found with the site is if you want to golf your answer you can
But as long as it functions you've solved it
which kata?
Yeah, I think that it's meant to work like that. A kata is meant to be something that you basically achieve the form and then you iteratively improve upon it to become more efficient. But cramming my solution down into fewer lines wouldn't have helped because I was approaching the problem backward
or rather
the correct way is to do it backwards.
ah
Do I need to be good at algs?
Imo i don't find it helps me much but I think people that learn with tutorial/videos should do it. It's super useful to find use cases for different funcs/etc
Nope the basic ones are pretty basic
It's more about understanding the logic
i think my problem to solve kata is that I often look it up. Like formula or smth. is that bad?
If you're good at recognising the form of problem you're looking at and research how to solve that problem correctly... I think that's more of a critical skill rather than cheating
Yeah that's what I mean I guess
otherwise you need to basically be able to rederive obscure branches of math to solve some problems and that's just doing things the hard way
It's important to understand how each part of the algo/formula works and what it does tho
Ya
Oh, yeah, ideally you should understand what you're implementing
I'm good at math, but still need practice to implement it in code
but if you need to look at an example to learn then might as well do that
If you just find an answer and copy it, you might know how to solve that specific problem but you're not learning anything
I find for myself I really have a hard time learning anything without a complete example
That comes with experience but like most of the super simple katas don't require much technical skill they're more for teaching you how to approach more logical based problems
Altho technical skill/knowing how and when to golf can be useful too
tbh when are solving algs useful for?
Like I don't think you need them in real projects
not at that level
I think a fresh CS student should start with Algorithms and Data-Structures and most of them won't occur in day to day life. They have importance in interviews so
They're usually applicable in one way or another
That's one thing I've been disliking about uni
If I wasn't learning on the side I think I wouldn't be able to function once if I graduate
I think same thing if you are only good at solving algs, but never did projects or smth
Yeah this is the reason why I got out of Algorithm and DS, started learning new things
Well ya even if you have a project that uses a specific algo, it's not going to be the whole project
and I am enjoying it more than practicing whole day
Yeah that's why I try to learn from doing projects than kata daily
I like doing Kata if I'm bored
but I'll get back to codewars again lol. For interview I guess
Then again I like puzzles
leetcode is better
I find the katas good because I have some kind of problem thinking up good projects to tackle that are within grasp of my current level
I find I occasionally get inspiration for ways to solve a specific issue I've got too
Am I meant to be solving these in, like, 30 minutes? I always feel like I need at least an hour
Probably with experience
Na I think the longest I've spent on one was like 3hrs
[F]
im so confused this is worded so poorly
"Given an array of numbers and an index, return the index of the least number larger than the element at the given index, or -1 if there is no such index ( or, where applicable, Nothing or a similarly empty value )."```
I was thinking that meant the value with the smallest difference
apparently not
huh
like with that logic the second one should be 5
Yeah no, I get it, it is worded kinda strangely
I actually don't know what it's asking
First example: it gives you index 0. That value is 4. You need to find the smallest number in the list that is bigger than 4 and give that number's index
yeah i would think that shold be 5
also the fact that -1 is acceptable as an invalid index pisses me off
Yeah it should be None in my opinion
I mean, I'm grappling with a cipher problem now and it's got multiple layers including dividing the message into 5 parts, but the rules for dividing up the message doesn't work if your message is 11 characters long
I'm just hoping that never comes up.
Haaaaaa
I'm kinda confused. smallest number in the list that is bigger than 4?
b r u h
ya the smallest difference between numbers bigger than the number at the index and the number at the index
not the least number larger than the element at the given index
the least number
trying to code shouldn't feel so much like having a stroke
you'd think
ty
hmm, i can think of a cheaty solution
I did it in 3 lines im so proud of myself
na it's not
def least_larger(a, i):
ind, lst = a[i], []
[lst.append(item) for item in a if item > ind]
return a.index(min(lst)) if len(lst) > 0 else -1```
oh dang I could've done it in 1
The solution i have in my mind is definitely cheating
def least_larger(a, i):
return min(((n, c) for c, n in enumerate(a) if n > a[i]), default=(0,-1))[1]```
what did you have in mind
JEEZ. That one certainly dragged out longer than I would have liked. I feel like that one really had too many steps to be considered a kata...
Encode message, attach key, cut up. And also the decode of it. So it's, like, six things
what level?
5 kyu
that's not too bad for 5
oh look, it's the function that I knew must exist but couldn't remember it or see it in the references: ord()
def least_larger(array, index):
return sorted(array).index(array[index]) + 1
print(least_larger([4, 1, 3, 5, 6], 0))
@versed saffron
i feel it is cheating since I sort the array
would that not mutate the indices tho?
what happens if you're given a 5, but there's another 5 in the list?
doesn't matter, return the first instance
I didn't think that far ahead actually
but I passed them all so 🤷♂️
def least_larger(array, index):
return array.index(sorted(array)[sorted(array).index(array[index]) + 1])
print(least_larger([4, 1, 3, 5, 6], 0))
looks ugly
but works
still better than the enum answers
wait i gotta make one more change so that it will return -1
but it will just make it even uglier 😂
def least_larger(array, index):
return array.index(sorted(array)[sorted(array).index(array[index]) + 1]) if array[index] != max(array) else -1
print(least_larger([4, 1, 3, 5, 6], 0))```
@versed saffron
pep8: Am I a joke to you?
same
that is not
I like golfing to the point where it's still readable
def accum(s):
return "-".join([i.upper() + i.lower()*s.index(i) for i in s])```
any idea why this is happening
like it's just cutting off letters
32 passed 88 failed wth
have no idea what I'm doing wrong
def least_larger(a, i):
answer = []
for inc in a:
if inc > a[i]:
answer.append(inc)
return -1 if answer == [] else a.index(answer[0])
btw it's been awhile
min(ans) works too
Omg it passed
congrats
lol ty. I accidently typed a.sort() instead of answer.sort()
thought I was missing something
anyway to do this without for loop?
you can't
you can use list comp but you need to iterate through them
ig you can use enum but it's 'pretty much' the same thing
I see. Should I learn list comp? I prefer "normal" code lol
actually, list comp looks fun
list comp's super nice when you need to generate a 'simple' list and want it in 1 line
@property
def armour_list(self):
return [getattr(self.Armour, attribute) for attribute in self.armour_slots]```
List comp is actually very nice to use
not a great example but I just did that
concise and efficient
any idea why this is happening
@versed saffron in case you haven't solved it yet, look what happens when characters have multiple occurences in the string
what's wrong with this? answer = [for inc in a if inc > a[i]]
wth why would that affect it?
you need something before your for
oh oops
.index, numpy
but im not mutating the original string?
ohh
shit maybe I can't do this in one line
you can
do i need to replace chars in the string?
no, you can't do that in python anyway
look into enumerate
it's sensibly the same thing as your solution
but with something other than .index
(and a tiny bit longer tho)
oh ok I see how to use it
I've actually been meaning to learn it but I've never had a use
I think you don't need the .lower() btw, isn't the input constrained to only alphabetical characters ?
https://www.codewars.com/kata/5877e7d568909e5ff90017e6/python I understand the problem but not how to tell the computer how to do it. I think that means that I should stay on this problem so that I learn.
def least_larger(a, i):
answer = []
s = [answer.append(inc) for inc in a if inc > a[i]]
return -1 if answer == [] else a.index(answer[0])
ah right
Getting better
does capitalize() switch cases around?
maybe?
swapcase() does
oh wait
capitalize just makes the firdst character of the string uppercase
maybe you can use title()?
or (c+c*i).lower().capitalize()
#bot-commands message
it (capitalize()) only capitalizes the very first character of the string
I'll try title tho didn't know that was a thing
def accum(s):
return "-".join([(v*(c+1)).title() for c, v in enumerate(s)])```
kata so fun
def sum_digits(number):
string = []
total = 0
for s in str(abs(number)):
string += s
for n in string:
total += int(n)
return total
how's my logic?
@rough sapphire no, I'm going to take a break maybe for the day and let it percolate. My first idea involved recursion but that might not be necessary
yeah recursion wont work
it will be 1e17 calls
I think there is some greedy way to do this
@frozen thorn why not modify the number directly instead of making it to string and then using that string
hm Idk how to access first digit. That's why I converted int to str
@frozen thorn what’s up with the nick?
haah I forgot
while number > 0:
total += number % 10
number = number // 10
return total
to add that name
from collections import Counter
from string import ascii_letters
def is_pangram(s):
for i in ascii_letters:
if Counter(s.lower())[f"%s"%i] >= 1:
valid = True
else:
return False
return valid```
anyway to golf that? im lost
I could convert it to str then add it to total like this total += int(s)
so no need for string = []
that's weird actually if I use [chr(i) for i in range(ord('a'),ord('z')+1)] it works but ascii_letters doesn't
Ya, my idea works
def sum_digits(number):
total = 0
for s in str(abs(number)):
total += int(s)
return total
lol i attempted list_comp = [total += int(s) for s in str(abs(number))], Looks like I need to learn more about list comp
code format is annoying
def sum_digits(number):
return sum(int(i) for i in str(number))
I assume this would work
!e ```py
def sum_digits(number):
return sum(int(i) for i in str(number))
print(sum_digits(6326))
@narrow pecan :white_check_mark: Your eval job has completed with return code 0.
17
it wont cause a recursion error?
Lovely
Nope
LOveLy
is my way bad?
nah
it fine
If you want it pythonic, you could probably improve my solution as well. It works and is short, and I heard code golf hahah
You have a good solution but I don't really like copying others
that's the best part tho :)
I would've done the same if I had more experience solving katas tho
wow
!e
You are not allowed to use that command here. Please use the #bot-commands channel instead.

Could you explain how module works with this?
which module?
I meant modulo
its the remainder you get after you do division
Ya
hmm
lets say you want to find a % b
it is equal to
r = a - k * b
where K is integer division of a and b
K = a / b
ah i thought k is the remainder
what does x do here? Is it just a variable?
x is any number
oh so an assign?
I mean to write number % 10 but i am lazy 🥴
no x % 10 just gives you the remainder when x gets divided by 10
sry lol. Where does the number in x come from? How does it know which remainder?
do you have to assign to x then?
yes
That's why i was confused. Like why does x even exist. now i get it..
lol sorry for confusion. I am bad at explaining things
sorry to interrupt
def delete_nth(order,n):
lst = []
for i in order:
if collections.Counter(lst)[str(i)] < n:
lst.append(i)
return lst```
`order` being a list with dups, `n` being the max amount of dups allowed
It's not doing anything and if I do `n-1` it's returning an empty list
collections.Counter(lst)[str(i)]
will this get executed?
ya but it shouldve just been Counter(lst)[i]
def number(lines):
arr = {"a": "1: a", "b": "2: b", "c": "3: c"}
print(arr["a"])
print(number(["a", "b", "c"])#, ["1: a", "2: b", "3: c"]))
I'm getting an error unexpected EOF while parsing
oh nvm lol. Missed a )
I just googled x
gon give it to ya
what
x gon deliver to ya
uh
I skipped the other part
I was wondering if you were gonna do that or censor it
do i do it
naa that got old quick
aww man
hm anyone wanna help me with this kata? Don't think i understand the desription or there's not enough test cases
Your team is writing a fancy new text editor and you've been tasked with implementing the line numbering.
Write a function which takes a list of strings and returns each line prepended by the correct number.
The numbering starts at 1. The format is n: string. Notice the colon and space in between.
your code is above right?
I think you can just run a for loop and modify the list itself
ah i got it
def number(lines):
result = []
n = 1
for char in lines:
result.append(str(n)+": "+char)
n += 1
return result
yep
I thought I had to use dict
I mean the description was not clear enough lol and there's only 1 test case
So i thought "a" is always "1: a"
I got it in my first try
nice
on my first try or in my first try 🤔 ?
btw @frozen thorn , try using enumerate
!enumerate
Ever find yourself in need of the current iteration number of your for loop? You should use enumerate! Using enumerate, you can turn code that looks like this:
index = 0
for item in my_list:
print(f"{index}: {item}")
index += 1
into beautiful, pythonic code:
for index, item in enumerate(my_list):
print(f"{index}: {item}")
For more information, check out the official docs, or PEP 279.
lol
def number(lines):
for i, line in enumerate(lines):
lines[i] = f"{i+1}: {line}"
return lines```
ya
should have appended to a new list, but w/e
can you do that with list_comp?
yes
I was actually gonna see if I can do with list comprehension
def number(lines):
return [f"{i + 1}: {line}" for i, line in enumerate(lines)]
def number(lines):
return [f"{i+1}: {line}" for i, line in enumerate(lines)]
works
lol
yeah
lmao
lol
nice
🤯
def number(lines):
#your code here
result = {}
count = 1
for i in lines:
result[count] = i
count +=1
final = []
for i in result:
final.append(str(i)+":"+" "+result[i])
return(final)
Not mine btw
well I'm glad I got back to katas
did the dude with the zip() solution delete their messages?
ya
hmm I think I will be kyu 6 tomorrow
Interesting, there is Roman Numerals Encoder in Kyu 6. Will do it tomorrow
Gn
https://www.codewars.com/kata/51b62bf6a9c58071c600001b/train/python if anyone want it
f
its not hard its annoying
ah
@tawny bronze could you stop spamming the help channels? if you want help go read #❓|how-to-get-help
ok i understood
you will be opm soon
What’s opm
Original Punk Music
Tf
except for IVOS
@cosmic lotus hmmm i think i like autotelic more
@rough sapphire hmmmmm
👌
f
hmmm
linuxuser
it is kinda weird that it is not vester who made the rule that there should be gurkan in our nicknames

i thought being gurkan embodies freedom
irdk ngl , ask vester

that defeats the point of 'freedom'
I am in jail
wtf
haven't seen the outside in almost two weeks
can someone recommend a book.. on how to break out of jail
dunno
can you come visit me
@rough sapphire youre in japan? i am not gonna kamikazee my way in
yeah
I'm in quarantine
whats the reason youre imprisoned?
quarantine is 2 weeks
who isn't
oh lol...
🎵 I am fucking kamakazi crashing into everything 🎵
well I can't leave this room.. at least you can go out
i mean yeah who isnt 😦
we can?
well I can't leave this room.. at least you can go out
@rough sapphire you cant leave your room?!
how the hell did that happen?
ROOM?!?!?
yes, if I leave.. they will arrest me
You got ... cor...?
no no
huh? under what grounds? was there a new protocol or something
nah, Tron was probably travelling
yeah I travelled to another country lol
why lol
classified
anyways.. it sucks.. I think I lost a lot of weight
it's not leisure travel
what the fuck is covid-19
covid-19 is the release before covid-20
covid-20 pre release
ah so 19 is prequel to 20
yes.. add as many versions as possible
I heard EU just got the second version
Cool
Yes it's a huge update
The hype tho
then world war 4
you mean world war Z
covid release schedule:
covid-19.04
covid-19.10
covid-20.04 (LTS)
first, lets focus on the zombies release
Canonical?
covid release schedule:
covid-19.04
covid-19.10
covid-20.04 (LTS)
@rough sapphire ah sounds like evil
Canonically evil
fits their company name

Oh also ig 20.04 LTS is gonna go into snap store
it sounds cooler than Umbrella Corporation
maybe the name has an influence over them
so if a name is related to something evil
😮
they become evil

so anyways.. World War Z
Guys any PRs to covid-19 yet?
Guys any PRs to covid-19 yet?
@lunar shore there is a lot
Oh nice
git commit --amend -m "Release Zombies in France"
That'd be enough for hacktoberfest ig
git commit --amend -m "Release Zombies in France"
@solid pollen wat do you think?
It'll get accepted
noice
Depends on where you release them
Also , the server was in China right?
If you release it in the north part of the country, I'm pretty okay with that
Hmm, I'd be a little less fine with that
i see i see.
yes..
Also , the server was in China right?
@lunar shore that's the reason for the latency and throughput issues..
It was digital ocean?
so when will we merge the patch to the main branch?
It was digital ocean?
@lunar shore whats this about digital ocean and china?
idk , we have to wait for our PR to be completly tested . It's so heavy
no time for testing, let's release it and fix the bugs in production
There could be a bug
we're too close to end of 20.. have to merge all these PRs before then
idk , we have to wait for our PR to be completly tested . It's so heavy
@lunar shore i thought we just only changed the location? did you edit some lines like the stats for each zombie types?
That terminates the program . And the cases will go down to 0
Oh yes , forgot to commit it tho
oh lol
i am adding baby zombies too dont PR yet
Oh no that'd be so much bugs to be fixed . Oh wait ... there is a development branch? I pushed to master lmao
Oh no that'd be so much bugs to be fixed . Oh wait ... there is a development branch? I pushed to master lmao
@lunar shore no github says it is 'main' now
oh ok ig I can revert that
did you already know that we config to git config --global init.defaultBranch main?
We have to change somethings tho , covix 's node library is getting heavier
State management would be hard
Without covix
ah okay. well you also did the rust code for the backend too
so we can collect data
thanks
tron went silent
what is he doing with the development branch?
Waaaiiit
Tron
What have you done
It has gone from 1 gb to 10 gb
tf
Oh my lord ... YOU COMMITED NODE_MODULES BRUH
Tron i thought you will assist me making the feature/zombie babies from the development branch?
git push origin master --delete
Tron is thinking about his reply lets wait
git push origin master --delete
@rough sapphire we use main now
not master
yeah
that will result to an error
I'm still on an older version of git.. isn't this going through
nah we can still move the head to main. and set it as the default branch
git push origin master: iirc on older versions
It will ask git to make the remote master point to nothing, and so delete it
Ok I dettached head
Or you can do it from your git provider web UI most of the time
Tron i thought you will assist me making the
feature/zombie babiesfrom the development branch?
@mild abyss what is this ugly space
okay. i will go back editing the genomic sequence of the virus while i am also making a phylogenetic tree to keep the track of the changes
@mild abyss what is this ugly space
@solid pollen my bad
we still gotta plan for features to come after our zombies release
imma send a pic in 2 minutes so you can see the changes
Should we postpone 20.04 to youtube rewind 2020?
I don't want cringy vids of our product in youtube rew
I am dreading YT rewind.. hopefully they don't think less of our product and push some feel good bs
Yeah
niiice
we should base the patch on covid19 patch auritaa
mk imma write an essay for my school now
@lunar shore mhm mhm
hi
@strong valley Please don't dump random gifs here
i have a problem with some latex i wrote:
\newpage
this is a example sentance:
\begin{table}[]
\centering
\begin{tabular}{l|l|l|l}
....
\end{tabular}
\end{table}
my problem is that for some reason the table gets rendered above my example sentence 😦
huge table obviously
Seriously though, h seems to stand for here, t is top and b is bottom
yeah that's right
Ah I need to learn latex
lol
huge table sounds good to me haha
thanks for explaining it 🙂
i've seem some people take notes using latex in real time and that just blows my mind.. probably the same people that use all the VI shortcuts lol
Once you get used to the latex syntax it's amazing for math notes
I am faster in latex than I am hand writing equations, even for complex stuff
haha exactly
ha no, I think my comfortable rate is 80-100, 110+ if I focus
i consider myself a pretty fast typer, but i cant get anywhere as fast speed as handwriting. taking notes in latex would help me so much
my handwriting becomes unreadable after ~20min of writing
anything after that is me clenching a pen and squiggly lines resembling letters
I consider myself a lazy typer, I do around 40 WPMs, 60 if I focus lol
And my handwriting just is unreadable
i get like 70wpm :/
Bro I feel the handwriting, I average 90 WPM and can't write for the life of me
Ad my handwriting just is unreadable
@solid pollen u havent seen mine yet xD
I have a very hard time putting letters in the right order lately weirdly enough, so it is even worst, they are letters squishing in between and things like that lol
mine is like a cat scratching a paper
I haven't written anything on paper in years
#programmer-life
Car deal asked if I had any questions when buying my second Isuzu.
I told him "No, this isn't my first Rodeo."
lol
😄
Is there no (easy) way of using a database in the free tier of Heroku?
what about AWS credit card free tier thing?
Yoo has anyone ever had a class where it took them away from programming? Currently doing a class with a ton of Haskell and finite state machines. Coding for 8 hours a day I simply don’t enjoy programming anymore
haskell rip
I code 10 hours a day
And I still love coding
And Haskell is awesome bruh
What's the problem with it
Haskell is great
Proceeds to write an essay
Probably it’s the way it’s presented for me and what we’re expected to do. Well briefly get an explanation on a concept and fully implement it. It’ll take me about 4 5 days just for setting up
https://dpaste.org/RJiQ I still need to add additional constructions and I havent started on nondeterministic machines, then I start on my assignment to have to conversion between machines.
I looked for possible haskell tutors but from haskell community most are just like learn yourself and come to freenode if you need help, but I get stuck too frequently
You can learn yourself
Half this server's community are self-taught
Also
http://learnyouahaskell/ is nice , currently following it personally
ig u have to go with chapter 9+
Since you know types and data and typeclasses
@sterile island b?
reading the chapters would like give me the rest of the foundation to get things done easier?
But thanks just making it seems manageable makes it seem less of torture
oh lol i did a class with some lisp variation called racket
it was a pain at the start
but it provides a new perspective after ur done
I made some fake code to prank my friends
password = input ("please put your password ")
print (password)
#send (password) to amazon.com.server.database
#amazon.com.server.database = hackarena.com/amazon
#hackarena.com/amazon/pass=$U73kj0/user=jeffbezos/save
#if hackarena.com/amazon.api.save == True:
#hackarena.send(password)to.all/amazonemployees
#email = hackemail.(password).username==""
#hackarena.signin.email==(email)
#hackarena.signin.password==(password)
#hackarena.com/rob.all.money/from(email+password).api.amazon
#hackarena.com/change.password/from(email+password).api.amazon
print ("Succesfully saved and hacked username and password in Amazon Database")
lol
Codewars problems are mostly not hard
I feel like it should be kyu 7
Iterating through a string and checking it ... lol and kyu 6 also
hmm
print(len([x for x in arr if x in smile))
This would be my solution to it
Not worth 6 kyu at all
imho
need more smiles lol
lol
smile = [':)',':-)',':~)',
':D',':~D',':-D',
';)',';-)',';~)',
';D',';~D',';-D']
print(sum(x in smile for x in arr))
eyes = set(":;")
noses = set("-~")
mouthes = set(")D")
return sum(
i[0] & eyes
and i[-1] & mouthes
and len(i) == 2 or (len(i) == 3 and i[1] & noses)
for i in smileys
)
Hm
lol I'm not ready to read that
where did i come from
def count_smileys(arr):
smile = [':)',':-)',':~)',
':D',':~D',':-D',
';)',';-)',';~)',
';D',';~D',';-D']
total = 0
for s in arr:
if s in smile:
total += 1
return total
bast did you change ur name for spooky season
import itertools
VALID_SMILEYS = set(itertools.product(":;", ["-", "~", ""], ")D"))
def count_smileys(smileys):
return sum(i & VALID_SMILEYS for i in smileys)
I did
good good
Just wondering. Did you have to look up these builtin funcs or did you know it already?
I've learned them all over the years
sum() is pretty useful, itertools.product() as well
generally though it's a case of "Right, that's a combination of things, therefore there's probably something in itertools to make it", and "counting? sum"
as well as they "checking for inside a lot? set"
Oh I see
According to kata's ranking system
Yellow (Novice)
complex language features
simple algorithms
I guess that makes sense
anyone know why this doesn't throw error in codewars but it does in repl.it?
def factorial(n):
result = 1
try:
if n > 0 and n <= 12:
for x in range(1, n+1):
result *= x
return result
elif n == 0:
return 1
else:
raise ValueError
except ValueError:
return 'Sorry, Try again.'
what is the error?
just that if the number is less than 0 and greater than 12 then should raise ValueError
Should i add condition?
oh, did you mean codewars isn't throwing an error though you are raising one
Yeah. Is there a difference?
u better use a condition for this one
import math
def factorial(n):
try:
if n >= 0 and n <= 12:
return math.factorial(n)
elif n < 0 or n > 12:
raise ValueError
except ValueError:
return 'Sorry, Try again.'
Still didn't work. Weird
Just use a condition
did the indentation carry over properly?
import math
def factorial(n):
if n >= 0 and n <= 12:
return math.factorial(n)
return 'Sorry, Try again.'
This would be if I would do it ^^^^
oh i see. I did this
import math
def factorial(n):
if n >= 0 and n <= 12:
return math.factorial(n)
raise ValueError('Sorry, try again')
You can do that
It said to throw ValueError
But it'd not return a value if it gave error
It just gives an error
And your program would be terminated
If that's what you want , do it
Yeah i get it. Idk why kata asks to raise ValueError if conditoin is false
¯_(ツ)_/¯
Is this bad practice?
I'm trying to use ternary operator for this.
Oh it'd not be so hard
Well, this is what I got return math.facorial(n) if n >= 0 and n <= 12 else raise ValueError('Test'), I'll figure it out
(n >= 0 && n <= 12) ? math.factorial(n) : NULL;
If I were to do it in cpp ^
I think raise ValueError isn't an expression isn't an expression so that wouldn't work?
Oh he needs an expression?
I need to raise ValueError if the condition is false. What can I do if I can't use return or raise in ternary operator?
print probably
Or pointers if it's C++
I mean , in Python you can use immutable objects
An example could be :
def factorial(n): # n is an array with one memeber : The number you want
n[0] = [math.factorial(n) if n >= 0 and n <= 12 else None][0]
Would change n's first element to the answer , if I'm not wrong
And if n is not satisfying the if , it is gonna be n = [None]
I see. But, I have to raise ValueError though. I can't do n = [ValueError can I?
You can check for n's value
but
u said u don't want raise?
ohhh
I mean
u can make n return a valueError
Probably define it to something that is gonna give val err
Maybe do this :
def factorial(n): # n is an array with one memeber : The number you want
n[0] = [math.factorial(n) if n >= 0 and n <= 12 else int("gives a value error probably")][0]
Try that probably yeah
Not sure if that only works in lazy langs like haskell or not
But should give it a try
Hmm. Prob not possible to raise an error oneline
But try that
But it wants ValueError throw. None, or other errors won't work
TypeError: 'int' object does not support item assignment
Yeah lol
I thought you are implementing a func
ah mb
Yeah that's what i used
Mhm that'd work
Can't do that in oneline because I can't use raise or return after else
Ya. This is what I used
import math
def factorial(n):
if n >= 0 and n <= 12:
return math.factorial(n)
raise ValueError('Try again')
import math
def factorial(n):
if n >= 0 and n <= 12: return math.factorial(n)
raise ValueError('Try again')
Probably short
ooh
Oh waaaiit
In one line
It could be this :
import math
def factorial(n):
return math.factorial(n) if n >= 0 and n <= 12 else int("Try again")
Try this
I thought int() convert string to an integar? Will try it
Oh i see it throw an error
ValueError
If that didn't work either
Try :
import math
def factorial(n):
return math.factorial(n) if n >= 0 and n <= 12 else ValueError("Try again")
Yeah, no one has done this in oneline
XD
lol
Well , i did now lmao
where?
Submit my code and you'll see
it works tho
mhm
import math
def factorial(n):
return math.factorial(n) if n >= 0 and n <= 12 else int("Try again")
huh it passed all for me
and like the 9th
did you use int()?
Yeah i submitted lol
Oh wait
Lemme try again
Mhm worked
Welp
Congrats to us , the only one line solution lmao
lol
or idts ...
factorial=lambda n:__import__("math").factorial(n)if 0<=n<13 else int("x")
Look at this dude ....
How did you know that int() will throw ValueError? I tried googling which built in function will throw ValueError in python
oof
Well , experience
Ya.
But he also did the int(string) thing too
Well , the only one line solution without lambda
haha
1 similar code variation is grouped with this one lol
Oh that's mine probably lmao
yeah it says your name
XD nice
hm you only completed 12 kata
what is cf?
codeforces
math related stuffs nice
⊕ for subtraction. interesting
For the first test case Sana can choose x=4 and the value will be (6⊕4) + (12⊕4) = 2+8 = 10. It can be shown that this is the smallest possible value.
wow lmao
Oh no
(logic) exclusive or. (logic) intensional disjunction, as in some relevant logics. (mathematics) direct sum.
This is what google said
ig it's like or or something
Mk I gtg btw
It's 12:30 AM here
see ya
cya
I’m gonna make a study app, it’s gonna be called studify, (original, ikr) it’s gonna make it easier in general to study and save digital notes you want to easily access, and such. What you guys think?
It's an idea that has been done to death, but if you want to just do it as a fun side project it could be cool
What kind of functionality would it have? How would you make it easy to save and access the digital notes?
although the idea of a study app has been done a lot of times, but personal features that are different than the others out there makes it cool
the idea of typing up notes on a phone keyboard is kinda scary
esp when you need to draw or have mathematical equations
hence u add a feature for typesetting
sure, but go on your phone rn and try to type a basic function like
def addition(a: int, b: int) -> int:
return a + b
unless you cram everything into one section, typing equations is just going to be slow and annoying
well then you're really gonna have to come up with something innovative
there are already soooooo many things that do that
such as one note
between notion and one note I'm pretty well covered for notes
type setting feature seems nice
maybe giving suggestings on how to allocate time would also be a nice feature
it's for the voice gate
there's a voice verification channel that explains
down near the bottom of the list with the other voice channels
haha that was surprisingly easy to do thanks
yeah you're not the type of user we're trying to restrict from voice activity
👍
how does the voice channel bot work
nevermind thats a stupid fucking question
i can't figure out how to word it
It looks like you're voice verified, so you should be good to go
would apache or nginx be better to use on like a pi4?
yeah you're not the type of user we're trying to restrict from voice activity
is that a compliment or a threat?
nginx is better always imo
ya I will be setting up my pi4 with it tonight I think
hi
coolio, watch the temps, I hear they get high
Ya if they get to hot I will get a custom case printed and use a 80mm fan that can push out over 80cfm
one of those tornado fans
niiice, I need to print a case for mine
well I finally found my usb 2.0 hub without meaning to, now I need to not look for my 3.0 hub and I will find it XD
well I finally found my usb 2.0 hub without meaning to, now I need to not look for my 3.0 hub and I will find it XD
@ancient stream pip install usb3
Hello.
Good, u?
day 3 of my tea mishaps: while half asleep i put the milk in first
you put tea in your milk?
i did indeed put tea in my milk before making it tea
tbh once i realise what i did i threw it in the bin and started over
milks goes in last
please don't throw liquids in the bin
but i can't pour a tea bag down the sink
like cold milk? e.e ew
i don't see how warm milk would be any better
you can still brew tea in hot milk. lol
i have more questions than i did before
mars is not moon?
