我的名字是什么?


9

给定一个PPCG用户ID,输出该用户的当前用户名。

例子

Input -> Output
61563 -> MD XF
2     -> Geoff Dalgas
12012 -> Dennis
foo   -> 
-3    -> 

规则

  • 输入/输出可以通过任何允许的方式进行。
  • 输出必须是具有正确大小写和空格的完整用户名,仅此而已。
  • 如果输入的不是有效的UserID或用户不存在,则程序应不输出任何内容或输出错误。
  • 您的程序必须对任何有效用户都有效,即使在挑战之后创建的用户也是如此。
  • 您的程序不必对社区用户有效。
  • 您的程序不必对已删除的用户有效。
  • 不允许使用URL缩短器。

计分

每种语言中最短的代码将获胜。


5
非常密切的关系,但因为我的票是一把锤子,我没有近距离投票呢。
AdmBorkBork '17

@AdmBorkBork是的,这些密切相关,但这要容易得多。
MD XF

哦,用C ++会很容易
HatsuPointerKun

1
英文,3个字节:Okx。是的,那是我的名字。
Okx

1
每个人都可以保存4个字节(以“正常”语言显示):xxx.stackexchange.com/u/123重定向至xxx.stackexchange.com/users/123
Gilles'SO-别再作恶了'

Answers:


4

05AB1E35 34字节

由于互联网限制,无法在线工作。

’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’.w'>¡4è5F¦}60F¨

说明

压缩后的字符串:

’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’

推送以下字符串:

codegolf.stackexchange.com/users/<input>

<input>用户输入。之后,我们使用读取所有数据,.w并对数据进行一些字符串操作技巧:

'>¡4è5F¦}60F¨

'>¡             # Split on '>' (Usernames aren't allowed to have '>' so we're safe)
   4è           # Take the 5th element (which is in the header of the HTML page)
     5F¦}       # Remove the first 5 characters, which is "User "
         60F¨   # Remove the last 60 characters, which is:
                  " - Programming Puzzles &amp; Code Golf Stack Exchange</title"
                # Implicitly output the username

在本地运行时,我得到以下输出:

在此处输入图片说明


我认为该黑魔法品牌需要解释
泰勒·斯科特

我正从一个角度看屏幕,是否应该在您的用户名旁边勾勒出一个完全人性化的轮廓?
NoOneIsHere

1
@TaylorScott完成。
阿德南

3
@NoOneIsHere是的,cmder有点透明。这实际上就是您所看到的答案
阿德南

嗯,您的解释的一部分是„ -¡¬
暴民埃里克(Erik the Outgolfer)'17年

8

Bash,120 112 106 102 80 76 74字节

-8个字节,因为wget足够聪明,可以在必要时将HTTP重定向到HTTPS
-6个字节,这要归功于sedCows quack的另一个建议
-26个字节(感谢Digital Trauma)
-4个字节(感谢Gilles)- codegolf.stackexchange.com/u/123重定向
-2个字节(感谢Digital Trauma的回答wget标志)

wget -qO- codegolf.stackexchange.com/u/$1|sed -nr 's/.*>User (.*) -.*/\1/p'

没有TIO链接,因为TIO竞技场无法访问互联网。

感谢这里的答案以及聊天中的人为我提供的帮助。我使用了类似于HyperNeutrino的方法。

  1. wget -qO- codegolf.stackexchange.com/users/$1下载用户的个人资料页面并将文件打印到STDOUT。-q安静地做(没有速度信息)。

  2. sed -nr 's/.*User (.*) -.*/\1/p'搜索第一个字符串User<space>,然后打印,直到到达使用sed魔术符找到的名称结尾为止。


我较独立地写的先前答案(102字节):

wget codegolf.stackexchange.com/users/$1 2>y
sed '6!d' <$1|cut -c 13-|cut -d '&' -f1|sed 's/.\{23\}$//'
  1. wget codegolf.stackexchange.com/users/$1 2>y将用户个人资料HTML保存到以其UserID命名的文件中,并将STDERR转储到中y

  2. cat $1 将文件传输到可删除无用HTML的部分中。

  3. sed '6!d'(代替head -6 | tail -1)本身获得第六行。

  4. cut -c 13- 删除前13个字符,使用户名从字符串的第一个字符开始。

  5. cut -d '&' -f1削减一切&。这是基于这样的事实:用户名或HTML标题中均不允许使用&符号。
    现在字符串是<username> - Programming Puzzles

  6. sed 's/.\{23\}$//'是一个建议,从奶牛呱删除最后一个15个字节的文件。这将单独获取用户名。

这是完整的bash脚本。


...TIO arenas can't access the internet他们可以,这就是您访问它的方式。:P不允许用户提交的代码访问Internet。 </nitpick>
完全人类

@totallyhuman您可以通过互联网访问TIO竞技场。但是竞技场本身无法访问互联网。甚至在竞技场上运行的丹尼斯代码也无法访问Internet。
MD XF

@totallyhuman afaik不,他们不能。您将主代码提供给主服务器,主服务器连接到竞技场并运行代码。不过那可能已经过时了
斯蒂芬

对于userID 11259,输出为Digital Trauma - Progr
Digital Trauma

@DigitalTrauma糟糕,忘记修复第二个sed字节数。
MD XF

6

Bash + GNU实用程序,66

  • @Arnauld节省了3个字节。
  • @Gilles节省了4个字节。
wget -qO- codegolf.stackexchange.com/u/$1|grep -Po '"User \K[^"]+'

使用-PCRE regex样式进行\K 匹配开始重置,以缩短输出过滤时间。


如果您的系统已经curl安装,我们可以使用@Gilles的建议:

Bash + curl + GNU实用程序,64

curl -L codegolf.stackexchange.com/u/$1|grep -Po '"User \K[^"]+'

目的是O-什么?
user41805

@Cowsquack -O-将下载的输出发送到STDOUT而不是文件,因此可以将其简单地传递到grep
Digital Trauma

1
您可以grep -Po '"User \K[^"]+'保存3个字节。
Arnauld

1
curl -L比短wget -qO-。您可以使用/u代替/users
吉尔(Gilles)'所以

1
@Ferrybig我假设默认情况下可以忽略STDERR
Digital Trauma

4

Python 2 +请求,112字节

from requests import*
t=get('http://codegolf.stackexchange.com/users/'+input()).text
print t[49:t.index('&')-23]

注意

SE完全运行后httpshttp需要更改为https,这将变为113个字节。

用户个人资料的开头看起来像这样:

<!DOCTYPE html>
<html>

<head>

<title>User MD XF - Programming Puzzles &amp; Code Golf Stack Exchange</title>

用户名从索引49开始,“&”号出现在其结尾处(- Programming Puzzles)的右边23个字符

-3字节归因于StepHen / Mego, 感谢Uriel 消除了未使用的re导入
-1字节


您永远不会使用,re因此可以丢弃3个字节
-Mego

@MELO,我傻了。谢谢
HyperNeutrino '17

您也可以http暂时使用,但是当SE变为完整的HTTPS时最终将逐步淘汰该功能。
Mego

@Mego我将其作为补充说明-谢谢
HyperNeutrino

from requests import*删除r.113个字节
Uriel

4

JavaScript(ES6),111 75字节

仅在通过PPCG域运行时有效。返回Promise包含用户名的对象。

i=>fetch("/users/"+i).then(r=>r.text()).then(t=>t.slice(44,t.search`&`-23))
  • 感谢Downgoat确认我正在使用的替代方法是有效的,因此可以节省36个字节。

77个字节:i=>fetch(`/users/${i}`).then(r=>r.text()).then(s=>/"User ([^"]+)/.exec(s)[1])
Downgoat

66个字节:i=>$.get(`/users/${i}`).done(s=>alert(/"User ([^"]+)/.exec(s)[1]))
下乡时间

您可以从中删除括号fetch以保存2个字节
GilZ

谢谢,@Downgoat; 我已经想过以fetch这种方式浏览用户页面的想法,但是认为这可能会增加我的运气。但是,正如您所建议的那样,我将对其进行编辑。当前是否支持任何浏览器.done()?我在Chrome&FF中对其进行了快速测试,但无法在那儿工作。
毛茸茸的

@Gilz,如果不涉及任何变量,我只能这样做。
毛茸茸的

4

雨燕 3,233字节

import Foundation;func f(i:String){let s=try!String(contentsOf:URL(string:"http://codegolf.stackexchange.com/users/"+i)!,encoding:.utf8);print(s[s.index(s.startIndex,offsetBy:44)...s.index(s.characters.index(of:"&")!,offsetBy:-24)])}

样品运行:

f(i:"8478") // Martin Ender
f(i:"12012") // Dennis
f(i:"59487") // Mr. Xcoder


1
是! 迅速!来自高尔夫语言沙漠的绿洲
bearacuda13 '17

@ bearacuda13哈哈true :)
Xcoder先生17年

您可以使用闭包并节省大量字节
Downgoat '17

@Downgoat感谢您的提示,我有时间会更新。
Xcoder先生17年

3

Python 2,116字节

只是认为有一个标准的库答案很好(实际上长度相当不错)。

from urllib import*
f=urlopen('http://codegolf.stackexchange.com/users/'+input()).read()
print f[49:f.index('&')-23]

当SE变为完全https,我们需要添加1个字节,开关urlopen('http://...urlopen('https://...


3

立体地 + Bash,1654 1336 1231字节

-423字节归功于TehPers

这需要三个Cubically脚本(命名为 123)和1个bash脚本。

立体脚本确实长,因为我还没有想到实现循环的好方法。

重击(84字节):

ln -s rubiks-lang /bin/r
r 1 <<<$1 2>y|xargs wget 2>y
cat $1|r 2 2>y|rev|r 3 2>y|rev

这会将第一个Cubically脚本传输到wget,然后将保存的文件传输到第二个Cubically脚本,然后反转该输出,将其传输到第三个Cubically脚本,然后反转。

1 (385字节):

+5/1+551@6:5+3/1+552@66:4/1+552@6:5+2/1+552@6:4/1+51@6:2/1+5@66:5+51@6:3/1+552@6:1/1+551@6:2/1+551@6:4/1+551@6:3/1+552@6:5+52@6:3/1+551@6:1/1+5@6:5+2/1+552@6:5+3/1+552@6:5+2/1+55@6:5+51@6:5+3/1+551@6:2/1+551@6:3/1+553@6:5+51@6:5/1+551@6:5+2/1+55@6:2/1+552@6:4/1+551@6:2/1+551@6:1/1+5@6:5+51@6:3/1+552@6:1/1+552@6:2/1+5@6:5+53@6:5+2/1+552@6:2/1+551@6:5+1/1+552@6:5+2/1+552@6:2/1+5@6$7%7

此打印 https://codegolf.stackexchange.com/users/,然后是输入的第一个整数。

2680505字节):

~7777777777777777777777777777777777777777777777777
F1R1
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6

这将从保存的文件中读取不需要的数据作为输入,然后打印直到和号输入 Programming Puzzles & Code Golf

~7@7读取并打印一个字符。F1R1:5=7检查输入是否为“&”号。&6如果是,则退出。

~7@7:5=7&6 重复45次,因为有15个字节的不必要数据和30个字节的最大StackExchange用户名。

3(505个 446 342字节):

U3D1R3L1F3B1U1D3
~777777777777777777777777
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7

与最后一个脚本非常相似,它读取前几个不必要的字节,然后读取cats直到EOF。由于最大的SE用户名,这也可以使用。


对于文件3,为什么不使用:0-1/1代替:4+4/1-1?同样,它的第一个实例可能只是-1/1因为记事本从0开始
。– TehPers

1
可能要警告/bin/r被覆盖。
NoOneIsHere

对于文件2,您可以F1R1+5+2/1+4
从头

2

PHP,163字节


<?php $a=new DOMDocument;@$a->loadHTML(implode(0,file("http://codegolf.stackexchange.com/users/$argv[1]")));echo$a->getElementsByTagName('h2')->item(0)->nodeValue;

2

的powershell,165个 142 137 127字节

感谢AdmBorkBork保存23 28 38个字节!

创建一个名为0副作用的文件。

((iwr"codegolf.stackexchange.com/u/$args").AllElements|?{$_.class-like"user-c*"})[1].innerhtml-match"(.+?) ?<|.+">0
$matches[1]

通过转到适当的网页,然后选择“用户卡名称”元素,然后从innerhtml中提取适当的文本来进行工作。

测试中

PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 61563
MD XF
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 2
Geoff Dalgas
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 12012
Dennis
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 foo
Invoke-WebRequest : current community chat Programming Puzzles & Code Golf
Programming Puzzles & Code Golf Meta your communities Sign up or log in to customize your list. more stack
exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour
Start here for a quick overview of the site Help Center
Detailed answers to any questions you might have Meta
Discuss the workings and policies of this site About Us
Learn more about Stack Overflow the company Business
Learn more about hiring developers or posting ads with us
Programming Puzzles & Code Golf Questions Tags Users Badges Unanswered Ask Question
 Page Not FoundWe're sorry, we couldn't find the page you requested.
Try searching for similar questions
Browse our recent questions
Browse our popular tags
If you feel something is missing that should be here, contact us.
about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback
Technology Life / Arts Culture / Recreation Science Other
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Software Engineering
Unix & Linux
Ask Different (Apple)
WordPress Development
Geographic Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
ExpressionEngine® Answers
Blender
Network Engineering
Cryptography
Code Review
Magento
Software Recommendations
Signal Processing
Emacs
Raspberry Pi
Programming Puzzles & Code Golf
Ethereum
Data Science
Arduino
more (26)
Photography
Science Fiction & Fantasy
Graphic Design
Movies & TV
Music: Practice & Theory
Worldbuilding
Seasoned Advice (cooking)
Home Improvement
Personal Finance & Money
Academia
Law
more (17)
English Language & Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
English Language Learners
Japanese Language
Arqade (gaming)
Bicycles
Role-playing Games
Anime & Manga
Puzzling
Motor Vehicle Maintenance & Repair
more (32)
MathOverflow
Mathematics
Cross Validated (stats)
Theoretical Computer Science
Physics
Chemistry
Biology
Computer Science
Philosophy
more (10)
Meta Stack Exchange
Stack Apps
Area 51
Stack Overflow Talent
site design / logo © 2017 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution
required rev 2017.8.1.26652
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:1 char:3
+ ((Invoke-WebRequest -URI("codegolf.stackexchange.com/users/"+$args[0])).AllEleme ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], We
   bException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Cannot index into a null array.
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:2 char:1
+ $matches[1]
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 -3
Invoke-WebRequest : current community chat Programming Puzzles & Code Golf
Programming Puzzles & Code Golf Meta your communities Sign up or log in to customize your list. more stack
exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour
Start here for a quick overview of the site Help Center
Detailed answers to any questions you might have Meta
Discuss the workings and policies of this site About Us
Learn more about Stack Overflow the company Business
Learn more about hiring developers or posting ads with us
Programming Puzzles & Code Golf Questions Tags Users Badges Unanswered Ask Question
 Page Not FoundWe're sorry, we couldn't find the page you requested.
Try searching for similar questions
Browse our recent questions
Browse our popular tags
If you feel something is missing that should be here, contact us.
about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback
Technology Life / Arts Culture / Recreation Science Other
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Software Engineering
Unix & Linux
Ask Different (Apple)
WordPress Development
Geographic Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
ExpressionEngine® Answers
Blender
Network Engineering
Cryptography
Code Review
Magento
Software Recommendations
Signal Processing
Emacs
Raspberry Pi
Programming Puzzles & Code Golf
Ethereum
Data Science
Arduino
more (26)
Photography
Science Fiction & Fantasy
Graphic Design
Movies & TV
Music: Practice & Theory
Worldbuilding
Seasoned Advice (cooking)
Home Improvement
Personal Finance & Money
Academia
Law
more (17)
English Language & Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
English Language Learners
Japanese Language
Arqade (gaming)
Bicycles
Role-playing Games
Anime & Manga
Puzzling
Motor Vehicle Maintenance & Repair
more (32)
MathOverflow
Mathematics
Cross Validated (stats)
Theoretical Computer Science
Physics
Chemistry
Biology
Computer Science
Philosophy
more (10)
Meta Stack Exchange
Stack Apps
Area 51
Stack Overflow Talent
site design / logo © 2017 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution
required rev 2017.8.1.26652
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:1 char:3
+ ((Invoke-WebRequest -URI("codegolf.stackexchange.com/users/"+$args[0])).AllEleme ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], We
   bException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Cannot index into a null array.
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:2 char:1
+ $matches[1]
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

PS C:\Users\Conor O'Brien\Documents\powershell>

1

Python + requests,126个字节

lambda n:get('http://api.stackexchange.com/users/%d?site=codegolf'%n).json()['items'][0]['display_name']
from requests import*

访问API显然比读取实际页面要长。


2
标准库+页面阅读时间短于requests:p的那一刻
Xcoder先生,17年

1

果冻,37 个字节

的端口HyperNeutrino的Python的2回答 -去提供信贷!

“3¬ẋṙẉṀḷo°ɓẏ8YyŒÇḣðk¦»;ŒGṾṫ51ṣ”&Ḣḣ-23

一个单数链接,它带有一个数字并返回一个字符列表;因为完整的程序会打印结果。

注意:不确定为什么ŒG需要强制将结果转换为字符串(在此处完成):/

怎么样?

“3¬ẋṙẉṀḷo°ɓẏ8YyŒÇḣðk¦» = compression of:
                         "code"+"golf"+"."+"stack"+"exchange"+".com/"+"user"+"s/"

codegolf.stackexchange.com/users/

“...»;ŒGṾṫ51ṣ”&Ḣḣ-23 - Main link: number, n
“...»                - "codegolf.stackexchange.com/users/"
     ;               - concatenate with n
      ŒG             - GET request (should be to string & looks like it on output)
        Ṿ            - uneval (force to a string - shrug)
         ṫ51         - tail from index 51 (seems the ŒG result is quoted too, so 51 not 50)
            ṣ”&      - split on '&'
               Ḣ     - head (get the first chunk)
                ḣ-23 - head to index -23 (discard the last 23 characters)


0

Mathematica,126个字节

StringTake[#&@@StringCases[Import["https://codegolf.stackexchange.com/users/"<>ToString@#,"Text"],"r "~~ __ ~~" - P"],{3,-4}]&  


输入

[67961]

输出

珍妮·玛西


0

Stratos,22字节

f"¹⁸s/%²"r"⁷s"@0s"³_⁴"

尝试一下!

说明:

f"¹⁸s/%?"               Read the data from the URL: 
                        http://api.stackexchange.com/users/%?site=codegolf
                        where % is replaced with the input
         r              Get the JSON array named
          "⁷s"          items
              @0        Get the 0th element
                 s"³_⁴" Get the string "display_name"
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.